Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory.

Similar presentations


Presentation on theme: "Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory."— Presentation transcript:

1 Copyright (c) Qusay H. Mahmoud 1 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)

2 Copyright (c) Qusay H. Mahmoud 2 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

3 Copyright (c) Qusay H. Mahmoud 3 The Naming Service (interfaces) org.omg.CosNaming: – NamingContext: primary interface to naming service – NameComponent: identify (name/kind) services – BindingIterator: 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

4 Copyright (c) Qusay H. Mahmoud 4 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()

5 Copyright (c) Qusay H. Mahmoud 5 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()

6 Copyright (c) Qusay H. Mahmoud 6 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);

7 Copyright (c) Qusay H. Mahmoud 7 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;

8 Copyright (c) Qusay H. Mahmoud 8 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 + "/"); }

9 Copyright (c) Qusay H. Mahmoud 9 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

10 Copyright (c) Qusay H. Mahmoud 10 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)

11 Copyright (c) Qusay H. Mahmoud 11 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

12 Copyright (c) Qusay H. Mahmoud 12 Clearing the Naming Service Steps: – Get a reference to initial naming context – Recursively iterate through the sub naming contexts – Call unbind – Call destroy

13 Copyright (c) Qusay H. Mahmoud 13 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)

14 Copyright (c) Qusay H. Mahmoud 14 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 }

15 Copyright (c) Qusay H. Mahmoud 15 Advanced IDL: Sequences A sequence is a 1-D array that can be of variable size Two types: – Bounded sequences sequence employee; – Unbounded sequences sequence employee

16 Copyright (c) Qusay H. Mahmoud 16 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); };

17 Copyright (c) Qusay H. Mahmoud 17 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 final CreditCard visa, amex, discover; public static final int _visa, _amex, _discover; public int value(); } To compare (using switch): (unknown.value() == _visa)

18 Copyright (c) Qusay H. Mahmoud 18 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; };

19 Copyright (c) Qusay H. Mahmoud 19 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); }

20 Copyright (c) Qusay H. Mahmoud 20 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)

21 Copyright (c) Qusay H. Mahmoud 21 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”; };


Download ppt "Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory."

Similar presentations


Ads by Google