tnameserv.1 revision 5116:d45bc4307996
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.
3."
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.
7."
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).
13."
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.
17."
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
20." questions.
21."
22.TH tnameserv 1 "10 May 2011"
23
24.LP
25.SH "Name"
26Java IDL: Transient Naming Service \- \f2tnameserv\fP
27.LP
28.LP
29This 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
30.na
31\f2Java IDL Naming Service Included with ORBD\fP @
32.fi
33http://download.oracle.com/javase/7/docs/technotes/guides/idl/jidlNaming.html topic.
34.LP
35.LP
36Topics in this section include:
37.LP
38.RS 3
39.TP 2
40o
41Java\ IDL Transient Naming Service
42.TP 2
43o
44Starting the Java\ IDL Transient Naming Service
45.TP 2
46o
47Stopping the Java\ IDL Transient Naming Service
48.TP 2
49o
50Sample Client: Adding Objects to the Namespace
51.TP 2
52o
53Sample Client: Browsing the Namespace
54.RE
55
56.LP
57.SH "Java\ IDL Transient Naming Service"
58.LP
59.LP
60The 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.
61.LP
62.LP
63Object 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.
64.LP
65.LP
66For 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.
67.LP
68.SH "Starting the Java\ IDL Transient Naming Service"
69.LP
70.LP
71You 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.
72.LP
73.LP
74If 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:
75.LP
76.nf
77\f3
78.fl
79        tnameserv \-ORBInitialPort \fP\f4nameserverport\fP\f3&
80.fl
81\fP
82.fi
83
84.LP
85.LP
86If 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:
87.LP
88.nf
89\f3
90.fl
91        tnameserv \-ORBInitialPort 1050&
92.fl
93\fP
94.fi
95
96.LP
97.LP
98From an MS\-DOS system prompt (Windows), enter:
99.LP
100.nf
101\f3
102.fl
103        start tnameserv \-ORBInitialPort 1050
104.fl
105\fP
106.fi
107
108.LP
109.LP
110Clients 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.
111.LP
112.SS
113Running the server and client on different hosts
114.LP
115.LP
116In 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.
117.LP
118.LP
119For 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
120.na
121\f2The Hello World Example Using RMI\-IIOP\fP @
122.fi
123http://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.
124.na
125\f2Java IDL: Running the Hello World Example on TWO Machines\fP @
126.fi
127http://download.oracle.com/javase/7/docs/technotes/guides/idl/tutorial/jidl2machines.html shows one way of doing this using the command line option.
128.LP
129.LP
130For 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.
131.LP
132.RS 3
133.TP 2
134o
135Start \f2tnameserv\fP on the host \f2nameserverhost\fP, as follows:
136.nf
137\f3
138.fl
139     tnameserv \-ORBInitialPort 1050
140.fl
141
142.fl
143\fP
144.fi
145.TP 2
146o
147Start the server on the \f2serverhost\fP, as follows:
148.nf
149\f3
150.fl
151     java Server \-ORBInitialPort 1050 \-ORBInitialHost nameserverhost
152.fl
153\fP
154.fi
155.TP 2
156o
157Start the client on the \f2clienthost\fP, as follows:
158.nf
159\f3
160.fl
161     java Client \-ORBInitialPort 1050 \-ORBInitialHost nameserverhost
162.fl
163\fP
164.fi
165.RE
166
167.LP
168.SS
169The \-J option
170.LP
171This command\-line option is available for use with \f2tnameserve\fP:
172.RS 3
173.TP 3
174\-Joption
175Pass \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.
176.RE
177
178.LP
179.SH "Stopping the Java\ IDL Transient Naming Service"
180.LP
181.LP
182To 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.
183.LP
184.SH "Sample Client: Adding Objects to the Namespace"
185.LP
186.LP
187The 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.
188.LP
189.RS 3
190.TP 2
191o
192\f4Initial Naming Context\fP
193.RS 3
194.TP 2
195*
196\f3plans\fP
197.TP 2
198*
199\f4Personal\fP
200.RS 3
201.TP 2
202-
203\f3calendar\fP
204.TP 2
205-
206\f3schedule\fP
207.RE
208.RE
209.RE
210
211.LP
212.LP
213In 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.
214.LP
215.nf
216\f3
217.fl
218import java.util.Properties;
219.fl
220import org.omg.CORBA.*;
221.fl
222import org.omg.CosNaming.*;
223.fl
224
225.fl
226public class NameClient
227.fl
228{
229.fl
230   public static void main(String args[])
231.fl
232   {
233.fl
234      try {
235.fl
236\fP
237.fi
238
239.LP
240In 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.
241.nf
242\f3
243.fl
244        Properties props = new Properties();
245.fl
246        props.put("org.omg.CORBA.ORBInitialPort", "1050");
247.fl
248        ORB orb = ORB.init(args, props);
249.fl
250
251.fl
252\fP
253.fi
254
255.LP
256This 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.
257.nf
258\f3
259.fl
260        NamingContext ctx =
261.fl
262NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
263.fl
264        NamingContext objref = ctx;
265.fl
266
267.fl
268\fP
269.fi
270
271.LP
272This 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.
273.nf
274\f3
275.fl
276        NameComponent nc1 = new NameComponent("plans", "text");
277.fl
278        NameComponent[] name1 = {nc1};
279.fl
280        ctx.rebind(name1, objref);
281.fl
282        System.out.println("plans rebind sucessful!");
283.fl
284
285.fl
286\fP
287.fi
288
289.LP
290This 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.
291.nf
292\f3
293.fl
294        NameComponent nc2 = new NameComponent("Personal", "directory");
295.fl
296        NameComponent[] name2 = {nc2};
297.fl
298        NamingContext ctx2 = ctx.bind_new_context(name2);
299.fl
300        System.out.println("new naming context added..");
301.fl
302
303.fl
304\fP
305.fi
306
307.LP
308The remainder of the code binds the dummy object reference using the names "schedule" and "calendar" under the "Personal" naming context (\f3ctx2\fP).
309.nf
310\f3
311.fl
312        NameComponent nc3 = new NameComponent("schedule", "text");
313.fl
314        NameComponent[] name3 = {nc3};
315.fl
316        ctx2.rebind(name3, objref);
317.fl
318        System.out.println("schedule rebind sucessful!");
319.fl
320
321.fl
322        NameComponent nc4 = new NameComponent("calender", "text");
323.fl
324        NameComponent[] name4 = {nc4};
325.fl
326        ctx2.rebind(name4, objref);
327.fl
328        System.out.println("calender rebind sucessful!");
329.fl
330
331.fl
332
333.fl
334    } catch (Exception e) {
335.fl
336        e.printStackTrace(System.err);
337.fl
338    }
339.fl
340  }
341.fl
342}
343.fl
344\fP
345.fi
346
347.LP
348.SH "Sample Client: Browsing the Namespace"
349.LP
350.LP
351The following sample program illustrates how to browse the namespace.
352.LP
353.nf
354\f3
355.fl
356import java.util.Properties;
357.fl
358import org.omg.CORBA.*;
359.fl
360import org.omg.CosNaming.*;
361.fl
362
363.fl
364public class NameClientList
365.fl
366{
367.fl
368   public static void main(String args[])
369.fl
370   {
371.fl
372      try {
373.fl
374\fP
375.fi
376
377.LP
378In 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.
379.nf
380\f3
381.fl
382
383.fl
384        Properties props = new Properties();
385.fl
386        props.put("org.omg.CORBA.ORBInitialPort", "1050");
387.fl
388        ORB orb = ORB.init(args, props);
389.fl
390
391.fl
392
393.fl
394\fP
395.fi
396
397.LP
398The following code obtains the intial naming context.
399.nf
400\f3
401.fl
402        NamingContext nc =
403.fl
404NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
405.fl
406
407.fl
408\fP
409.fi
410
411.LP
412The \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.
413.nf
414\f3
415.fl
416        BindingListHolder bl = new BindingListHolder();
417.fl
418        BindingIteratorHolder blIt= new BindingIteratorHolder();
419.fl
420        nc.list(1000, bl, blIt);
421.fl
422
423.fl
424\fP
425.fi
426
427.LP
428This code gets the array of bindings out of the returned BindingListHolder. If there are no bindings, the program ends.
429.nf
430\f3
431.fl
432        Binding bindings[] = bl.value;
433.fl
434        if (bindings.length == 0) return;
435.fl
436
437.fl
438\fP
439.fi
440
441.LP
442The remainder of the code loops through the bindings and prints the names out.
443.nf
444\f3
445.fl
446        for (int i=0; i < bindings.length; i++) {
447.fl
448
449.fl
450            // get the object reference for each binding
451.fl
452            org.omg.CORBA.Object obj = nc.resolve(bindings[i].binding_name);
453.fl
454            String objStr = orb.object_to_string(obj);
455.fl
456            int lastIx = bindings[i].binding_name.length\-1;
457.fl
458
459.fl
460            // check to see if this is a naming context
461.fl
462            if (bindings[i].binding_type == BindingType.ncontext) {
463.fl
464              System.out.println( "Context: " +
465.fl
466bindings[i].binding_name[lastIx].id);
467.fl
468            } else {
469.fl
470                System.out.println("Object: " +
471.fl
472bindings[i].binding_name[lastIx].id);
473.fl
474            }
475.fl
476        }
477.fl
478
479.fl
480       } catch (Exception e) {
481.fl
482        e.printStackTrace(System.err);
483.fl
484       }
485.fl
486   }
487.fl
488}
489.fl
490\fP
491.fi
492
493.LP
494
495