1 / 16

RMI

RMI. Reporter:Vincent. RMI 定義和功能. RMI 是 Remote Method Invocation 的簡稱,是 J2SE 的一部分,能夠開發出基於 Java 的分散式應用。一個 RMI 對象是一個遠程 Java 對象,可以從另一個 Java 虛擬機器上(甚至跨過網絡)調用它的方法,可以像調用本地 Java 對象的方法一樣調用遠程對象的方法,使分佈在不同的 JVM 中的對象的外表和行為都像本地對象一樣。. RMI 架構. Registry Server. TCP/IP. RMI 程式開發步驟. 步驟一:定義遠端介面

dalton
Download Presentation

RMI

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. RMI Reporter:Vincent

  2. RMI定義和功能 RMI是Remote Method Invocation的簡稱,是J2SE的一部分,能夠開發出基於Java的分散式應用。一個RMI對象是一個遠程Java對象,可以從另一個Java虛擬機器上(甚至跨過網絡)調用它的方法,可以像調用本地Java對象的方法一樣調用遠程對象的方法,使分佈在不同的JVM中的對象的外表和行為都像本地對象一樣。

  3. RMI架構 Registry Server TCP/IP

  4. RMI 程式開發步驟 步驟一:定義遠端介面 步驟二:Server 端程式設計 步驟三:產生stub程式 步驟四:Client 端程式設計

  5. 步驟一:定義遠端介面 HelloIF.java • 提供服務前需先定義一個遠端物件的服務介面,透過此介面,Client 端程式才可以運用Server 端物件的方法。 • 介面撰寫的兩點規定 • A. 必須繼承java.rmi.Remote 介面。 • B. 必須定義Server 端物件的方法,並且宣告拋出RemoteException 的例外事件。

  6. 步驟二:Server 端程式設計 • 實作Server 端程式的規則 • A. 宣告實作遠端物件的服務介面。 • B. 需繼承UnicastRemoteObject 類別。 • C. 欲提供給Client 端使用的方法,必須宣告拋出RemoteException 例外事件。 • D. 在程式中利用Naming.rebind 向Register Server 做登錄。

  7. 步驟三:產生stub程式 • 產生stub程式的方法是透過rmic 指令,如下: • > rmic HelloImpl • 執行上述指令後,會產生HelloImpl _Stub.class程式。

  8. 步驟四:Client 端程式設計

  9. access control 的錯誤訊息

  10. 安全政策 由於RMI的安全機制將在服務端發生作用,所以必須增加安全政策。 在資料夾中,建立*.policy檔案。

  11. 執行SERVER端程式 • 執行RMIRegistry • start rmiregistry • 根據policy實行SERVER的實體 • java -Djava.security.policy=java.policy HelloImpl

  12. 執行Client端程式 • 直接執行就好哩 • Java HelloClient

  13. 練習題 請將這個範例改成service 傳回hostname 並加上時間。 再將這個service 改成提供兩個介面,一個介面是getIPAddress() 回傳service 所在的IP address,另一個介面是getTime() 回傳service 所在的時間。

  14. Thank You ! http://hpds.ee.kuas.edu.tw/

More Related