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()));
| }
}
}
Transient Object Ids:
4a424b5200020001e180b8084dab88fb00000001
4a424b5200020001e180b8084dab88fb00000002
4a424b5200020001e180b8084dab88fb00000003
4a424b5200020001e180b8084dab88fb00000004
4a424b5200020001e180b8084dab88fb00000005
4a424b5200020001e180b8084dab88fb00000006
4a424b5200020001e180b8084dab88fb00000007
4a424b5200020001e180b8084dab88fb00000008
4a424b5200020001e180b8084dab88fb00000009
4a424b5200020001e180b8084dab88fb0000000a
Persistent Object Ids:
4a424b520003000200000101246ac6780000000000000001
4a424b520003000200000101246ac6780000000000000002
4a424b520003000200000101246ac6780000000000000003
4a424b520003000200000101246ac6780000000000000004
4a424b520003000200000101246ac6780000000000000005
4a424b520003000200000101246ac6780000000000000006
4a424b520003000200000101246ac6780000000000000007
4a424b520003000200000101246ac6780000000000000008
4a424b520003000200000101246ac6780000000000000009
4a424b520003000200000101246ac678000000000000000a
Transient Object Ids:
4a424b5200020001e181615c4dab88fb00000001
4a424b5200020001e181615c4dab88fb00000002
4a424b5200020001e181615c4dab88fb00000003
4a424b5200020001e181615c4dab88fb00000004
4a424b5200020001e181615c4dab88fb00000005
4a424b5200020001e181615c4dab88fb00000006
4a424b5200020001e181615c4dab88fb00000007
4a424b5200020001e181615c4dab88fb00000008
4a424b5200020001e181615c4dab88fb00000009
4a424b5200020001e181615c4dab88fb0000000a
Persistent Object Ids:
4a424b520003000200000101246ac6780000000000000015
4a424b520003000200000101246ac6780000000000000016
4a424b520003000200000101246ac6780000000000000017
4a424b520003000200000101246ac6780000000000000018
4a424b520003000200000101246ac6780000000000000019
4a424b520003000200000101246ac678000000000000001a
4a424b520003000200000101246ac678000000000000001b
4a424b520003000200000101246ac678000000000000001c
4a424b520003000200000101246ac678000000000000001d
4a424b520003000200000101246ac678000000000000001e
| Copyright © 2000-2003, Novell, Inc. All rights reserved. |