OOPortal OOPortal


Mapping Clients  «Prev  Next»
Lesson 7 Writing a basic server mainline
Objective Describe the Startup Sequence of a Service

Writing a Basic Server Mainline

Writing Corba
Implementation objects, also called servant objects, are the objects that implement IDL interfaces; they embody the CORBA objects that those interfaces define. Like any other objects, these need a process in which to live, this is provided by the CORBA server. A CORBA server creates CORBA objects by creating instances of their implementation classes, and then makes those objects accessible to clients.

Startup sequence

In greater detail, the startup sequence of a basic server is shown in the following illustration:
Startup sequence of basic server

Weather Service example

Continuing with the running Weather Service example, here is a sample basic server for the Weather Service, followed by an explanation of key code elements:

package weather;
//Server class for WeatherService
public class SimpleWeatherServer{
 public static void main( String[] args ){
   org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init (args, null);
   try{
     org.omg.PortableServer.POA poa = 
     org.omg.PortableServer.POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
     POA_WeatherService_tie weatherTIE = 
     new POA_WeatherService_tie(new WeatherServiceOperationsImpl());
     org.omg.CORBA.Object o = poa.servant_to_reference(weatherTIE);
     //Export reference to clients (Module 5)
   } 
   catch (Exception e ) {
     e.printStackTrace();
   }
   orb.run();
 }
}

The ORB.init() call is used to initialize the ORB within an application (step 1). The code for obtaining an initial reference to the POA and using the POA to map from the servant ( weatherTIE ) to an object reference will be fully explained later in the course (steps 2 and 4). The instantiation of the TIE object, which we covered earlier in the module, provides us with our servant object (step 3). Also later in the course, we’ll fill in the code for making the reference given by the POA accessible to clients (step 5). The orb.run() call will put the server into the request processing loop (step 6).
As the course proceeds, we will cover the details inherent in steps 2, 4, and 5 in greater depth and explore more sophisticated server models.
In the next lesson, we will return to mapping issues by examining how IDL interface inheritance maps to Java.

Server Action Sequence

Click on the Exercise link below to test your ability to order the steps for a basic server sequence.
Server Action Sequence