[omniORB] Is a servant allowed as member variable of another servant?

scott.rediger at teradyne.com scott.rediger at teradyne.com
Fri Jan 23 09:40:53 GMT 2004


>I created an instance of the servant for A as a member variable of B,
>and used the _this() function to get a reference.  This didn't work.

_this() is OK as long as you are using the root POA. If B is in a child POA
of the Root POA, then this could explain your situation. Generally
speaking, your code is more maintainable over time (in case it ever uses
more than one POA) if you do the following:
      specificPOA->activate_object(new_servant); // to activate a servant
object in a specific POA
      CORBA::Object_var obj =
specificPOA->servant_to_reference(new_servant); // to get the CORBA object
reference you need

>I guess the only reason B wouldn't show up in the NS, would be that
>the B servant constructor never returned...?  The B servant
>constructor constructs an A servant, and then calls _this() on the A
>servant, to get a POA managed object reference.

>Perhaps the timing of the calling of _this(), on the A servant is the
>problem?

>This call to _this() is done before the B servant constructor has
>completed, and before _this() has been called on the B servant.

I have done something similar to what you are doing except that there is a
login() method in B's interface which creates an A servant, and activates
it, then returns it to the caller. It works fine.

I have a feeling the problem lies in the fact that you are performing A.
_this() this in the constructor of your servant class B, which is still
under construction, and it depends on the state of the ORB from your B's
perspective.

Try doing the A creation and NS registration in your main() method before
your B creation, then having B get A's ref from the NS only once and then
cache it. This would show whether it is a problem with doing it in the
constructor.

FWIW,
ScottR





More information about the omniORB-list mailing list