7.7.3 これらのプロパティはいつ使用するか

幾つかのサーバエンジンプロパティの変更が必要な場合はよくあります。これらのプロパティを変更する方法は必要事項によって異なります。例えば,ポート番号を変更したい場合は,次のようにします。

デフォルトのlistener.portプロパティを変更することは最も単純な方法ですが,デフォルトのサーバエンジンを使用するすべてのPOAに影響を与えます。

特定のPOAのポート番号を変更したい場合は,新しいサーバエンジンを生成し,この新サーバエンジンのプロパティを定義し,さらにPOAの生成時に新サーバエンジンを参照する必要があります。「7.7.1 サーバエンジンプロパティの設定」ではサーバエンジンプロパティの更新方法を説明しました。次に示すコードの一部では,サーバエンジンのプロパティの定義方法とユーザ定義のサーバエンジンポリシーによるPOAの生成方法を示しています。

コードサンプル7-23 特定サーバエンジンによるPOAの生成(C++)

// static initialization
AccountRegistry AccountManagerImpl::_accounts;
int main(int argc, char* const* argv)
{
  try {
  // Initialize the orb
  CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
  // Get the property manager; notice the value returned
  // is not placed into a 'var' type.
  VISPropertyManager_ptr pm = orb->getPropertyManager();
  pm->addProperty("vbroker.se.mySe.host", "");
  pm->addProperty("vbroker.se.mySe.proxyHost", "");
  pm->addProperty("vbroker.se.mySe.scms", "scmlist");
  pm->addProperty("vbroker.se.mySe.scm.scmlist.manager
      .type", "Socket");
  pm->addProperty("vbroker.se.mySe.scm.scmlist.manager
      .connectionMax", 100UL);
  pm->addProperty("vbroker.se.mySe.scm.scmlist.manager
      .connectionMaxIdle", 300UL);
  pm->addProperty("vbroker.se.mySe.scm.scmlist.listener
      .type", "IIOP");
  pm->addProperty("vbroker.se.mySe.scm.scmlist.listener
      .port", 55000UL);
  pm->addProperty("vbroker.se.mySe.scm.scmlist.listener
      .proxyPort", 0UL);
  pm->addProperty("vbroker.se.mySe.scm.scmlist.dispatcher
      .type", "ThreadPool");
  pm->addProperty("vbroker.se.mySe.scm.scmlist.dispatcher
      .threadMax", 100UL);
  pm->addProperty("vbroker.se.mySe.scm.scmlist.dispatcher
      .threadMin", 5UL);
  pm->addProperty("vbroker.se.mySe.scm.scmlist.dispatcher
      .threadMaxIdle", 300UL);
  // Get a reference to the rootPOA
  CORBA::Object_var obj =
      orb->resolve_initial_references("RootPOA");
  PortableServer::POA_var rootPOA =
      PortableServer::POA::_narrow(obj);
  // Create the policies
  CORBA::Any_var seAny(new CORBA::Any);
  // The SERVER_ENGINE_POLICY_TYPE requires a sequence,
  // even if only one engine is being specified.
  CORBA::StringSequence_var engines =
     new CORBA::StringSequence(1UL);
  engines->length(1UL);
  engines[0UL] = CORBA::string_dup("mySe");
  seAny <<= engines;
  CORBA::PolicyList_var policies = new CORBA::PolicyList(2UL);
  policies->length(2UL);
  policies[0UL] = orb->create_policy(
     PortableServerExt::SERVER_ENGINE_POLICY_TYPE, seAny);
     policies[1Ul] = rootPOA->create_lifespan_policy
        (PortableServer::PERSISTENT);
  // Create our POA with our policies
  PortableServer::POAManager_var manager =
     rootPOA->the_POAManager();
  PortableServer::POA_var myPOA = rootPOA->create_POA(
        "bank_se_policy_poa", manager, policies);

  // Create the servant
  AccountManagerImpl* managerServant =
        new AccountManagerImpl();
  // Activate the servant
  PortableServer::ObjectId_var oid =
        PortableServer::string_to_ObjectId("BankManager");
  myPOA->activate_object_with_id(oid ,managerServant);
  // Obtain the reference
  CORBA::Object_var ref =
           myPOA->servant_to_reference(managerServant);
  CORBA::String_var string_ref =
           orb->object_to_string(ref.in());
  ofstream refFile("ref.dat");
  refFile << string_ref << endl;
  refFile.close();
  // Activate the POA manager
  manager->activate();
  // Wait for Incoming Requests
  cout << "AccountManager Server ready" << endl;
  orb->run();
  }
  catch(const CORBA::Exception& e) {
  cerr << e << endl;
  return (1);
  }
return (0);
}

コードサンプル7-24 特定サーバエンジンによるPOAの生成(Java)

// Server.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 property manager
     com.inprise.vbroker.properties.PropertyManager pm =
          ((com.inprise.vbroker.orb.ORB)orb).
                                      getPropertyManager();
     pm.addProperty("vbroker.se.mySe.host", "");
     pm.addProperty("vbroker.se.mySe.proxyHost", "");
     pm.addProperty("vbroker.se.mySe.scms", "scmlist");
     pm.addProperty(
        "vbroker.se.mySe.scm.scmlist.manager.type",
        "Socket");
     pm.addProperty(
        "vbroker.se.mySe.scm.scmlist.manager.connectionMax",
         100);
     pm.addProperty(
        "vbroker.se.mySe.scm.scmlist.
         manager.connectionMaxIdle", 300);
     pm.addProperty(
       "vbroker.se.mySe.scm.scmlist.listener.giopVersion", "1.2");
     pm.addProperty(
       "vbroker.se.mySe.scm.scmlist.listener.type", "IIOP");
     pm.addProperty(
       "vbroker.se.mySe.scm.scmlist.listener.port", 55000);
     pm.addProperty(
       "vbroker.se.mySe.scm.scmlist.listener.proxyPort", 0);
     pm.addProperty(
        "vbroker.se.mySe.scm.scmlist.dispatcher.type",
        "ThreadPool");
     pm.addProperty(
        "vbroker.se.mySe.scm.scmlist.dispatcher.threadMax",
         100);
     pm.addProperty(
        "vbroker.se.mySe.scm.scmlist.dispatcher.threadMin",
         5);
     pm.addProperty(
        "vbroker.se.mySe.scm.scmlist.
         dispatcher.threadMaxIdle",300);
     // get a reference to the rootPOA
     POA rootPOA = POAHelper.narrow(
        orb.resolve_initial_references("RootPOA"));
     // Create our server engine policy
     org.omg.CORBA.Any seAny = orb.create_any();
     org.omg.CORBA.StringSequenceHelper.insert(
        seAny, new String[ ]{"mySe"});
     org.omg.CORBA.Policy sePolicy =
     orb.create_policy(
           com.inprise.vbroker.PortableServerExt.
           SERVER_ENGINE_POLICY_TYPE.value, seAny);
        // Create policies for our persistent POA
        org.omg.CORBA.Policy[ ] policies = {
        rootPOA.create_lifespan_policy(
            LifespanPolicyValue.PERSISTENT),sePolicy
     };
     // Create myPOA with the right policies
     POA myPOA = rootPOA.create_POA("bank_se_policy_poa",
           rootPOA.the_POAManager(),
           policies );
     // Create the servant
     AccountManagerImpl managerServant =
                                  new AccountManagerImpl();
     // Activate the servant
     myPOA.activate_object_with_id(
        "BankManager".getBytes(), managerServant);
     // Obtaining the reference
     org.omg.CORBA.Object ref = myPOA.servant_to_reference(
        managerServant);
     // Now write out the IOR
     try {
        java.io.PrintWriter pw =
              new java.io.PrintWriter(
                        new java.io.FileWriter("ior.dat"));
        pw.println(orb.object_to_string(ref));
        pw.close();
     } catch (java.io.IOException e ) {
        System.out.println(
                  "Error writing the IOR to file ior.dat");
        return;
     }
     // Activate the POA manager
     rootPOA.the_POAManager().activate();
     System.out.println(ref + "is ready.");
     // Wait for incoming requests
     orb.run();
     } catch (Exception e){
        e.printStackTrace();
     }
  }
}