|
|
|
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) |
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
|
|
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); |
|
|
|
|
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; |
|
|
|
|
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 + "/"); |
|
} |
|
} |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
Steps: |
|
Get a reference to initial naming context |
|
Recursively iterate through the sub naming
contexts |
|
Call unbind |
|
Call destroy |
|
|
|
|
|
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) |
|
|
|
|
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 |
|
} |
|
|
|
|
|
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 |
|
|
|
|
|
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); |
|
}; |
|
|
|
|
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) |
|
|
|
|
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; }; |
|
|
|
|
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); |
|
} |
|
|
|
|
|
|
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) |
|
|
|
|
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”; }; |
|
|
|
|
|
|
|