by Uwe Meding

The Interoperable Object Reference (IOR) is at the heart of many operations in the CORBA communications. The content of an IOR describes how to connect to a resource on the server. In particular it contains IP addresses and port references and descriptions on how to reach an object or resource.

Typically IORs are volatile in the sense that they are valid for the duration of a successful server/client connection. If this connection is severed for whatever reason (say a timeout, network failure etc), then the IOR itself becomes invalid. This poses huge challenge for managing servers and clients in a distributed environment: for the most part recovery and restarting resources in order to get them into a known state can be messy and non-trivial in the least .

One of the salient features of CORBA is the persistent IOR. This enables a client to stay concerned, even if the server holding the object it represents is stopped and restarted. This greatly reduces the amount of recovery a client has to perform and allows for continued operations.

Use the following recipe to create persistent IOR:

1. Initialize the ORB and create an initial portable object adapter (POA)

// CORBA properties, like host, port, ip address etc.
Properties orbProps = new Properties();
    …
// Create the ORB
ORB orb = ORB.init(new String[0], orbProps);
POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
POAManager poaManager = rootPOA.the_POAManager();

2. Create a set of persisting POA policies

Policy[] policies = new Policy[] {
    rootPOA.create_thread_policy(ThreadPolicyValue.ORB_CTRL_MODEL),
    rootPOA.create_id_uniqueness_policy(IdUniquenessPolicyValue.UNIQUE_ID),
    rootPOA.create_implicit_activation_policy(
        ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION),
    rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT),
    rootPOA.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID),
    rootPOA.create_servant_retention_policy(ServantRetentionPolicyValue.RETAIN),
    rootPOA.create_request_processing_policy(
        RequestProcessingPolicyValue.USE_ACTIVE_OBJECT_MAP_ONLY)
};

3. Create an entry POA using the persisting policies

POA entryPOA = rootPOA.create_POA("entry", poaManager, policies);

4. Associate the POA with your main server “session” servant

// Register the servant with the entry POA
MyServerServant server = new MyServerServant();
byte[] oid = "session".getBytes();
entryPOA.activate_object_with_id(oid, server);

5. Save the persistent IOR to a file

org.omg.CORBA.Object obj = entryPOA.id_to_reference(oid);
String serverIor = orb.object_to_string(obj);
try (FileWriter fw = new FileWriter("my.ior")) {
    fw.write(serverIor);
} catch(IOException ioe) {
    …
}

Now you can distribute and use “my.ior” on a CORBA client to persistently connect to a CORBA server.

Leave a Reply