[Erlang Systems]

7 CosNaming Service

7.1 Overview of the CosNaming Service

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:

A name is allways 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 directive 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 refered 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.

name
Figure 1: Contextual object relationships using the Naming Service.

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 alpha from one context or gamma from another.

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 beta and epsilon, which are bound to other naming contexts. The initial naming context is a well known location used to share a common name space between multiple programs. You can traverse the naming graph until you reach a name, which is bound to an object, which is not a naming context.

We recommend reading chapter 12, CORBA Fundamentals and Programming, for detailed information regarding the Naming Service.

7.2 The Basic Use-cases of the Naming Service

The basic use-cases of the Naming Service are:

7.2.1 Fetch initial reference to the naming service

In order to use the naming service you have to fetch an initial reference to it. This is done with:

   NS = corba:resolve_initial_reference("NameService").
      

Note!

NS in the other use-cases refers to this initial reference.

7.2.2 Creating a naming context

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"])).
      

7.2.3 Binding and unbinding names to objects

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 /workgroup/services, and that reference to the services context are in the variable Sc.

  1. Use the naming library functions to create a name
    Name = lname:new(["object"]).
            
  2. Use CosNaming::NamingContext::bind() to bind a name to an object
    'CosNaming_NamingContext':bind(Sc, Name, Object).
            
  3. Use CosNaming::NamingContext::unbind() to remove the NameBinding from an object
    'CosNaming_NamingContext':unbind(Sc, Name).
            

Note!

Objects can have more than one name, to indicate different paths to the same object.

7.2.4 Resolving a name to an object

The following steps show how to retrieve the object reference to the service context above (/workgroup/services).

  1. Use the naming library functions to create a name path:
    Name = lname:new(["workgroup", "services"]).
            
  2. Use CosNaming::NamingContext::resolve() to to resolve the name to an object
    Sc = 'CosNaming_NamingContext':resolve(NS, Name).
            

7.2.5 Listing the bindings in a NamingContext

  1. 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).
            

Note!

Normally a BindingIterator is helpful in situations where you have a large number of objects in a list, as the programmer then can traverse it more easily. In Erlang it is not needed, because lists are easily handled in the language itself.

Warning!

Remember that the BindingIterator (BIterator in the example) is an object and therefore must be removed otherwise dangling processes will occur. Use CosNaming::BindingIterator::destroy() to remove it.

      'CosNaming_NamingContext':destroy(BIterator).
    

7.2.6 Destroying a naming context

The naming contexts are persistent and must be explicitly removed. (they are also removed if all Orber nodes in the domain are stopped).

  1. Use CosNaming::NamingContext::destroy() to remove a NamingContext
    'CosNaming_NamingContext':destroy(Sc).
            

Copyright © 1991-1999 Ericsson Utvecklings AB