The CosNaming Service is a service developed to help users and programmers identify objects by human readable names rather than by a reference. By binding a name to a naming context (another object), a contextual reference is formed. This is helpful when navigating in the object space. In addition, identifying objects by name allows you to evolve and/or relocate objects without client code modification.
The CosNaming service has some concepts that are important:
name binding - a name to object association.
naming context - is an object that contains a set of name bindings in which each name is unique. Different names can be bound to the same object.
to bind a name - is to create a name binding in a given context.
to resolve a name - is to determine the object associated with the name in a given context.
A name is always resolved in a context, there no absolute names exist. Because a context is like any other object, it can also be bound to a name in a naming context. This will result in a naming graph (a directed graph with notes and labeled edges). The graph allows more complex names to refer to an object. Given a context, you can use a sequence to reference an object. This sequence is henceforth referred to as name and the individual elements in the sequence as name components. All but the last name component are bound to naming contexts.
The diagram in figure 1 illustrates how the Naming Service provides a contextual relationship between objects, NamingContexts and NameBindings to create an object locality, as the object itself, has no name.
The naming contexts provide a directory of contextual reference and naming for objects (an object can appear to have more than one name).
In figure 1 the object to the right can either be
called
The Naming Service has an initial naming context, which is shown
in the diagram as the top-most object in the naming graph.
It has two names
We recommend reading chapter 12, CORBA Fundamentals and Programming, for detailed information regarding the Naming Service.
The basic use-cases of the Naming Service are:
In order to use the naming service you have to fetch an initial reference to it. This is done with:
NS = corba:resolve_initial_references("NameService").
NS in the other use-cases refers to this initial reference.
There are two functions for creating a naming context. The first function, which only creates a naming context object is:
NC = 'CosNaming_NamingContext':new_context(NS).
The other function creates a naming context and binds it to a name in an already existing naming context (the initial context in this example):
NC = 'CosNaming_NamingContext':bind_new_context(NS, lname:new(["new"])).
The following steps illustrate how to bind/unbind an object reference
to/from a name. For the example below, assume that the NamingContexts
in the path are already bound to the name
Use the naming library functions to create a name
Name = lname:new(["object"]).
Use CosNaming::NamingContext::bind() to bind a name to an object
'CosNaming_NamingContext':bind(Sc, Name, Object).
Use CosNaming::NamingContext::unbind() to remove the NameBinding from an object
'CosNaming_NamingContext':unbind(Sc, Name).
Objects can have more than one name, to indicate different paths to the same object.
The following steps show how to retrieve the object reference to the service context above (/workgroup/services).
Use the naming library functions to create a name path:
Name = lname:new(["workgroup", "services"]).
Use CosNaming::NamingContext::resolve() to to resolve the name to an object
Sc = 'CosNaming_NamingContext':resolve(NS, Name).
An alternative is to use:
Sc = corba:string_to_object("corbaname:rir:/NameService#workgroup/services/").
The
Use CosNaming::NamingContext::list() to list all the bindings in a context
The following code retrieves and lists up to 10 bindings from a context.
{BList, BIterator} = 'CosNaming_NamingContext':list(Sc, 10).
lists:foreach(fun({{Id, Kind},BindingType}) -> case BindingType of
nobject ->
io:format("id: %s, kind: %s, type: object~n", [Id, Kind]);
_ ->
io:format("id: %s, kind: %s, type: ncontext~n", [Id, Kind])
end end,
Blist).
Normally a
Remember that the BindingIterator (BIterator in the example) is an object and therefore
must be removed otherwise dangling processes will occur.
Use
'CosNaming_NamingContext':destroy(BIterator).
The naming contexts are persistent and must be explicitly removed. (they are also removed if all Orber nodes in the domain are stopped).
Use CosNaming::NamingContext::destroy() to remove a NamingContext
'CosNaming_NamingContext':destroy(Sc).
The OMG specifies URL schemes, which represent a CORBA object and a CORBA object bound in a NamingContext, for resolving references from other ORB:s. As of today, three schemes are defined:
A stringified IOR is a valid URL format but difficult for humans to handle through non-electronic means. This URL format does not depend on a specific Name Service and, thus, is robust and insulates the client from the encapsulated transport information and object key used to reference the object.
The notation of this scheme is similar to the more well known URL
= "corbaloc:"["/"]
= [","]*
= |
= |
= ":"
= rir
=
= ":"
=
= | ":"
= ":"
= "iiop"
= [":"]
= DNS-style Host Name | ip_address
= ".""@" | empty_string
= number
= number
= number
= for example NameService
]]>
The
A
Currently, the OMG defines a set of reserved keys and the type of object,
listed below, they should be associated with. The
1> Factory = cosNotificationApp:start_global_factory().
2> corba:add_initial_service("NotificationService", Factory).
This object can then be easily resolved by any other ORB, supporting the Interoperable Naming Service, by using:
3> NF = corba:string_to_object("corbaloc::1.0@erlang.org:4001/NotificationService").
The
= "corbaname:"["/"]["#"]
= as described above.
= as described above.
]]>
The
After creating a stringified Name we can either use:
NameStr = "org.erlang",
NS = corba:resolve_initial_references("NameService"),
Obj = 'CosNaming_NamingContextExt':resolve_str(NS, NameStr),
or concatenate the Name String using:
NameStr = "Swedish/Soccer/Champions",
Address = "corbaname:iiop:1.0@www.aik.se:2000/NameService",
NS = corba:resolve_initial_references("NameService"),
URLStr = 'CosNaming_NamingContextExt':to_url(NS, Address, NameStr),
Obj = corba:string_to_object(URLStr),
Using the first alternative, the configuration variables
The function