Homepage of Ingo Klöckl
 Home
 Programmieren
 - Toolbox
 - Java
 - PostScript
 - Perl
 - Assembler
 - Links
 - Download
Ingo Klöckl
i.kloeckl@2k-software.de

Programming CORBA with Orbacus on Linux

POA creation and usage

Getting a root POA

Before creating own POAs, a reference to a root POA must be found. This can be done by resolving the initial service named "RootPOA" as follows:

PortableServer::POA_var rootPOA;
try {
  CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
  if (CORBA::is_nil(obj)){
    // handle this error
  }
  rootPOA = PortableServer::POA::_narrow(obj);
  if (CORBA::is_nil(myPOA)){
    // handle this error
  }
} catch (const CORBA::ORB::InvalidNames& e){
  // "RootPOA" was invalid, should not occur
} catch (const CORBA::SystemException& e){
  // something else was wrong
}
As a result, you got a reference to a root POA object, which you may use directly or using for the creation of other, new POAs.

An example of getting a root POA is given here.

Activation of POAs

Every POA must be activated before it can process requests (meaning dispatching requests to the CORBA objects and servants it manages). Even the default POA, called the root POA, in the simplest server programs must be activated by a method of its corresponding POA manager:

PortableServer::POAManager::activate();
The POA manager can be retrieved by the method the_POAManager() of a POA. Typically, you activate a POA as follows:
PortableServer::POA_var rootPOA = <get root POA as above>;
PortableServer::POAManager_var manager = rootPOA->the_POAManager();

// activate POA manager
manager->activate();

An example of activating a root POA is given here.

Creation of POAs

If you have a reference to a root POA, you can use it for the creation of your own POA. Typically, you do this if you need POAs with special policies. The creation of a new POA is done with the method

PortableServer::POA_ptr 
  PortableServer::POA::create_POA(<newPOAname>, <POAmanager>, <policies>)
The method gets a string with the name of the new POA, a POA manager which handles requests for this POA, and an object with the desired policies for this POA. It returns a reference to the new POA.

The method may return a nil reference and raise some exceptions, so a typical usage is as follows:

PortableServer::POA_var rootPOA = <get root POA as above>;

PortableServer::POA_var myPOA;
PortableServer::POAManager_var myPOAManager;
try {
  CORBA::PolicyList policies;
  policies.length(2);
  policies[0] = rootPOA->create_id_assignment_policy(PortableServer::USER_ID);
  policies[1] = rootPOA->create_lifespan_policy(PortableServer::PERSISTENT);

  myPOAManager = rootPOA->the_POAManager();
  myPOA = rootPOA->create_POA("MyPOA", myPOAManager, policies);
  if (CORBA::is_nil(myPOA)){
    // handle this error
  }

  // activate POA manager
  myPOAManager->activate();

  <>use new POA for interesting things>
} catch (const PortableServer::POA::AdapterAlreadyExists& e){
  // this POA already exists
  try {
    myPOA = rootPOA->find_POA("MyPOA", 0);
  } catch (const PortableServer::POA::AdapterNonExistent&){
    // strange
  }
} catch (const PortableServer::POA::InvalidPolicy& e){
  // the choosen policy combination is invalid
}
For simplicity, we use the POA manager of the root POA instead of create our own. The root POA's manager can often be used for newly created POAs. The new POAs must be activated by invoking the activate method on the manager belonging to this POA. This can be done after creation of the POA, but must at least be done before entering the ORB loop because the ORB may want to dispatch requests to the new POA, and it should be able to react to these requests. If more own POAs use the same manager, the activation of this manager may be senseful after the creation of the last new POA.

back to CORBA page