[omniORB] Persistent Obj Refs.

Duncan Grisby dgrisby@uk.research.att.com
Thu, 21 Jun 2001 11:33:44 +0100


On Tuesday 19 June, Andrew Weaver wrote:

> Moi, here is some modification of eg2_impl from the
> $TOP/src/examples/poa/persistent_objeref
> 
>     // Activate the echo object...
>     Echo_i* myecho = new Echo_i();
> //
> // AWE - 1
> //
>     obj = myecho->_this();
>     CORBA::String_var sior(orb->object_to_string(obj));
>     cerr << "AWE 1 '" << (char*)sior << "'" << endl;
> 
>     poa->activate_object_with_id(oid, myecho);
> //
> // AWE -2
> //
>     obj = myecho->_this();
>     CORBA::String_var sior2(orb->object_to_string(obj));
>     cerr << "AWE 2 '" << (char*)sior2 << "'" << endl;
> 
> With the code like this, I get the same string for the IOR from the AWE -1
> block as from AWE-2. However, this string is not the same from run to run.

There has been a huge amount of misinformation in this thread. The
problem with the above code is that the call to myecho->_this()
activates the object in the Root POA, not the persistent POA that has
just been created. The original code says

    // Activate the echo object...
    Echo_i* myecho = new Echo_i();
    poa->activate_object_with_id(oid, myecho);

    obj = myecho->_this();
    CORBA::String_var sior(orb->object_to_string(obj));
    cerr << "'" << (char*)sior << "'" << endl;

The vital call is the activate_object_with_id() call. Once that has
been done, the call to _this() returns a reference the activated
object, rather than activating the servant in the root POA.

_this() is rather evil. Its behaviour changes depending on the context
of the call.

As long as you definitely activate the object in the persistent POA,
the object reference is the same from run to run. Note that the
stringified IORs may still differ slightly since they contain padding
bytes which can be set to arbitrary values. The IOR from one run will
work fine on another run, even if the strings are different.

Cheers,

Duncan.

-- 
 -- Duncan Grisby  \  Research Engineer  --
  -- AT&T Laboratories Cambridge          --
   -- http://www.uk.research.att.com/~dpg1 --