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

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

18.7 サーバのインプリメンテーション

mainルーチンのインプリメンテーションは,コードサンプル18-11および18-12に示すように,「4. Borland Enterprise Server VisiBrokerによるサンプルアプリケーションの開発」で示したサンプルとほぼ同じものです。

コードサンプル18-11 サーバのインプリメンテーション(C++)
 
int main(int argc, char* const* argv) {
   try {
      // Initialize the ORB
      CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
 
      // Get a reference to the rootPOA
      CORBA::Object_var obj =
            orb->resolve_initial_references("RootPOA");
      PortableServer::POA_var rootPOA = 
            PortableServer::POA::_narrow(obj);
      // Get the POA Manager
      PortableServer::POAManager_var poaManager =
            rootPOA->the_POAManager();
      // Create the account POA with the right policies
      CORBA::PolicyList accountPolicies;
      accountPolicies.length(3);
      accountPolicies [(CORBA::ULong)0] =
            rootPOA->create_servant_retention_policy(
            PortableServer::NON_RETAIN);
      accountPolicies[(CORBA::ULong)1] =
            rootPOA->create_request_processing_policy(
            PortableServer::USE_DEFAULT_SERVANT);
      accountPolicies[(CORBA::ULong)2] =
            rootPOA->create_id_uniqueness_policy(
            PortableServer::MULTIPLE_ID);
      PortableServer::POA_var accountPOA = rootPOA->create_POA(
            "bank_account_poa",
            poaManager,
            accountPolicies);
     // Create the account default servant
      PortableServer::Current_var current =
            PortableServer::Current::_instance();
      AccountImpl accountServant(current, accountPOA);
      accountPOA->set_servant(&accountServant);
      // Create the manager POA with the right policies
      CORBA::PolicyList managerPolicies;
      managerPolicies.length(3);
      managerPolicies[(CORBA::ULong)0] =
            rootPOA->create_lifespan_policy(
            PortableServer::PERSISTENT);
      managerPolicies[(CORBA::ULong)1] =
            rootPOA->create_request_processing_policy(
            PortableServer::USE_DEFAULT_SERVANT);
      managerPolicies[(CORBA::ULong)2] =
            rootPOA->create_id_uniqueness_policy(
            PortableServer::MULTIPLE_ID);
      PortableServer::POA_var managerPOA = 
            rootPOA->create_POA(
            "bank_agent_poa",
            poaManager,
            managerPolicies);
      // Create the manager default servant
      AccountManagerImpl managerServant(&accountServant);
      managerPOA->set_servant(&managerServant);
      // Activate the POA Manager
      poaManager->activate();
      cout << "AccountManager is ready" << endl;
      // Wait for incoming requests
      orb->run();
   } catch(const CORBA::Exception& e) {
      cerr << e << endl;
      return 1;
   }
   return 0;
}
 

コードサンプル18-12 サーバのインプリメンテーション(Java)
 
import org.omg.PortableServer.*;
public class Server {
   public static void main(String[ ] args) {
      try {
         // Initialize the ORB
         org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
         // Get a reference to the rootPOA
         POA rootPOA = POAHelper.narrow(orb.
                                  resolve_initial_references("RootPOA"));
         // Get the POA Manager
         POAManager poaManager = rootPOA.the_POAManager();
         // Create the account POA with the right policies
         org.omg.CORBA.Policy[ ] accountPolicies = {
            rootPOA.create_servant_retention_policy(
               ServantRetentionPolicyValue.NON_RETAIN),
            rootPOA.create_request_processing_policy(
               RequestProcessingPolicyValue.USE_DEFAULT_SERVANT)
         };
         POA accountPOA = rootPOA.create_POA("bank_account_poa",
               poaManager, accountPolicies);
         // Create the account default servant
         AccountImpl accountServant = new AccountImpl(orb,
                                                         accountPOA);
         accountPOA.set_servant(accountServant);
         // Create the manager POA with the right policies
         org.omg.CORBA.Policy[ ] managerPolicies = {
          rootPOA.create_lifespan_policy(
                  LifespanPolicyValue.PERSISTENT),
          rootPOA.create_request_processing_policy(
                  RequestProcessingPolicyValue.USE_DEFAULT_SERVANT)
         };
         POA managerPOA = rootPOA.create_POA("bank_agent_poa",
               poaManager,managerPolicies);
         // Create the manager default servant
         AccountManagerImpl managerServant =
                           new AccountManagerImpl(orb, accountServant);
         managerPOA.set_servant(managerServant);
         // Activate the POA Manager
         poaManager.activate();
         System.out.println("AccountManager is ready");
         // Wait for incoming requests
         orb.run();
      } catch(Exception e) {
         e.printStackTrace();
      }
   }
}
 

DSIインプリメンテーションは,デフォルトサーバントとして実体化されます。また,POAは該当するポリシーのサポートによって生成されなければなりません。詳細については,「7. POAの使用」を参照してください。