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.
Demonstrate the usage of Persistent IORs.
module POADemo { interface Greetings { string hello( in string strName); }; }; |
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); |
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); |
GreetingsImpl oIGreetings = new GreetingsImpl(); System.Text.Encoding oEncoder = System.Text.Encoding.Default; string strObjId = "MyPersistentObjId"; oMyPoa.activate_object_with_id( oEncoder.GetBytes(strObjId), oIGreetings ); |
oIGreetings._this().setObjectKeyAlias("PersistentDemo"); |
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")); |
a.) Start the Server.
b.) Start the Client.