OSDN Git Service

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