Main page / CORBA with MinCor.NET page

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 not only possible to restart the server 
	process	with the same identity, but also to use corbaloc-URLs to address own
	server objects.


Source: 
	MinCor\Demo\Persistent

Goal: 
	Demonstrate the usage of Persistent IORs.



Example 

The IDL (POADemo.idl):

    The IDL is more or less our usual 'Greetings' interface:
    
    module POADemo
    {
        interface Greetings
        {
            string hello( in string strName);
        };
    };
    
    (Will be compiled into POADemo.cs)



The Server (ServerImpl.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):
    
    string[] m_strORBInit = { "-ORBEndpoint iiop://localhost:8545", 
                              "-ORBDebug Out=.\\PersistentSrv.log",
                              "-ORBKeyAlias PersitentDemo=RootPOA/MyPOA/-MT-/MyPersistentObjId"};
                             
    m_oOrb = Middsol.CORBA._ORB.init( m_strORBInit, null);
    
    
    Retrieve the root POA and create a child POA with the appropriate policies 
    for creating persistent IORs:
    
    m_oRootPOA = Middsol.PortableServer.POAHelper.narrow( m_oOrb.resolve_initial_references( "RootPOA" ));
    m_oRootPOA.the_POAManager.activate();
    
    Middsol.CORBA.Policy[] oPol = new Middsol.CORBA.Policy[2];
    oPol[0] = oRootPOA.create_lifespan_policy( Middsol.PortableServer.LifespanPolicyValue.PERSISTENT);
    oPol[1] = oRootPOA.create_id_assignment_policy( Middsol.PortableServer.IdAssignmentPolicyValue.USER_ID);
    
    Middsol.PortableServer.POA	oMyPoa  = 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( this );
    
    System.Text.Encoding oEncoder =  System.Text.Encoding.Default;
    string strObjId = "MyPersistentObjId";
    oMyPoa.activate_object_with_id( oEncoder.GetBytes(strObjId), oIGreetings );
    
    
    
The Client (ClientImpl.cs):

    The client obtains the servers reference using corbaloc-URL:
    
    Middsol.CORBA.Object oGreetingsObj = oOrb.string_to_object( "corbaloc:iiop:1.1@localhost:8545/PersitentDemo");
    
    POADemo.Greetings oIGreetings  = POADemo.GreetingsHelper.narrow( oGreetingsObj);
    
    string srLog = "\nReturn Prameter:" + oIGreetings.hello("Hans");
    
    
    Note, that the object ID string within the URL is not identical with the object ID 
    used by the server to activate the object, but will be mapped into the correct POA path
    by a servers ORB initialization parameter:
    
    "-ORBKeyAlias PersitentDemo=RootPOA/MyPOA/-MT-/MyPersistentObjId"