[omniORB] How to use more than one naming server?
Duncan Grisby
dgrisby@uk.research.att.com
Wed, 17 Oct 2001 11:15:06 +0100
On Tuesday 16 October, Mark Johnson wrote:
> I'm confused from reading the documentation about how to configure a server
> and a client to use redundant naming servers. We have to run our
> applications to use a fail over naming service in case we lose the primary
> name server.
>
> But I'm confused, in the examples they always the ORB_init() method to pass
> the command line and always use "RootPOA" to register the servant. If I
> wanted to use two (or more) naming services and have the servant register
> with all of them would I do something like this?
No :-)
You are mixing up several independent things. First, there is a _big_
difference between activating a servant in a POA, and registering the
associated object in a Naming service. I guess the cause of your
confusion is that you get references to both the Root POA and the
Naming service from resolve_initial_references().
Server programs incarnate CORBA objects by activating servants in
POAs. All POAs are created as children of the Root POA, which is
obtained with a call to resolve_initial_references("RootPOA"). For
many simple applications, it is sufficient to activate all servants in
the Root POA. Note that this has nothing whatsoever to do with
registering the resulting objects in a Naming service.
Once an application has created an object reference (by incarnating a
servant or by some other means), it may _choose_ to export that object
reference somewhere. It might do that by printing an IOR string, or it
might register it with some service. The Naming service is one
example service. The application is under no obligation to export the
object reference at all.
Services like the Naming service are just collections of CORBA
objects. You obtain a reference to a NamingContext object from
somewhere, and call operations on it to bind your object reference
with the desired name. Note that this has nothing at all to do with
where the object reference you are binding came from. Often it is a
reference to an object incarnated by the calling application, but it
could just as easily be a reference received from somewhere else.
So now the question is where to get a reference to a NamingContext
from. One option is to configure the ORB with some initial references,
to be returned from resolve_initial_references(). That's what
-ORBInitRef does. You can bind any kind of object reference you like
to any name you like. So you could do something like your suggestion,
but note the two -ORBInitRefs:
myserver -ORBInitRef FOO=corbaname::foo.onfiber.com -ORBInitRef
BAR=corbaname::bar.onfiber.com
This allows you to use resolve_initial_references() to get hold of
your different Naming service references. Remember that this has
noting to do with activating servants or POAs. e.g.:
CORBA::Object_var obj;
obj = orb->resolve_initial_references("FOO");
CosNaming::NamingContext_var foo_nc = CosNaming::NamingContext::_narrow(obj);
obj = orb->resolve_initial_references("BAR");
CosNaming::NamingContext_var bar_nc = CosNaming::NamingContext::_narrow(obj);
foo_nc->bind(myname, myobj);
bar_nc->bind(myname, myobj);
There is nothing magical about the objects returned by
resolve_initial_references(). If the machines running the Naming
services never change, it might be easier to hard code the references
in the program, and use string_to_object():
CORBA::Object_var obj;
obj = orb->string_to_object("corbaname::foo.onfiber.com");
CosNaming::NamingContext_var foo_nc = CosNaming::NamingContext::_narrow(obj);
obj = orb->string_to_object("corbaname::bar.onfiber.com");
CosNaming::NamingContext_var bar_nc = CosNaming::NamingContext::_narrow(obj);
I hope that helps,
Duncan.
--
-- Duncan Grisby \ Research Engineer --
-- AT&T Laboratories Cambridge --
-- http://www.uk.research.att.com/~dpg1 --