330 likes | 445 Views
Naming Service. Naming service. The CORBA COS (Common Object Services) Naming Service provides a tree-like directory for object references It is like a filesystem provides a directory structure for files.
E N D
Naming service • The CORBA COS (Common Object Services) Naming Service provides a tree-like directory for object references • It is like a filesystem provides a directory structure for files. • The Naming Service provided with Java IDL is an implementationof the COS Naming Service specification.
Naming service (cont.) • 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 set of name bindings in which each name is unique. • Different names can be bound to an object in the same or different contexts at the same time.
Naming service (cont.) • To resolve a name is to determine the object associated with the name in a given context. • To bind a name is to create a name binding in a given context. • A name is always resolved relative to a context - there are no absolute names.
Naming service (cont.) • Because a context is like any other object, it can also be bound to a name in a naming context. • Binding contexts in other contexts creates a naming graph – • a directed graph with nodes and labeled edges where the nodes are contexts.
Naming service (cont.) • A naming graph allows more complex names to reference an object. • Given a context in a naming graph, a sequence of names can reference an object. • This sequence of names (called a compound name) • defines a path in the naming graph to navigate the resolution process.
Naming service (cont.) • For an application to use the COS Naming Service, its ORB must know • the port of a host running a naming service or • have access to a stringified initial naming context for that naming service. • The naming service can either be the Java IDL naming service or another COS-compliant naming service.
Naming service (cont.) • Prior to running a client or a server, you will start ORBD. • ORBD includes • a persistent Naming Service and • a transient Naming Service, • both of which are an implementation of the COS Naming Service.
Persistent Naming Service • The Persistent Naming Service provides persistence for naming contexts. • information is persistent across service shutdowns and startups, and • is recoverable in the event of a service failure. • If ORBD is restarted, the Persistent Naming Service will restore the naming context graph, so that the binding of all clients' and servers' names remains intact (persistent).
Transient Naming Service • For backward compatibility, tnameserv, a Transient Naming Service shipped with older versions of the JDK, is also included in J2SE v.1.4. • A transient naming service retains naming contexts as long as it is running. • If there is a service interruption, the naming context graph is lost.
How to get the naming service? • Both client and server should agree on which root naming context to use. • The orb.resolve_initial_references(String name_of_service) method is used to obtain the root naming context. • If you get a handle on a Naming Service by providing "NameService" as the name_of_service, you will get a persistent naming service, meaning that the naming context graph will be restored after a service failure. • If you get the handle using "TNameService", you will get a transient naming service, meaning that you will need to re-obtain the root naming context using orb.resolve_initial_references(String name_of_service) if there is a service interruption.
Code to get the naming service? For example, // get the root naming context org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
Getting naming service • The string "NameService" is defined for all CORBA ORBs. • When you pass in this string, the ORB returns a naming context object that is an object reference for: • The persistent name service if you are using the Naming Service that is part of ORBD. • The transient name service if you are using tnameserv.
Getting TNameService naming service in ORBD (cont.) • To specify that you want to use the transient naming service with ORBD, pass in the string "TNameService". • The string "TNameService" is a proprietary name. • When you pass in this string, the ORB returns a naming context object that is an object reference for ORBD's transient name service.
NamingContextExt • As with all CORBA object references, objRef is a generic CORBA object. • To use it as a NamingContextExt object, you must narrow it to its proper type. • NamingContextExtHelper is an idlj-generated helper class, similar in function to HelloHelper. • The ncRef object is now an org.omg.CosNaming.NamingContextExt and you can use it to access the naming service and register the server. • NamingContextExt and NamingContextExtHelper are new to this release of J2SE.
NamingContextExt (cont) • NamingContextExt is the extension of NamingContext. • It contains a set of name bindings in which each name is unique and • It is part of the Interoperable Naming Service. • Different names can be bound to an object in the same or different contexts at the same time. • Using NamingContextExt, you can use URL-based names to bind and resolve. • NamingContextExtHelper provides additional helper methods like narrow() that are type-specific but don't deal with business logic.
Interoperable Naming Service (INS) • INS is a URL-based naming system on top of the CORBA Naming Service, as well as • a common bootstrap mechanism that lets applications share a common initial naming context. • The INS provides the following features: • Capability to resolve using stringified names (e.g., a/b.c/d) • URLs for CORBA object references (corbaloc: and corbaname: formats) • Standard APIs in NamingContextExt for converting between CosNames, URLs, and Strings • ORB arguments for bootstrapping (ORBInitRef and ORBDefaultInitRef)
Interoperable Naming Service (INS) • An object reference contains at least three pieces of information: • an address, • the name of the POA that created an object reference, and • an Object ID. • Using INS, you can provide a URL to access the CORBA object, • which is more readable than a stringified IOR.
stringified object reference • The following stringified object reference formats are allowed: • Interoperable Object References (IOR) • An IOR is an object reference that is understood by ORBs that can interoperate using the OMG-defined protocols GIOP and IIOP. • A client can obtain an object reference using orb.object_to_string(objRef), as shown in the Browsing the Namespace example, or as a result of an invocation on another object reference. • Note: If an IOR contains multiple profiles, the J2SE v.1.4 ORB always uses the first one.
stringified object reference (cont) • Human-Readable URL Formats for CORBA Object References • corbaloc: • The corbaloc: format is useful for CORBA client programs, and • is typically used to resolve the reference using the GIOP LocateRequest or Request message.
stringified object reference (cont) corbaloc:(cont.) • For example, a corbaloc: object reference might look like this: • corbaloc:iiop:1.2@MyBank.com:2050/TraderService • This example show how to get an object reference for TraderService from host myBank.com on port 2050.
stringified object reference (cont) • corbaname: • The corbaname: format provides a mechanism for a client to bootstrap directly, and • is typically used to resolve the stringified name from the root naming context. • For example, a corbaname: object reference might look like this: • corbaname::myBank.com:2050#Personal/schedule • where myBank.com is the host, 2050 is the port.
stringified object reference (cont) • corbaname: (cont.) • The portion of the reference up to the hash mark (corbaname::myBank.com:2050 ) is the URL that returns the root naming context. • This example provides the URL to use to: a) locate the Naming Service, and, b) resolve the name Personal/schedule from the Naming Service.
Bootstrap Options for the ORB • INS provides ORB options for bootstrapping. • To bootstrap a CORBA system, you must give it an object reference. • The ORB can be configured to return the handle of a customized CORBA service from resolve_initial_references() using either ORBInitRef and/or ORBDefaultInitRef. • For example, • -ORBInitRef TraderService = corbaloc::myBank.com:2050/TraderService • -ORBDefaultInitRef corbaloc:iiop:1.2:myBank.com:2050
Bootstrap Options for the ORB • The order of resolution when these options are used is as follows: • Objects registered with register_initial_references • -ORBInitRef • -ORBDefaultInitRef • Proprietary Bootstrap (Sun ORBs only)
Using the Naming Service • To use the Naming Service, you must first write the server and client code that finds and/or creates the namespace and/or the objects in the namespace. • Before running the client and server, you must start the Naming Service and tell the client and server where to find it.
Using the Naming Service • The following steps loosely suggest what happens when the client and server attempt to access the Naming Service: • The server invokes the bind or rebind method to associate a logical name with an object reference. • The Naming Service adds this object reference/name binding to its namespace database. • A client application invokes the resolve method to obtain an object reference with this name. • The client uses an object reference to invoke methods on the target object.
Starting the Naming Service • we use the Object Request Broker Daemon, orbd, which includes both a Persistent and a Transient Naming Service, and is available with every download of J2SE 1.4 and higher. • For a caller (client, peer, or client application) to be able to invoke a method on a remote object, that caller must first obtain a reference to the remote object. • Once a remote object is registered on the server, callers can look up the object by name, obtain a remote object reference, and then remotely invoke methods on the object.
Stopping the Naming Service • To stop the naming service, use the relevant operating system command, such as kill on Solaris, or Ctrl+C in the DOS window in which orbd is running. • Note that names registered with the naming service may disappear when the service is terminated if the naming service is transient. • The Java IDL naming service will run until it is explicitly stopped.
How do I connect to a 3rd-party Naming Service from Sun's ORB? • The recommended way is to use the Inter-Operable Naming Service (INS), if this option is supported by the 3rd-party Naming Service. • To use the Sun ORB with another vendor's Naming Service, • Start the 3rd-party name server on Host and Port. • Pass the following argument to ORB.init(): -ORBInitRef NameService=corbaloc:iiop:1.2@:/NameService
How do I connect to a 3rd-party Naming Service from Sun's ORB? • When you do orb.resolve_initial_references( "NameService" ), you should be able to connect to 3rd-party Name Service. • If you are still not able to connect, try these troubleshooting hints: • Verify that the 3rd-party Name Service supports INS. • Verify that the host and port information is accurate. • Verify that the 3rd-party Name Service has been started successfully. • Verify that the 3rd-party Name Service supports GIOP 1.2. If not, refer to the Name Server's documentation for the correct the GIOP version, and modify the corbaloc: URL accordingly. • Determine if the 3rd-party Name Service has a different object key it uses to contact NameService. If so, refer to the Name Server's documentation.
References • Naming service: URL:http://java.sun.com/j2se/1.4.2/docs/guide/idl/jidlNaming.html • Java IDL: Interoperable Naming Service (INS): • URL:http://java.sun.com/j2se/1.4.2/docs/guide/idl/INStutorial.html