[omniORB] Persistent Objects Question

jnye@micro-optics.com jnye@micro-optics.com
Mon, 29 Jan 2001 10:53:53 -0400


Hi All,

I'm not sure if this is an omni-specific question, or if this is just a
misunderstading I have with persistent references. To start off, here is my
understanding of how persistent references work:

Persistent references outlive the process in which the objects they refer to
live. This means that theoretically, I should be able to create a persistent
object reference, write it to disk in some registry at software installation
time and it should never have to be updated (unless the server code changes
somehow and even then, I'm not sure if it should change if the interface did
not change).


My Goal:

I'm kind of adopting COM's installation method where If I want CORBA objects
to reside in Dlls, their Dlls will get registered in the system with an
exported DllRegisterServer and servers in executables will use a command
line switch of /regserver to install themselves -> this will result in a
persistent IOR being written to some globally accessible registration
database or file. When the server executables are run with the /regserver
command line option, they register themselves then simply exit.


My Problem:

The infrastructure is all set up, the only problem that I am having now is
setting up a persistent reference. I run my test server exe as

myobject.exe /regserver

It indeed registers an IOR in a registration database, but when clients
attempt to use the IOR, they get a COMM_FAILURE exception. If I change the
myobject code to register the IOR each time it is started (which is
undesirable), clients can access the server with no problem. In other words,
the server's IOR is not persistent for some reason.


My Code:

I've included the main program for the server which creates a child POA with
the persistent and user id assignment policies, then calls
create_reference_with_id on that child POA with an id that I created using
string_to_ObjectId. I would expect for that reference to be the same each
time since it is persistent. Not so -- clients can't use it across server
restarts, either.


Can someone review my code and tell me what I am doing wrong?

TIA,
Jason



//////// Code
////////////////////////////////////////////////////////////////


int main(int argc, char * argv)
{
    try
    {
        namespace PS = PortableServer;  // Easier to read!!

        // Initialize the orb
        CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

        // Get reference to Root POA
        CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
        PS::POA_var poa = PS::POA::_narrow(obj);

        // Activate POA manager
        PS::POAManager_var mgr = poa->the_POAManager();

        PS::LifespanPolicy_var lifespan =
poa->create_lifespan_policy(PS::PERSISTENT);
        PS::IdAssignmentPolicy_var assign =
poa->create_id_assignment_policy(PS::USER_ID);

        CORBA::PolicyList poaPolicyList;
        poaPolicyList.length(2);
        poaPolicyList[0] = PS::LifespanPolicy::_duplicate(lifespan);
        poaPolicyList[1] = PS::IdAssignmentPolicy::_duplicate(assign);

        PS::POA_var childPOA = poa->create_POA("MyObjectPOA", mgr,
poaPolicyList);
        lifespan->destroy();
        assign->destroy();

        MyObjectImpl servant;
        PS::ObjectId_var oid = PS::string_to_ObjectId("MyObject");

        // Just register and exit.
        if (findCmdLineArg(argc, argv, "/RegServer"))
        {
            // Object registration/unregistration.
            try
            {
                CORBA::Object_var ref =
childPOA->create_reference_with_id(oid, "IDL:MyObject:1.0");
                CORBA::String_var ior = orb->object_to_string(ref);

                // Simply writes a reference to a globally accessable
registration file in the form:
                //
                // MyObject=IOR:.....
                //
                ObjectRegistrar::registerIOR("MyObject", (const char *)ior);
            }
            catch (...)
            {
                ::MessageBox(0, "Failed to register IOR", "MyObject", 0);
                return -1;
            }
        }
        else
        {
            // Normal execution of server.
            mgr->activate();

            // Activate object.
            childPOA->activate_object_with_id(oid, &servant);
            orb->run();
        }
    }
    catch(const CORBA::Exception &e )
    {
        int size;
        cout << e._NP_repoId(&size) << endl;
        return -1;
    }

    return 0;
}