POA System Generated Ids

Server

The server creates two POA with SYSTEM_IDS - one for transient objects and the other for persistent objects. It then asks the POAs to create 10 system ids each.

The ORB's POA implementation returns the entire object key to you as the system generated id. It is done so that the POA methods that take the object id as parameter (eg. activate_object_with_id) can check whether this POA instance created the id or not.

The real object id part of the object key for transient objects is the last four bytes, and for the persistent objects, it is the last 8 bytes. For peristent objects the system ids are guaranteed to be unique; you may, for example, use these as a primary key in a database table to store the servant state.

package poaSystemIds;
                                                                           
import util.Util;
                                                                           
import org.omg.CORBA.ORB;
import org.omg.CORBA.Policy;
                                                                           
import org.omg.PortableServer.POA;
import org.omg.PortableServer.Servant;
import org.omg.PortableServer.LifespanPolicyValue;
import org.omg.PortableServer.IdAssignmentPolicyValue;
import org.omg.PortableServer.ImplicitActivationPolicyValue;
                                                                           
import helloWorld.Hello;
import poaHello.HelloImpl;
                                                                           
public class Server
{
    public static void main(String[] args)
    {
    |   try {
    |   |                                                                  
    |   |   // create the jBroker ORB
    |   |   ORB orb = ORB.init(args, null);
    |   |                                                                  
    |   |   // get the root POA
    |   |   POA rootPOA = (POA) orb.resolve_initial_references("RootPOA");
    |   |                                                                  
    |   |   // create a transient, implicit activation, and System IDs POA
    |   |   POA transientPOA = rootPOA.create_POA("transHello", null, 
    |   |       new Policy[] {
    |   |       |   rootPOA.create_lifespan_policy(
    |   |       |       LifespanPolicyValue.TRANSIENT),         // default
    |   |       |   rootPOA.create_id_assignment_policy(
    |   |       |       IdAssignmentPolicyValue.SYSTEM_ID),     // default
    |   |       |   rootPOA.create_implicit_activation_policy(
    |   |       |       ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION)
    |   |       });
    |   |                                                                  
    |   |   // create a persistent, implicit activation, and System IDs POA
    |   |   POA persistentPOA = rootPOA.create_POA("persHello", null,
    |   |       new Policy[] {
    |   |       |   rootPOA.create_lifespan_policy(
    |   |       |       LifespanPolicyValue.PERSISTENT),
    |   |       |   rootPOA.create_id_assignment_policy(
    |   |       |       IdAssignmentPolicyValue.SYSTEM_ID),     // default
    |   |       |   rootPOA.create_implicit_activation_policy(
    |   |       |       ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION)
    |   |       });
    |   |                                                                  
    |   |   // activate all the POAs
    |   |   rootPOA.the_POAManager().activate();
    |   |                                                                  
    |   |   // list system ids generated by transient POA
    |   |   System.out.println("\nTransient Object Ids:\n");
    |   |   listObjectIds(transientPOA, 10);
    |   |                                                                  
    |   |   // list system ids generated by persistent POA
    |   |   System.out.println("\nPersistent Object Ids:\n");
    |   |   listObjectIds(persistentPOA, 10);
    |   |                                                                  
    |   |   System.out.println();
    |   |                                                                  
    |   } catch (Exception ex) {
    |   |   ex.printStackTrace();
    |   }
    }
                                                                           
    static void listObjectIds(POA poa, int number) throws Exception
    {
    |   for (int i=0; i < number; i++) {
    |   |   Util.printBytes(poa.servant_to_id(new HelloImpl()));
    |   }
    }
}

Sample Output from the Server

Notice that the transient object ids always start at 1, while the persistent system generated object ids are always unique.



Copyright © 2003, 2004 Novell, Inc. All rights reserved. Copyright © 2001, 2002, 2003 SilverStream Software, LLC. All rights reserved.