Notes
Outline
The Naming Service (Client’s View)
A tree-like directory for object references
Much like a file system: provides directory structure for files
Object references are stored by name
Each object reference-name pair is called a name binding
Name bindings may be organized under naming contexts (name binding itself)
All bindings are stored under initial naming context (the only persistent binding)
The Naming Service….
Your client’s ORB must know the name and port# of a host running the naming service
The naming service can either be the JavaIDL naming service or any COS-compliant service
To start: tnameserv –ORBInitialPort port#
The default port number is 900
To stop: use relevant OS command (kill, ctrl-c)
Namespace is lost if name server halts/restarts
The Naming Service (interfaces)
org.omg.CosNaming:
NamingContext: primary interface to naming service
NameComponent: identify (name/kind) services
BindingInterator: iterating through the contents
Binding: a single entry in the naming service
BindingList: a list of entries in the naming service
BindingType: the type of an entry
Naming Service (NamingContext)
Analogous to a directory on a file system
Contains a series of named objects
An object in a NamingContext may be another NamingContext (analogous to subdirectory)
A reference to the top level NamingContext can be obtained with the ORB method:
resolve_initial_references()
Naming Service (NamingContext)
To get a reference to an object stored under NamingContext, use:
resolve(NameComponent namePath)
It throws: NotFound, CannotProceed, InvalidName
This method returns org.omg.CORBA.Object
Therefore, it must be narrowed to a particular interface using a helper’s narrow()
Browsing the Naming Service
The top level only….
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
public class Browser {
   ORB orb = ORB.init (args, null);
   // obtain a reference to the naming service
   org.omg.CORBA.Object nc =
      orb.resolve_initial_references ("NameService");
    NamingContext namingContext =
      NamingContextHelper.narrow (nc);
Browsing the Naming Service….
  BindingListHolder b1 = new BindingListHolder ();
  BindingIteratorHolder b2 = new BindingIteratorHolder ();
  // get initial content-list
  namingContext.list (10, b1, b2);
  // print out bindings
  Binding[] bindings = b1.value;
  if(bindings.length == 0) return;
Browsing the Naming Service….
for (int i = 0; i < bindings.length; i++) {
  Binding binding = bindings[i];
  NameComponent[] name = binding.binding_name;
  BindingType type = binding.binding_type;
  if (type == BindingType.nobject) {
      System.out.println (name[0].id + "-" + name[0].kind);
  } else { // BindingType.ncontext
   System.out.println (name[0].id + "-" + name[0].kind + "/");
  }
 }
CORBA Servers
Implement the IDL interfaces by subclassing the appropriate pregenerated skeleton class
Each class is called a servant
The HelloServer Example (Slide 34)
Initialize the ORB
Create initial objects (servants)
Connect each servant to the ORB
Bind the servants in the naming service
Wait for connections
CORBA Servers (ObjectImpl)
When a servant extends the _interfaceObjectImpl, it is actually extending the orb.omg.CORBA.Portable.ObjectImpl class
This class provides a variety of helper methods (including all methods of CORBA Object)
Naming Service (Server’s View)
Registering/Unregistering services:
bind: register the object under the specified name
rebind:identical to bind(), but an AlreadyBound exception won’t be thrown – existing object replaced
unbind:unregister a CORBA object
Creating new naming contexts:
bind_new_context, new_context, bind_context
Destroying a naming context:
destroy: destroy an empty NamingContext
Registering Services
Example: NameClient.java
This will add names to the namespace:
Plans is an object reference
Personal is a naming context that contains two object references: Calendar and Schedule
Clearing the Naming Service
Steps:
Get a reference to initial naming context
Recursively iterate through the sub naming contexts
Call unbind
Call destroy
Advanced IDL
IDL supports C/C++ style comments:
// This is a comment
/* This is another comment */
Also, it supports:
conditionals (#if)
defines (#define)
includes (#include)
idlj requires access to a C preprocessor (cpp)
Advanced IDL: Arrays
IDL provides multidimensional fixed-size arrays
The array size is fixed at compile time
IDL arrays map directly into Java arrays
Example:
interface Customer {
   attribute string address[4]; // 1-D array
   attribute short table[5][7];   // 2-D array
}
Advanced IDL: Sequences
A sequence is a 1-D array that can be of variable size
Two types:
Bounded sequences
        sequence<long, 15>employee;
Unbounded sequences
     sequence<long> employee
Advanced IDL: Enumerations
The enum data type defines an enumeration
A user-defined data type that can hold one of a fixed set of values
Example:
enum CreditCard { visa, amex, discover };
interface Bank {
     void applyForCreditCard(CreditCard cc);
};
Enumerations (mapping to Java)
An enum is mapped to a Java class with static variables representing the set of values
Example:
public class CreditCard {
    public static vindl CReditCard visa, amex, discover;
    public static final int _visa, _amex, _discover;
    public int value();
}
To compare (using switch): (unknown.value() == _visa)
Advanced IDL: Structures
The IDL type struct defines a structure
Use a struct to group related data together
Example:
struct Name {
    string firstName;
    string lastName;
};
interface Customer { attribute Name name; };
Structures (mapping to Java)
A struct is mapped to a Java class that provides instance variables for the fields, and a constructor for all values, and a null constructor
Example:
public class Name {
    public String firstName;
    public String lastname;
    public Name();
    public Name(String firstName, String lastName);
}
Advanced IDL: typedefs
A typedef is an alias, or another name for an existing data type
Example:
    typedef long age;
     interface Customer {
        age howOld;
     }
Typedefs of simple data types are mapped to the original (I.e. replaced by the more basic type)
Advanced IDL: Constants
1. Within an interface:
interface Foo { const long aLong = -32; };
Mapped to: public interface Foo {
    public static final int aLong = (int) –32L; };
2. Not within an interface:
const string Message=“hello”;
Mapped to: public interface Message {
         public static final String Message=“hello”; };