POA - Using Multiple POAs within one CORBA Server

Description:

CORBAs Portable Object Adaptor (POA) owes a good part of its flexibility the fact that starting with the root POA a whole tree of child POAs may be created, each of it with a different configuration given by different policies.

The POA which creates the object reference is used for all calls on this reference.

Source:

\Demo\POA

Goal:

Demonstrate the usage of multiple POAs within one server process.


Example

Step 1. 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)

Step 2. The Server (POASrv.cs):

The implementation of the IDL is trivial (just the "standard" implementation within the Hello example), but we enhance it with a local method, displaying some informations about the object adaptor:

    public class GreetingsImpl: POADemo.GreetingsPOA
    {
        public override string hello(  string a_strmyName)
        {
            System.Console.WriteLine("Function 'OATest' Parameter '{0,20}'", a_strmyName);     
            
            displayInfo();
            return "Greetings to " + a_strmyName;
        }
        
        public void displayInfo()
        {
            Console.WriteLine( "My POA          :{0}", _poa().the_name);
            Console.WriteLine( "The Default POA :{0}", _default_POA().the_name);
            byte[] oId = this._object_id();
            Console.WriteLine( "Object ID       :{0}", System.BitConverter.ToString(oId));
            Ics.CORBA.Object  oObj = _this_object();
            oObj.printIOR();
        }
    }
    

Retrieve a reference to the root POA from the ORB and activate the root POA:

    m_oRootPOA = Ics.PortableServer.POAHelper.narrow( m_oOrb.resolve_initial_references( "RootPOA" ));
    m_oRootPOA.the_POAManager.activate();  

Create child POAs, some of them with specific policies, and create an object reference using one of them:

    Ics.CORBA.Policy[] oPol = new Ics.CORBA.Policy[1];
    oPol[0] = m_oRootPOA.create_implicit_activation_policy( Ics.PortableServer.ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION);    
    
    Ics.PortableServer.POA	oPOA_A      = m_oRootPOA.create_POA( "A", null, null);
    Ics.PortableServer.POA	oPOA_AA_1   = oPOA_A.create_POA( "AA_1",  null, null);
    Ics.PortableServer.POA	oPOA_AA_2   = oPOA_A.create_POA( "AA_2",  null, null);
    
    Ics.PortableServer.POA	oPOA_B      = m_oRootPOA.create_POA( "B", null, null);
    Ics.PortableServer.POA	oPOA_BB_1   = oPOA_B.create_POA( "BB_1",  null, null);
    Ics.PortableServer.POA	oPOA_BB_2   = oPOA_B.create_POA( "BB_2",  null, oPol);
    
    GreetingsImpl oGreetingsImpl = new GreetingsImpl();
    
    Ics.CORBA.Object oObjRef = oPOA_BB_2.servant_to_reference( oGreetingsImpl); 

Publish the object reference as usual:

    
    Ics.CORBA._ORB.wrIORtoFile( "c:\\POADemo.ior", oObjRef );  

Note, that calls to the server object using this reference will always be routed over the child POA named "BB_2".

Step 3. The Client (POAClt.cs):

The client obtains the servers reference as usual from a flat file at startup and calls the server:

    Ics.CORBA.Object oGreetingsObj = m_oOrb.string_to_object( "file://c:\\POADemo.ior");   
    
    m_oIGreetings  = POADemo.GreetingsHelper.narrow( oGreetingsObj);
    
    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.