Initializing the server environment

Why and when to perform this task

One of the first tasks for a CORBA server application after startup is to initialize the server environment to perform the following actions:

  1. Get a pointer to the implementation repository.

    The implementation repository is a persistent data store of ImplementationDef objects, each representing a logical CORBA server that has been registered in the repository. A server application typically receives a pointer to the implementation repository by using the CORBA::ImplRepository method. For example:

    ::CORBA::ImplRepository_ptr implrep = new ::CORBA::ImplRepository();
    

  2. Get a pointer to the ImplementationDef associated with the server alias.

    The ImplementationDef, which is obtained from the Implementation Repository, describes the server. For example, it specifies a UUID that uniquely identifies the server throughout a network. Each server must retrieve its own ImplementationDef object from the Implementation Repository (using the ImplRepository class) because the ImplementationDef is a parameter required by the BOA::impl_is_ready method. A server application typically receives a pointer to its ImplementationDef by using the CORBA::ImplRepository find_impldef or find_impldef_by_alias method. For example:

    imp = implrep->find_impldef_by_alias(argv[1] );
    

    where argv[1] is the server alias specified as a string in the command used to start the server.

  3. Initialize the Object Request Broker (ORB) and BOA.

    This action is used to initialize the ORB and BOA and to return a pointer to each.

    A server application initializes the ORB by calling the CORBA::ORB_init() method, which also returns a pointer to the ORB. (If necessary, this method creates a new instance of the ORB.) For example, the following code extract initializes the ORB and returns a pointer to it:

    op = ::CORBA::ORB_init(argc, argv, "DSOM");
    

    where argc and argv refer to the properties specified in the command used to start the server.

    A server application initializes the BOA by calling the CORBA::BOA_init() method on the ORB. For example, the following code extract initializes the BOA and returns a pointer to it:

    bp = op->BOA_init(argc, argv, "DSOM_BOA");

    where argc and argv refer to the properties specified in the command used to start the server. Using the BOA_init() method, you must specify DSOM_BOA after the parameter argv.

  4. Register the server application as a CORBA server.

    This action calls the CORBA::BOA::impl_is_ready method to initialize the server application as a CORBA server. This method initializes the server's communications resources so that it can accept incoming request messages and export objects. For example, the following code extract registers the server (with the alias specified on the command used to start the server):

    bp->impl_is_ready(imp, 0 );
    

    Note: The zero (0) value indicates that the server must not register itself with the location service daemon because CORBA servers within WebSphere Application Server support transient objects only. This parameter is an IBM extension to the CORBA specification and must be specified only for lightweight servers of transient objects.

The following example illustrates the initialization code that must be added to the server's main() function:

int main( int argc, char *argv[] )
{
   // Replace "servantServer" with the appropriate server alias.
   const char *serverAlias = "servantServer";

   // Create the implementation repository.
   ::CORBA::ImplRepository *implRep    = new ::CORBA::ImplRepository();

   // Find this server's implementation definition.
   ::CORBA::ImplementationDef *implDef = implRep->find_impldef_by_alias ( serverAlias );

   if ( implDef == NULL )
   {
      cerr << "Error: could not find the implementation definition: " 
           << serverAlias << endl;
      return 1;
   }

   ::CORBA::ORB_ptr orbPtr = ::CORBA::ORB_init ( argc, argv, "DSOM" );
   if ( ::CORBA::is_nil(orbPtr) )
   {
      cerr << "Error: could not initialize the ORB." << endl;
      return 2;
   }

   ::CORBA::BOA_ptr boaPtr = orbPtr->BOA_init ( argc, argv, "DSOM_BOA" );
   if ( ::CORBA::is_nil(boaPtr) )
   {
      cerr << "Error: could not initialize the BOA." << endl;
      return 3;
   }

   try
   {
      bp->impl_is_ready ( implDef, 0 );
   }
   catch ( ::CORBA::SystemException &e )
   {
      cerr << "Error: received system exception: " << e.id() 
           << ", minor code " << (void *) e.minor() << endl;
   }
   catch ( ... )
   {
      cerr << "Error: received unknown exception." << endl;
   }

   .
   .
   .

   return 0; 
} 

What to do next

Add code to the server source file to enable the server to access naming contexts as described in Adding code to access naming contexts.

Related tasks
Creating the CORBA server main code (server.cpp)



Searchable topic ID:   tcor_pgms5c
Last updated: Jun 21, 2007 8:07:48 PM CDT    WebSphere Business Integration Server Foundation, Version 5.0.2
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.wasee.doc/info/ee/corba/tasks/tcor_pgms5c.html

Library | Support | Terms of Use | Feedback