1 ." Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2 ." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 ." This code is free software; you can redistribute it and/or modify it
5 ." under the terms of the GNU General Public License version 2 only, as
6 ." published by the Free Software Foundation.
8 ." This code is distributed in the hope that it will be useful, but WITHOUT
9 ." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ." FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 ." version 2 for more details (a copy is included in the LICENSE file that
12 ." accompanied this code).
14 ." You should have received a copy of the GNU General Public License version
15 ." 2 along with this work; if not, write to the Free Software Foundation,
16 ." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 ." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 ." or visit www.oracle.com if you need additional information or have any
22 .TH tnameserv 1 "10 May 2011"
26 Java IDL: Transient Naming Service \- \f2tnameserv\fP
29 This document discusses using the Java IDL Transient Naming Service, \f2tnameserv\fP. Java IDL also includes the Object Request Broker Daemon (ORBD). ORBD is a daemon process containing a Bootstrap Service, a Transient Naming Service, a \f3Persistent\fP Naming Service, and a Server Manager. The Java IDL tutorials all use ORBD, however, you can substitute \f2tnameserv\fP for \f2orbd\fP in any of the examples that use a Transient Naming Service. For documentation on the \f2orbd\fP tool, link to its orbd(1) or the
31 \f2Java IDL Naming Service Included with ORBD\fP @
33 http://download.oracle.com/javase/7/docs/technotes/guides/idl/jidlNaming.html topic.
36 Topics in this section include:
41 Java\ IDL Transient Naming Service
44 Starting the Java\ IDL Transient Naming Service
47 Stopping the Java\ IDL Transient Naming Service
50 Sample Client: Adding Objects to the Namespace
53 Sample Client: Browsing the Namespace
57 .SH "Java\ IDL Transient Naming Service"
60 The CORBA COS (Common Object Services) Naming Service provides a tree\-like directory for object references much like a filesystem provides a directory structure for files. The Transient Naming Service provided with Java IDL, \f2tnameserv\fP, is a simple implementation of the COS Naming Service specification.
63 Object references are stored in the namespace by name and each object reference\-name pair is called a name \f2binding\fP. Name bindings may be organized under \f2naming contexts\fP. Naming contexts are themselves name bindings and serve the same organizational function as a file system subdirectory. All bindings are stored under the \f2initial naming context\fP. The initial naming context is the only persistent binding in the namespace; the rest of the namespace is lost if the Java IDL naming service process halts and restarts.
66 For an applet or application to use COS naming, 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.
68 .SH "Starting the Java\ IDL Transient Naming Service"
71 You must start the Java\ IDL naming service before an application or applet that uses its naming service. Installation of the Java\ IDL product creates a script (Solaris: \f2tnameserv\fP) or executable file (Windows NT: \f2tnameserv.exe\fP) that starts the Java\ IDL naming service. Start the naming service so it runs in the background.
74 If you do not specify otherwise, the Java\ IDL naming service listens on port 900 for the bootstrap protocol used to implement the ORB \f2resolve_initial_references()\fP and \f2list_initial_references()\fP methods, as follows:
79 tnameserv \-ORBInitialPort \fP\f4nameserverport\fP\f3&
86 If you do not specify the name server port, port 900 is used by default. When running Solaris software, you must become root to start a process on a port under 1024. For this reason, we recommend that you use a port number greater than or equal to 1024. To specify a different port, for example, 1050, and to run the naming service in the background, from a UNIX command shell, enter:
91 tnameserv \-ORBInitialPort 1050&
98 From an MS\-DOS system prompt (Windows), enter:
103 start tnameserv \-ORBInitialPort 1050
110 Clients of the name server must be made aware of the new port number. Do this by setting the \f2org.omg.CORBA.ORBInitialPort\fP property to the new port number when creating the ORB object.
113 Running the server and client on different hosts
116 In most of the Java IDL and RMI\-IIOP tutorials, the Naming Service, Server, and Client are all running on the development machine. In real world deployment, it is likely that the client and server will run on different host machines than the Naming Service.
119 For the client and server to find the Naming Service, they must be made aware of the port number and host on which the naming service is running. Do this by setting the \f2org.omg.CORBA.ORBInitialPort\fP and \f2org.omg.CORBA.ORBInitialHost\fP properties in the client and server files to the machine name and port number on which the Naming Service is running. An example of this is shown in
121 \f2The Hello World Example Using RMI\-IIOP\fP @
123 http://download.oracle.com/javase/7/docs/technotes/guides/rmi\-iiop/rmiiiopexample.html. You could also use the command line options \f2\-ORBInitialPort\fP \f2nameserverport#\fP and \f2\-ORBInitialHost\fP \f2nameserverhostname\fP to tell the client and server where to find the Naming Service.
125 \f2Java IDL: Running the Hello World Example on TWO Machines\fP @
127 http://download.oracle.com/javase/7/docs/technotes/guides/idl/tutorial/jidl2machines.html shows one way of doing this using the command line option.
130 For example, suppose the Transient Naming Service, \f2tnameserv\fP is running on port 1050 on host \f2nameserverhost\fP. The client is running on host \f2clienthost\fP and the server is running on host \f2serverhost\fP.
135 Start \f2tnameserv\fP on the host \f2nameserverhost\fP, as follows:
139 tnameserv \-ORBInitialPort 1050
147 Start the server on the \f2serverhost\fP, as follows:
151 java Server \-ORBInitialPort 1050 \-ORBInitialHost nameserverhost
157 Start the client on the \f2clienthost\fP, as follows:
161 java Client \-ORBInitialPort 1050 \-ORBInitialHost nameserverhost
171 This command\-line option is available for use with \f2tnameserve\fP:
175 Pass \f2option\fP to the Java virtual machine, where \f2option\fP is one of the options described on the reference page for java(1). For example, \f3\-J\-Xms48m\fP sets the startup memory to 48 megabytes. It is a common convention for \f3\-J\fP to pass options to the underlying virtual machine.
179 .SH "Stopping the Java\ IDL Transient Naming Service"
182 To stop the Java\ IDL naming service, use the relevant operating system command, such as \f2kill\fP for a Unix process, or \f2Ctrl\-C\fP for a Windows process. The naming service will continue to wait for invocations until it is explicitly shutdown. Note that names registered with the Java\ IDL naming service disappear when the service is terminated.
184 .SH "Sample Client: Adding Objects to the Namespace"
187 The following sample program illustrates how to add names to the namespace. It is a self\-contained Transient Naming Service client that creates the following simple tree.
192 \f4Initial Naming Context\fP
213 In this example, \f3plans\fP is an object reference and \f3Personal\fP is a naming context that contains two object references: \f3calendar\fP and \f3schedule\fP.
218 import java.util.Properties;
220 import org.omg.CORBA.*;
222 import org.omg.CosNaming.*;
226 public class NameClient
230 public static void main(String args[])
240 In the above section, Starting the Java IDL Transient Naming Service, the nameserver was started on port 1050. The following code ensures that the client program is aware of this port number.
244 Properties props = new Properties();
246 props.put("org.omg.CORBA.ORBInitialPort", "1050");
248 ORB orb = ORB.init(args, props);
256 This code obtains the initial naming context and assigns it to \f3ctx\fP. The second line copies \f3ctx\fP into a dummy object reference \f3objref\fP that we'll attach to various names and add into the namespace.
262 NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
264 NamingContext objref = ctx;
272 This code creates a name "plans" of type "text" and binds it to our dummy object reference. "plans" is then added under the initial naming context using \f2rebind\fP. The \f2rebind\fP method allows us to run this program over and over again without getting the exceptions we'd get from using \f2bind\fP.
276 NameComponent nc1 = new NameComponent("plans", "text");
278 NameComponent[] name1 = {nc1};
280 ctx.rebind(name1, objref);
282 System.out.println("plans rebind sucessful!");
290 This code creates a naming context called "Personal" of type "directory". The resulting object reference, \f3ctx2\fP, is bound to the name and added under the initial naming context.
294 NameComponent nc2 = new NameComponent("Personal", "directory");
296 NameComponent[] name2 = {nc2};
298 NamingContext ctx2 = ctx.bind_new_context(name2);
300 System.out.println("new naming context added..");
308 The remainder of the code binds the dummy object reference using the names "schedule" and "calendar" under the "Personal" naming context (\f3ctx2\fP).
312 NameComponent nc3 = new NameComponent("schedule", "text");
314 NameComponent[] name3 = {nc3};
316 ctx2.rebind(name3, objref);
318 System.out.println("schedule rebind sucessful!");
322 NameComponent nc4 = new NameComponent("calender", "text");
324 NameComponent[] name4 = {nc4};
326 ctx2.rebind(name4, objref);
328 System.out.println("calender rebind sucessful!");
334 } catch (Exception e) {
336 e.printStackTrace(System.err);
348 .SH "Sample Client: Browsing the Namespace"
351 The following sample program illustrates how to browse the namespace.
356 import java.util.Properties;
358 import org.omg.CORBA.*;
360 import org.omg.CosNaming.*;
364 public class NameClientList
368 public static void main(String args[])
378 In the above section, Starting the Java IDL Transient Naming Service, the nameserver was started on port 1050. The following code ensures that the client program is aware of this port number.
384 Properties props = new Properties();
386 props.put("org.omg.CORBA.ORBInitialPort", "1050");
388 ORB orb = ORB.init(args, props);
398 The following code obtains the intial naming context.
404 NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
412 The \f2list\fP method lists the bindings in the naming context. In this case, up to 1000 bindings from the initial naming context will be returned in the BindingListHolder; any remaining bindings are returned in the BindingIteratorHolder.
416 BindingListHolder bl = new BindingListHolder();
418 BindingIteratorHolder blIt= new BindingIteratorHolder();
420 nc.list(1000, bl, blIt);
428 This code gets the array of bindings out of the returned BindingListHolder. If there are no bindings, the program ends.
432 Binding bindings[] = bl.value;
434 if (bindings.length == 0) return;
442 The remainder of the code loops through the bindings and prints the names out.
446 for (int i=0; i < bindings.length; i++) {
450 // get the object reference for each binding
452 org.omg.CORBA.Object obj = nc.resolve(bindings[i].binding_name);
454 String objStr = orb.object_to_string(obj);
456 int lastIx = bindings[i].binding_name.length\-1;
460 // check to see if this is a naming context
462 if (bindings[i].binding_type == BindingType.ncontext) {
464 System.out.println( "Context: " +
466 bindings[i].binding_name[lastIx].id);
470 System.out.println("Object: " +
472 bindings[i].binding_name[lastIx].id);
480 } catch (Exception e) {
482 e.printStackTrace(System.err);