Next Previous Up Top Contents Index

6 The Bank Server

6.6 Implementing CORBA initialization for the bank server

To complete the implementation of the bank server we need to write the code that enters it into the CORBA environment. In detail, we need to:

To do this, we need to make use of some additional operations specified in the CORBA module:

module CORBA {
...
  interface ORB {
...
    typedef string ObjectId;
     exception InvalidName {};
     Object resolve_initial_references (in ObjectId identifier)
       raises (InvalidName);

void run(); void shutdown( in boolean wait_for_completion ); } }

The CORBA standard specifies the ORB operation resolve_initial_references. This operation provides a portable method for applications to obtain initial references to a small set of standard objects (objects other than the initial ORB). These objects are identified by a mnemonic name, using a string knows as an ObjectId. For instance, the ObjectID for an initial POA object is "RootPOA". (References to a select few other objects, such as the "Interface Repository" and "NamingService", can also be obtained in this manner.)

The ORB operation resolve_initial_references returns the object associated with an ObjectId, raising the exception InvalidName for an unrecognized ObjectID.

The run and shutdown operations are useful in multi-threaded programs, such as servers, which, apart from the main thread, need to run a separate request receiver thread for each POA.

(A single threaded application, such as a pure ORB client, does not generally need to use these operations.)

A thread that calls an ORB's run operation simply waits until it receives notification that the ORB has shut down.

Calling run in a server's main thread can then be used to ensure that the server process does not exit until the ORB has been explicitly shut down.

Meanwhile, the shutdown operation instructs the ORB, and its object adapters, to shut down.

If the wait_for_completion parameter is TRUE, the operation blocks until all pending ORB processing has completed, otherwise it simply shuts down the ORB immediately.

define method initialize-server ()

let location-service = get-location-service();

// get reference to ORB let orb = CORBA/ORB-init(make(CORBA/<arg-list>), "Functional Developer ORB");

// get reference to root POA, initially in the holding state let RootPOA = CORBA/ORB/resolve-initial-references(orb, "RootPOA");

with-dbms ($dbms) // connect to the database let database = make(<database>, datasource-name: $datasource-name); let user = make(<user>, user-name: $user-name, password: $user-password); let connection = connect(database, user);

// make the server frame, initialize and refresh it. let server-frame = make(<server-frame>, connection: connection); server-frame.refresh-check-button.gadget-value := #t; refresh(server-frame);

// make the bank servant let bank = make(<bank-implementation>, connection: connection, poa: RootPOA, name: "Dylan Bank", server-frame: server-frame);

// get the servant's object reference from the poa let bank-reference = PortableServer/POA/servant-to-reference(bank.poa, bank); // activate the bank's POA using its POA manager. let POAManager = PortableServer/POA/the-POAManager(bank.poa); PortableServer/POAManager/activate(POAManager);

// register the bank with the location service register-bank(orb, location-service, bank-reference);

// create a separate thread to shut down the orb, // unblocking the main thread. make(<thread>, function: method () start-frame(server-frame); CORBA/ORB/shutdown(orb, #t); end method);

// block the main thread CORBA/ORB/run(orb);

// remove from location service unregister-bank(orb, location-service, bank-reference);

// close the bank's connection. disconnect(connection); end with-dbms; end method;

The initialize-server function first initializes the Functional Developer ORB by calling the Dylan generic function CORBA/ORB-init, just as we initialized the ORB in the client. The call returns a CORBA/<ORB> pseudo object.

Invoking CORBA/ORB/resolve-initial-references on this ORB, passing the ObjectID "RootPOA", returns a POA object of class PortableServer/<POA>. This is the CORBA standard method for obtaining the initial POA object. Note that RootPOA is initially in the holding state.

Next, we connect to the database and use the connection to make a bank servant. We register the servant with the POA, RootPOA, and publish the resulting object reference, encoded as a string, according to the location-service requested in the command line arguments. By default this is via a shared file. However, if the following is specified on the command line:

-location-service:naming-service

then a Name Service is used instead. Use the ORB command line option
-ORBname-service to specify the IOR of the Name Service. Be sure to use the same command line options for the client and the server or they will not find each other!

We then obtain the POA Manager for the POA using the POA operation PortableServer/POA/the-POAManager. The call to PortableServer/POAManager/activate moves the POA out of the holding state, into the active state, ready to receive and process incoming requests.

To prevent the server from exiting before having the chance to process any requests, we introduce a new thread. This thread waits until the user responds to a DUIM dialog and then proceeds to shut down the ORB with a CORBA standard call to CORBA/ORB/shutdown. Meanwhile, back in the main thread, the subsequent call to CORBA/ORB/run causes the main thread to block, waiting for notification that the ORB has shut down.

Once the ORB has shut down, the main thread resumes, closes the connection to the bank, and exits, terminating the server application.

The full implementation of the server initialization is in the file init-server.dylan.

This completes the description of our implementation of the server.


Developing Component Software with CORBA - 26 May 1999

Next Previous Up Top Contents Index