Persistent - Using Persistent Server IORs

Description:

A CORBA objects IOR is generated by the object adaptor. The CORBA Portable Object Adaptor (POA) allows to configure in which way IORs are created.

Setting the right policies, it is possible to configure the POA in a way, that always the same IOR is generated for the same CORBA object (assuming the server process is listening on the same TCP/IP port; this is ensured by setting the '-ORBEndpoint' option.)

With the usage of 'Persistent IORs' it is possible to restart the server process with the same identity.

Source:

\Demo\Persistent

Goal:

Demonstrate the usage of Persistent IORs.


Example

Step 1. The IDL (Persistent.idl):

The IDL is more or less our usual 'Greetings' interface:

    module POADemo
    {
        interface Greetings
        {
            string hello( in string strName);   
        };
    };
    

(Will be compiled into Persistent.cs)

Step 2. The Server (PersistentSrv.cs):

While the implementation of the IDL is trivial (just refer to the "standard" implementation within the Hello example), the interesting point is the configuration of the ORB.

Ensure, that the ORB is always started on the same port (we could provide this options on the command line as well):

  RuntimeConfiguration rc = new RuntimeConfiguration();
  rc.SetApplicationLog(OrbErrorLevel.ERRORS, "SrvLog.log", false);   
  rc.SetORBEndpoint("localhost", 14001, 0);
  m_oOrb = Ics.CORBA._ORB.init(rc); 

Retrieve the root POA and create a child POA with the appropriate policies for creating persistent IORs:

  m_oRootPOA = Ics.PortableServer.POAHelper.narrow( m_oOrb.resolve_initial_references( "RootPOA" ));
  m_oRootPOA.the_POAManager.activate();
    
  Ics.CORBA.Policy[] oPol = new Ics.CORBA.Policy[2];
  oPol[0] = m_oRootPOA.create_lifespan_policy( Ics.PortableServer.LifespanPolicyValue.PERSISTENT);
  oPol[1] = m_oRootPOA.create_id_assignment_policy( Ics.PortableServer.IdAssignmentPolicyValue.USER_ID);   
    
  Ics.PortableServer.POA	oMyPoa  = m_oRootPOA.create_POA( "MyPOA", null, oPol);  

Create a server object and register it with the new child POA under a unique ID:

    GreetingsImpl oIGreetings = new GreetingsImpl();
    
    System.Text.Encoding oEncoder =  System.Text.Encoding.Default;
    string strObjId = "MyPersistentObjId";
    oMyPoa.activate_object_with_id( oEncoder.GetBytes(strObjId), oIGreetings );
    

Set an alias to simplify the object key. This allows to access the object with 'corbaloc' more easily:

    oIGreetings._this().setObjectKeyAlias("PersistentDemo");
    

Step 3. The Client (PersistentClt.cs):

The client obtains the object reference using 'corbaloc' and makes a call to the server:

  RuntimeConfiguration rc = new RuntimeConfiguration();
  rc.SetApplicationLog(OrbErrorLevel.ERRORS, "CltLog.log", false);            
  m_oOrb = Ics.CORBA._ORB.init(rc);			
    
  Ics.CORBA.Object oGreetingsObj = m_oOrb.string_to_object( "corbaloc:iiop:1.2@localhost:14001/PersistentDemo");   
    
  m_oIGreetings  = POADemo.GreetingsHelper.narrow( oGreetingsObj);
  Console.WriteLine("Call hello '{0}', returned '{1}'", "Santa Claus", m_oIGreetings.hello("Santa Claus")); 

Give some time to shutdown & restart the server.
Call the server again with the same reference used the first time (i.e. without rereading the IOR from the flat file):

  Console.WriteLine("\nShutdown and restart the server.");
  Console.WriteLine("(press Enter when ready...)");
  Console.ReadLine();
  Console.WriteLine("Call hello '{0}', returned '{1}'", "Santa Claus", m_oIGreetings.hello("Santa Claus"));   

Step 4. Run the example

a.) Start the Server.

b.) Start the Client.