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