blob: bdafd440d25c19844d536d113f9a27a2a7152725 [file] [log] [blame]
bpatel87d64cc2010-07-14 15:42:06 -07001." Copyright (c) 1999, 2010, Oracle and/or its affiliates. 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."
bpatel87d64cc2010-07-14 15:42:06 -070022.TH tnameserv 1 "02 Jun 2010"
duke6e45e102007-12-01 00:00:00 +000023
24.LP
tbell16c34dd2009-05-04 18:28:26 -070025.SH "Name"
duke6e45e102007-12-01 00:00:00 +000026Java IDL: Transient Naming Service \- \f2tnameserv\fP
27.LP
duke6e45e102007-12-01 00:00:00 +000028.LP
tbell16c34dd2009-05-04 18:28:26 -070029This 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 +000030.na
31\f2Java IDL Naming Service Included with ORBD\fP @
32.fi
33http://java.sun.com/javase/6/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://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.
124.na
125\f2Java IDL: Running the Hello World Example on TWO Machines\fP @
126.fi
127http://java.sun.com/javase/6/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
174.LP
tbell16c34dd2009-05-04 18:28:26 -0700175.RS 3
duke6e45e102007-12-01 00:00:00 +0000176.TP 3
177\-Joption
tbell16c34dd2009-05-04 18:28:26 -0700178Pass \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.RE
180
duke6e45e102007-12-01 00:00:00 +0000181.LP
182.RE
183.SH "Stopping the Java\ IDL Transient Naming Service"
184.LP
185.LP
186To 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.
187.LP
188.SH "Sample Client: Adding Objects to the Namespace"
189.LP
190.LP
191The 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.LP
193.nf
194\f3
195.fl
196\fP\f3
197.fl
198 \fP\f4Initial\fP\f3
199.fl
200 \fP\f4Naming Context\fP\f3
201.fl
tbell16c34dd2009-05-04 18:28:26 -0700202 / \\
duke6e45e102007-12-01 00:00:00 +0000203.fl
tbell16c34dd2009-05-04 18:28:26 -0700204 / \\
duke6e45e102007-12-01 00:00:00 +0000205.fl
206 plans \fP\f4Personal\fP\f3
207.fl
tbell16c34dd2009-05-04 18:28:26 -0700208 / \\
duke6e45e102007-12-01 00:00:00 +0000209.fl
tbell16c34dd2009-05-04 18:28:26 -0700210 / \\
duke6e45e102007-12-01 00:00:00 +0000211.fl
212 calendar schedule\fP
213.fl
214.fi
215
216.LP
217.LP
218In 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.
219.LP
220.nf
221\f3
222.fl
223import java.util.Properties;
224.fl
225import org.omg.CORBA.*;
226.fl
227import org.omg.CosNaming.*;
228.fl
229
230.fl
231public class NameClient
232.fl
233{
234.fl
235 public static void main(String args[])
236.fl
237 {
238.fl
239 try {
240.fl
241\fP
242.fi
243
244.LP
245In 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.
246.nf
247\f3
248.fl
249 Properties props = new Properties();
250.fl
251 props.put("org.omg.CORBA.ORBInitialPort", "1050");
252.fl
253 ORB orb = ORB.init(args, props);
254.fl
255
256.fl
257\fP
258.fi
259
260.LP
261This 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.nf
263\f3
264.fl
265 NamingContext ctx =
266.fl
267NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
268.fl
269 NamingContext objref = ctx;
270.fl
271
272.fl
273\fP
274.fi
275
276.LP
277This 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.
278.nf
279\f3
280.fl
281 NameComponent nc1 = new NameComponent("plans", "text");
282.fl
283 NameComponent[] name1 = {nc1};
284.fl
285 ctx.rebind(name1, objref);
286.fl
287 System.out.println("plans rebind sucessful!");
288.fl
289
290.fl
291\fP
292.fi
293
294.LP
295This 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.
296.nf
297\f3
298.fl
299 NameComponent nc2 = new NameComponent("Personal", "directory");
300.fl
301 NameComponent[] name2 = {nc2};
302.fl
303 NamingContext ctx2 = ctx.bind_new_context(name2);
304.fl
305 System.out.println("new naming context added..");
306.fl
307
308.fl
309\fP
310.fi
311
312.LP
313The remainder of the code binds the dummy object reference using the names "schedule" and "calendar" under the "Personal" naming context (\f3ctx2\fP).
314.nf
315\f3
316.fl
317 NameComponent nc3 = new NameComponent("schedule", "text");
318.fl
319 NameComponent[] name3 = {nc3};
320.fl
321 ctx2.rebind(name3, objref);
322.fl
323 System.out.println("schedule rebind sucessful!");
324.fl
325
326.fl
327 NameComponent nc4 = new NameComponent("calender", "text");
328.fl
329 NameComponent[] name4 = {nc4};
330.fl
331 ctx2.rebind(name4, objref);
332.fl
333 System.out.println("calender rebind sucessful!");
334.fl
335
336.fl
337
338.fl
339 } catch (Exception e) {
340.fl
341 e.printStackTrace(System.err);
342.fl
343 }
344.fl
345 }
346.fl
347}
348.fl
349\fP
350.fi
351
352.LP
353.SH "Sample Client: Browsing the Namespace"
354.LP
355.LP
356The following sample program illustrates how to browse the namespace.
357.LP
358.nf
359\f3
360.fl
361import java.util.Properties;
362.fl
363import org.omg.CORBA.*;
364.fl
365import org.omg.CosNaming.*;
366.fl
367
368.fl
369public class NameClientList
370.fl
371{
372.fl
373 public static void main(String args[])
374.fl
375 {
376.fl
377 try {
378.fl
379\fP
380.fi
381
382.LP
383In 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.nf
385\f3
386.fl
387
388.fl
389 Properties props = new Properties();
390.fl
391 props.put("org.omg.CORBA.ORBInitialPort", "1050");
392.fl
393 ORB orb = ORB.init(args, props);
394.fl
395
396.fl
397
398.fl
399\fP
400.fi
401
402.LP
403The following code obtains the intial naming context.
404.nf
405\f3
406.fl
407 NamingContext nc =
408.fl
409NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
410.fl
411
412.fl
413\fP
414.fi
415
416.LP
417The \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.
418.nf
419\f3
420.fl
421 BindingListHolder bl = new BindingListHolder();
422.fl
423 BindingIteratorHolder blIt= new BindingIteratorHolder();
424.fl
425 nc.list(1000, bl, blIt);
426.fl
427
428.fl
429\fP
430.fi
431
432.LP
433This code gets the array of bindings out of the returned BindingListHolder. If there are no bindings, the program ends.
434.nf
435\f3
436.fl
437 Binding bindings[] = bl.value;
438.fl
439 if (bindings.length == 0) return;
440.fl
441
442.fl
443\fP
444.fi
445
446.LP
447The remainder of the code loops through the bindings and prints the names out.
448.nf
449\f3
450.fl
451 for (int i=0; i < bindings.length; i++) {
452.fl
453
454.fl
455 // get the object reference for each binding
456.fl
457 org.omg.CORBA.Object obj = nc.resolve(bindings[i].binding_name);
458.fl
459 String objStr = orb.object_to_string(obj);
460.fl
461 int lastIx = bindings[i].binding_name.length\-1;
462.fl
463
464.fl
465 // check to see if this is a naming context
466.fl
467 if (bindings[i].binding_type == BindingType.ncontext) {
468.fl
469 System.out.println( "Context: " +
470.fl
471bindings[i].binding_name[lastIx].id);
472.fl
473 } else {
474.fl
475 System.out.println("Object: " +
476.fl
477bindings[i].binding_name[lastIx].id);
478.fl
479 }
480.fl
481 }
482.fl
483
484.fl
485 } catch (Exception e) {
486.fl
487 e.printStackTrace(System.err);
488.fl
489 }
490.fl
491 }
492.fl
493}
494.fl
495\fP
496.fi
497
498.LP
duke6e45e102007-12-01 00:00:00 +0000499