[Erlang Systems]

4 Naming Service

4.1 Why using a Name Service

The name service allows yuo to attach human readable names to distributed objects and manage the names. This makes it more convenient for people and programs to identify objects using names. In addition identifying objects by name allows you to evolve and/or relocate distributed objects without client modification.

4.2 How does the name service work

A name to object association is called a name binding. A name binding is always defined relative to a naming context. A naming context is an object that contains a number of name bindings and provides operations on those bindings. The following figure shows the name bindings within the the /workgroup/services naming context. ( The COSS Naming Service don't specify a syntax for names, but we have used / as separator here as a convenience).

naming_graph
Figure 1: A naming graph

To resolve a name is to determine the object associated with it in a given context. To bind a name is to create a name binding in a given context. A name is always resolved relative a given context. Because a naming context is like any other object you can bind it to a name in another naming context. In this way you can create a naming graph which is a directed graph with nodes and labeled edges where the nodes are contexts. Figure 1 shows an example of a naming graph. The top context is called the initial naming context. This context is a well known location used to share a common name space among multiple programs within this name server domain.

4.3 Using the Naming Service

The basic use cases for the Naming Service are:

Each of theese cases are described below.

4.4 Creating a Naming Context

Just as files vcan be grouped in directories you can group objects into a naming context. Naming contexts are objects and can be created by a factory which in this case is the naming service itself.

  1. Obtain the initial reference to the Naming Service
    NS = corba:resolve_initial_references("NameService").
            
  2. Use the CosNaming::NamingContext::new_context() to create a naming context
    NC = 'CosNaming_NamingContext':new_context(NS).
            

4.5 Binding and unbinding names to objects

The following steps illustrate how to bind/unbind an object reference to/from a name. We use the name /workgroup/services and assume that the naming contexts in the path already has been bound. We also assume that reference to the services context are in the variable Sc.

  1. Use the naming library functions to create a name
    NameComp = lname_component:set_id(lname_component:create(), "object").
    Name = lname:insert_component(lname:create(), NameComp).
            
  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 name binding from an object
    'CosNaming_NamingContext':unbind(Sc, Name).
            

4.6 Resolving a name to an object

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

  1. Obtain the initial reference to the Naming Service to start from
    NS = corba:resolve_initial_references("NameService").
            
  2. Use the naming library functions to create a name path
    NameComp1 = lname_component:set_id(lname_component:create(), "workgroup").
    NameComp2 = lname_component:set_id(lname_component:create(), "services").
    Name = lname:insert_component(lname:create(), NameComp1).
    Name1 = lname:insert_component(Name, NameComp2).
            
  3. Use CosNaming::NamingContext::resolve() to to resolve the name to an object
    Sc = 'CosNaming_NamingContext':resolve(NS, Name1).
            

4.7 Listing the bindings in a Naming Context

  1. Use CosNaming::NamingContext::list() to list all the bindings in a context
    The following code gets and lists up to 10 bindings from a context.
    {BList, BIterator} = 'CosNaming_NamingContext':resolve(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).
            

Warning!

Rememeber that the BindingIterator (BIterator in the example) is an object and therefor must be removed explicitly otherwise you will get dangling processes. Use CosNaming::BindingIterator::destroy() to remove it.

      'CosNaming_NamingContext':destroy(BIterator).
    

4.8 Destroying a Naming Context

The implementation of the naming context as a part of the CosNaming implementation in Orber makes naming contexts persistent until you explicitly remove them (unless you stops all nodes Orber is configured to run on).

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

Copyright © 1991-98 Ericsson Telecom AB