19.2.9 ORBInitializerの登録

ORBInitializerを登録するために,グローバルメソッドであるregister_orb_initializerが提供されています。インタセプタをインプリメントする各サービスは,ORBInitializerのインスタンスを提供します。サービスを使用するために,アプリケーションは次の手順を行います。

  1. サービスのORBInitializerでregister_orb_initializer()メソッドを呼び出します。
  2. 新しいORB識別子でORB_Init()メソッド呼び出しを実体化して新しいORBを生成します。
Javaの場合
register_orb_initializer()メソッドは,グローバルメソッドであるため,ORBに関するアプレットセキュリティに違反します。結果として,ORBInitializerは,register_orb_initializer()メソッドを呼び出すのではなく,Java ORBプロパティを使用してVisiBroker Edition ORBに登録されます。
<この項の構成>
(1) 新しいプロパティセット(Java)
(2) サンプル

(1) 新しいプロパティセット(Java)

新しいプロパティ名の形式を次に示します。

org.omg.PortableInterceptor.ORBInitializerClass.<Service>

ここで<Service>は,org.omg.PortableInterceptor.ORBInitializerをインプリメントするクラスの文字列名です。

ORB.init()メソッドの実行中に行われることを次に示します。

  1. org.omg.PortableInterceptor.ORBInitializerClassで始まるORBプロパティが収集されます。
  2. 各プロパティの<Service>部分が収集されます。
  3. オブジェクトは,そのクラス名として<Service>文字列を使用して実体化されます。
  4. pre_init()メソッドおよびpost_init()メソッドがそのオブジェクトで呼び出されます。
  5. 例外が発生すると,ORBはそれを無視して続行します。
名前の衝突を避けるために,DNS名の入れ替え規則を適用することを推奨します。例えば,ABC社に二つのイニシャライザがある場合,次のプロパティを定義できます。

org.omg.PortableInterceptor.ORBInitializerClass.com.abc.ORBInit1
org.omg.PortableInterceptor.ORBInitializerClass.com.abc.ORBInit2

C++の場合
register_orb_initializerメソッドはPortableInterceptorモジュールに次のように定義されます。

class _VISEXPORT PortableInterceptor {
   static void register_orb_initializer(ORBInitializer *init);
}

(2) サンプル

ABC社が書き込んだクライアント側の監視ツールに,次に示すORBInitializerインプリメンテーションがあるとします。

コードサンプル19-21 ORBInitializerの登録例(C++)

#include "PortableInterceptor_c.hh"

class MonitoringService:public PortableInterceptor::ORBInitializer
{
  void pre_init(ORBInitInfo_ptr _info)
  {
     //instantiate the service ’s Interceptor.
     Interceptor*interceptor =new MonitoringInterceptor();

     //register the Monitoring ’s Intereptor.
     _info->add_client_request_interceptor(interceptor);
  }

  void post_init(ORBInitInfo_ptr _info)
  {
     //This init point is not needed.
  }
};
MonitoringService *monitoring_service =new MonitoringService();
PortableInterceptor::register_orb_initializer(monitoring_service);

コードサンプル19-22 ORBInitializerの登録例(Java)

package com.abc.Monitoring;

import org.omg.PortableInterceptor.Interceptor;
import org.omg.PortableInterceptor.ORBInitializer;
import org.omg.PortableInterceptor.ORBInitInfo;

public class MonitoringService extends org.omg.CORBA.LocalObject
  implements org.omg.PortableInterceptor.ORBInitializer
{
  void pre_init(ORBInitInfo info)
  {
     //instantiate the service ’s Interceptor.
     Interceptor interceptor =new MonitoringInterceptor();

     //register the Monitoring ’s Interceptor.
     info.add_client_request_interceptor(interceptor);
  }

  void post_init(ORBInitInfo info)
  {
     //This init point is not needed.
  }
}

この監視サービスを使用してMyAppと呼ばれるプログラムを実行するために次のコマンドが使用されます。

java -Dorg.omg.PortableInterceptor.ORBInitializerClass.
    com.abc.Monitoring.MonitoringService MyApp