Borland(R) Enterprise Server VisiBroker(R) デベロッパーズガイド

[目次][索引][前へ][次へ]

21.3.3 アンタイプドオブジェクトラッパーファクトリの生成と登録

C++の場合
アンタイプドオブジェクトラッパーファクトリは,ロケーションを受け付けるbaseクラスコンストラクタで生成される場合,アンタイプドオブジェクトラッパーのチェーンに自動的に追加されます。
クライアント側では,オブジェクトがバインドされる前にアンタイプドオブジェクトラッパーファクトリが生成,登録される場合だけ,オブジェクトがラッピングされます。サーバ側では,オブジェクトインプリメンテーションが呼び出される前にアンタイプドオブジェクトラッパーファクトリが生成,登録されます。
コードサンプル21-5に,クライアント用の二つのアンタイプドオブジェクトラッパーファクトリの生成と自動登録を示したUntypedClient.Cサンプルファイルの一部を示します。ファクトリはVisiBroker ORBが初期化されたあと,かつクライアントがオブジェクトにバインドする前に生成されます。

コードサンプル21-5 二つのクライアント側アンタイプドオブジェクトラッパーファクトリの生成と登録(C++)
 
int main(int argc, char* const* argv) {
   try {
         // Initialize the ORB.
         CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
         // Install untyped object wrappers
         TimingObjectWrapperFactory timingfact(
               VISObjectWrapper::Client, "timeclient");
         TraceObjectWrapperFactory tracingfact(
               VISObjectWrapper::Client, "traceclient");
         // Now locate an account manager.
. . .
 

Javaの場合
コードサンプル21-6に,クライアント用の二つのアンタイプドオブジェクトラッパーファクトリの生成とインストールを示したUntypedClient.javaサンプルファイルの一部を示します。ファクトリはVisiBroker ORBが初期化されたあと,ただしクライアントがオブジェクトにバインドする前に生成されます。

コードサンプル21-6 二つのクライアント側アンタイプドオブジェクトラッパーファクトリのインストール(Java)
 
// UntypedClient.java
import com.inprise.vbroker.interceptor.*;
 
public class UntypedClient {
   public static void main(String[ ] args) throws Exception {
      // Initialize the ORB.
      org.omg.CORBA.ORB orb =
                           org.omg.CORBA.ORB.init(args,null);
      doMain (orb, args);
   }
   public static void doMain(org.omg.CORBA.ORB orb,
                            String[ ] args) throws Exception {
      ChainUntypedObjectWrapperFactory Cfactory =
            ChainUntypedObjectWrapperFactoryHelper.narrow(
               orb.resolve_initial_references(
               "ChainUntypedObjectWrapperFactory")
            );
      Cfactory.add(new UtilityObjectWrappers.
            TimingUntypedObjectWrapperFactory(),
            Location.CLIENT);
      Cfactory.add(new UtilityObjectWrappers.
            TracingUntypedObjectWrapperFactory(),
            Location.CLIENT);
      // Locate an account manager. . . .
   }
}
 

C++の場合
コードサンプル21-7にUntypedServer.Cサンプルファイルを示します。このファイルはサーバ用のアンタイプドオブジェクトラッパーファクトリの生成と登録を示しています。ファクトリはVisiBroker ORBが初期化されたあと,ただしオブジェクトインプリメンテーションが生成される前に生成されます。

コードサンプル21-7 サーバ側アンタイプドオブジェクトラッパーファクトリの登録(C++)
 
// UntypedServer.C
#include "Bank_s.hh"
#include "BankImpl.h"
#include "TimeWrap.h"
#include "TraceWrap.h"
USE_STD_NS
int main(int argc, char* const* argv) {
   try {
      // Initialize the ORB.
      CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
      // Initialize the POA.
      CORBA::Object_var obj = 
            orb->resolve_initial_references("RootPOA");
      PortableServer::POA_var rootPoa = 
            PortableServer::POA::_narrow(obj);
      CORBA::PolicyList policies;
      policies.length(1);
      policies[(CORBA::ULong)0] =
            rootPoa->create_lifespan_policy(
            PortableServer::PERSISTENT);
      // Get the POA Manager.
      PortableServer::POAManager_var poa_manager = 
            rootPoa->the_POAManager();
      // Create myPOA With the Right Policies.
      PortableServer::POA_var myPOA = 
            rootPoa->create_POA("bank_ow_poa",
            poa_manager,
            policies);
      // Install Untyped Object Wrappers for Account Manager.
      TimingObjectWrapperFactory timingfact(
           VISObjectWrapper::Server, "timingserver");
      TraceObjectWrapperFactory tracingfact(
           VISObjectWrapper::Server, "traceserver");
      // Create the Account Manager Servant.
      AccountManagerImpl managerServant;
      // Decide on ID for Servant.
      PortableServer::ObjectId_var managerId =
      PortableServer::string_to_ObjectId("BankManager");
      // Activate the Servant with the ID on myPOA.
      myPOA->activate_object_with_id(
            managerId, &managerServant);
      // Activate the POA Manager.
      rootPoa->the_POAManager()->activate();
      cout << "Manager is ready." << endl;
      // Wait for Incoming Requests.
      orb->run();
   } catch(const CORBA::Exception& e) {
      cerr << e << endl;
      return 1;
   }
   return 0;
}
 

Javaの場合
コードサンプル21-8にUntypedServer.javaサンプルファイルを示します。このファイルはサーバ用のアンタイプドオブジェクトラッパーファクトリの生成と登録を示しています。ファクトリはVisiBroker ORBが初期化されたあと,ただしオブジェクトインプリメンテーションが生成される前に生成されます。

コードサンプル21-8 サーバ側アンタイプドオブジェクトラッパーファクトリのインストール(Java)
 
// UntypedServer.java
import com.inprise.vbroker.interceptor.*;
import org.omg.PortableServer.*;
import com.inprise.vbroker.PortableServerExt.
                                BindSupportPolicyValue;
import com.inprise.vbroker.PortableServerExt.
                                BindSupportPolicyValueHelper;
import com.inprise.vbroker.PortableServerExt.
                                BIND_SUPPORT_POLICY_TYPE;
 
public class UntypedServer {
   public static void main(String[ ] args) throws Exception {
      // Initialize the ORB.
      org.omg.CORBA.ORB orb =
                           org.omg.CORBA.ORB.init(args,null);
      ChainUntypedObjectWrapperFactory Sfactory =
            ChainUntypedObjectWrapperFactoryHelper.narrow
            (orb.resolve_initial_references(
            "ChainUntypedObjectWrapperFactory"));
      Sfactory.add(new UtilityObjectWrappers.
            TracingUntypedObjectWrapperFactory(),
            Location.SERVER);
      // get a reference to the rootPOA
      POA rootPOA = POAHelper.
           narrow(orb.resolve_initial_references("RootPOA"));
      // Create a BindSupport Policy that makes POA register
      // each servant with osagent
      org.omg.CORBA.Any any = orb.create_any();
      BindSupportPolicyValueHelper.insert(any,
         BindSupportPolicyValue.BY_INSTANCE);
      org.omg.CORBA.Policy bsPolicy =
         orb.create_policy(BIND_SUPPORT_POLICY_TYPE.value,
                           any);
      // Create policies for our testPOA
      org.omg.CORBA.Policy[ ] policies = {
         rootPOA.create_lifespan_policy
            (LifespanPolicyValue.PERSISTENT), bsPolicy
      };
      // Create myPOA with the right policies
      POA myPOA = rootPOA.create_POA( "bank_agent_poa",
         rootPOA.the_POAManager(),
         policies );
 
      // Create the account manager object.
      AccountManagerImpl managerServant =
                                    new AccountManagerImpl();
      // Decide on the ID for the servant
      byte[ ] managerId = "BankManager".getBytes();
      // Activate the servant with the ID on myPOA
      myPOA.activate_object_with_id(managerId,
                                    managerServant);
      // Activate the POA manager
      rootPOA.the_POAManager().activate();
      System.out.println(
                     "AccountManager: BankManager is ready.");
      for( int i = 0; i < args.length; i++ ) {
         if( args[i].equalsIgnoreCase("-runCoLocated") ) {
            if( args[i+1].equalsIgnoreCase("Client") ) {
               Client.doMain(orb, new String[0]);
            }else if( args[i+1].
                           equalsIgnoreCase("TypedClient") ) {
               TypedClient.doMain(orb, new String[0]);
            }
            if( args[i+1].equalsIgnoreCase("UntypedClient") ) {
               UntypedClient.doMain(orb, new String[0]);
            }
            System.exit(1);
         }
      }
      // Wait for incoming requests
      orb.run();
   }
}