RMI-IIOP
RMI-IIOP(RMI オーバー IIOP)とは、CORBAシステム
概要
[この
CORBA と RMI-IIOP はどちらも
RMI-IIOP の
Hello world の例
[Java RMI-IIOP を
インタフェース
[public interface MyServer extends Remote
{
// クライアントは self を第 一 引数 に渡 す。サーバはクライアント側
// にあるリモートメソッドを呼 び出 せる。これは要求 処理 に時間 がかかる場合 に
// 便利 である。
void receiveRequest(MyClient client, String message) throws RemoteException;
}
public interface MyClient extends Remote
{
// このリモートメソッドはサーバから呼 び出 される
void receiveReply(String message) throws RemoteException;
}
クライアントとサーバの機能 実装
[public class MyServerImpl implements MyServer { void receiveRequest(MyClient client, String message) throws RemoteException { System.out.println("The client says: "+message); client.receiveReply("Yes, "+message+", "+message+", "+message+"..."); } }
public class MyClientImpl implements MyClient { MyServer server; public MyClientImpl(String Server_IOR, ORB orb) throws Exception { server = (MyServer) PortableRemoteObject.narrow( orb.string_to_object(Server_IOR), MyServer.class); } // これはリモートメソッド void receiveReply(String message) throws RemoteException { System.out.println("And the answer is: "+message); } // これはリモートメソッドではなく、ローカルメソッド public void talk(String conversation) { server.receiveRequest(this, conversation); } }
RMI-IIOP
サーバ機能 開始 に必要 なコード
[new Thread() { public void run() { try { // CORBA ORB の生成 MyServerImpl.orb = ORB.init(args, properties); // ルート Portable Object Adapter を取得 : POA rootPOA = POAHelper.narrow (MyServerImpl.orb.resolve_initial_references("RootPOA")); // MyServerImpl にはサーバがサポートしなければならない // メソッドの実装 が含 まれる。 MyServerImpl impl = new MyServerImpl(); PortableRemoteObject.exportObject(impl); // Tie の構築 。Tie はサーバントでもある。 // _MyServerImpl_Tie クラスは MyServerImpl から自動的 に生成 される。 Tie tie = new _MyServerImpl_Tie(); // この Tie の呼 び出 しターゲットを設定 tie.setTarget(impl); //対応 する CORBA オブジェクトへの参照 を取得 : org.omg.CORBA.Object object = rootPOA.servant_to_reference((Servant) tie); // ルート POA の活性 化 rootPOA.the_POAManager().activate(); // クライアントに渡 す IOR URL を取得 String Server_IOR = MyServerImpl.orb.object_to_string(object); MyServerImpl.orb.run(); //文字 列 変数 Server_IOR の内容 をどうにかしてクライアントに //転送 しなければならない } catch (Exception exc) { exc.printStackTrace(); } } }.start();
クライアント機能 開始 に必要 なコード
[MyClient the_client; new Thread() { public void run() { try { ORB orb = ORB.init(args, parameters); the_client = new MyClientImpl(Server_IOR, orb); POA rootPOA = POAHelper.narrow(desk.orb.resolve_initial_references("RootPOA")); rootPOA.the_POAManager().activate(); // Tie構築 Tie tie = new _MyClientImpl_Tie(); //実装 クラス(呼 び出 しターゲット)の設定 tie.setTarget(the_client); // Tie を POA サーバントとして接続 org.omg.CORBA.Object object = rootPOA.servant_to_reference((Servant) tie); // IOR文字 列 を使 ってWeb上 でこのオブジェクトを探 すことが可能 String IOR = desk.orb.object_to_string(object); orb.run(); } catch (Exception exc) { exc.printStackTrace(); } } }.start();
ORB スレッドが
the_client.talk("it is raining");
実行
[ここに
略語 利用 の法的 問題
[IIOP という