1tnameserv(1)                General Commands Manual               tnameserv(1)
2
3
4

Name

6       Java IDL: Transient Naming Service - tnameserv
7
8       This  document  discusses  using the Java IDL Transient Naming Service,
9       tnameserv. Java IDL also includes  the  Object  Request  Broker  Daemon
10       (ORBD).  ORBD  is  a  daemon  process containing a Bootstrap Service, a
11       Transient Naming Service, a Persistent Naming  Service,  and  a  Server
12       Manager.  The Java IDL tutorials all use ORBD, however, you can substi‐
13       tute tnameserv for orbd in any of the examples  that  use  a  Transient
14       Naming Service. For documentation on the orbd tool, link to its orbd(1)
15       or the Java IDL Naming Service Included with ORBD @
16       http://docs.oracle.com/javase/7/docs/technotes/guides/idl/jidlNam
17       ing.html topic.
18
19       Topics in this section include:
20
21          o Java IDL Transient Naming Service
22
23          o Starting the Java IDL Transient Naming Service
24
25          o Stopping the Java IDL Transient Naming Service
26
27          o Sample Client: Adding Objects to the Namespace
28
29          o Sample Client: Browsing the Namespace
30
31

Java IDL Transient Naming Service

33       The CORBA COS (Common Object Services) Naming Service provides a
34       tree-like directory for object references much like a filesystem pro‐
35       vides a directory structure for files. The Transient Naming Service
36       provided with Java IDL, tnameserv, is a simple implementation of the
37       COS Naming Service specification.
38
39       Object references are stored in the namespace by name and each object
40       reference-name pair is called a name binding. Name bindings may be
41       organized under naming contexts. Naming contexts are themselves name
42       bindings and serve the same organizational function as a file system
43       subdirectory. All bindings are stored under the initial naming context.
44       The initial naming context is the only persistent binding in the names‐
45       pace; the rest of the namespace is lost if the Java IDL naming service
46       process halts and restarts.
47
48       For an applet or application to use COS naming, its ORB must know the
49       port of a host running a naming service or have access to a stringified
50       initial naming context for that naming service. The naming service can
51       either be the Java IDL naming service or another COS-compliant naming
52       service.
53

Starting the Java IDL Transient Naming Service

55       You must start the Java IDL naming service before an application or
56       applet that uses its naming service. Installation of the Java IDL prod‐
57       uct creates a script (Solaris: tnameserv) or executable file (Windows
58       NT: tnameserv.exe) that starts the Java IDL naming service. Start the
59       naming service so it runs in the background.
60
61       If you do not specify otherwise, the Java IDL naming service listens on
62       port 900 for the bootstrap protocol used to implement the ORB
63       resolve_initial_references() and list_initial_references() methods, as
64       follows:
65
66               tnameserv -ORBInitialPort nameserverport&
67
68
69       If you do not specify the name server port, port 900 is used by
70       default. When running Solaris software, you must become root to start a
71       process on a port under 1024. For this reason, we recommend that you
72       use a port number greater than or equal to 1024. To specify a different
73       port, for example, 1050, and to run the naming service in the back‐
74       ground, from a UNIX command shell, enter:
75
76               tnameserv -ORBInitialPort 1050&
77
78
79       From an MS-DOS system prompt (Windows), enter:
80
81               start tnameserv -ORBInitialPort 1050
82
83
84       Clients of the name server must be made aware of the new port number.
85       Do this by setting the org.omg.CORBA.ORBInitialPort property to the new
86       port number when creating the ORB object.
87
88   Running the server and client on different hosts
89       In most of the Java IDL and RMI-IIOP tutorials, the Naming Service,
90       Server, and Client are all running on the development machine. In real
91       world deployment, it is likely that the client and server will run on
92       different host machines than the Naming Service.
93
94       For the client and server to find the Naming Service, they must be made
95       aware of the port number and host on which the naming service is run‐
96       ning. Do this by setting the org.omg.CORBA.ORBInitialPort and
97       org.omg.CORBA.ORBInitialHost properties in the client and server files
98       to the machine name and port number on which the Naming Service is run‐
99       ning. An example of this is shown in The Hello World Example Using
100       RMI-IIOP @
101       http://docs.oracle.com/javase/7/docs/technotes/guides/rmi-iiop/rmii
102       iopexample.html. You could also use the command line options -ORBIni‐
103       tialPort nameserverport# and -ORBInitialHost nameserverhostname to tell
104       the client and server where to find the Naming Service.  Java IDL: Run‐
105       ning the Hello World Example on TWO Machines @
106       http://docs.oracle.com/javase/7/docs/technotes/guides/idl/tuto
107       rial/jidl2machines.html shows one way of doing this using the command
108       line option.
109
110       For example, suppose the Transient Naming Service, tnameserv is running
111       on port 1050 on host nameserverhost. The client is running on host
112       clienthost and the server is running on host serverhost.
113
114          o Start tnameserv on the host nameserverhost, as follows:
115                 tnameserv -ORBInitialPort 1050
116
117
118          o Start the server on the serverhost, as follows:
119                 java Server -ORBInitialPort 1050 -ORBInitialHost nameserverhost
120
121          o Start the client on the clienthost, as follows:
122                 java Client -ORBInitialPort 1050 -ORBInitialHost nameserverhost
123
124
125   The -J option
126       This command-line option is available for use with tnameserve:
127
128          -Joption
129             Pass option to the Java virtual machine, where option is one of
130             the options described on the reference page for java(1). For
131             example, -J-Xms48m sets the startup memory to 48 megabytes. It is
132             a common convention for -J to pass options to the underlying vir‐
133             tual machine.
134
135

Stopping the Java IDL Transient Naming Service

137       To stop the Java IDL naming service, use the relevant operating system
138       command, such as kill for a Unix process, or Ctrl-C for a Windows
139       process. The naming service will continue to wait for invocations until
140       it is explicitly shutdown. Note that names registered with the Java IDL
141       naming service disappear when the service is terminated.
142

Sample Client: Adding Objects to the Namespace

144       The following sample program illustrates how to add names to the names‐
145       pace. It is a self-contained Transient Naming Service client that cre‐
146       ates the following simple tree.
147
148          o Initial Naming Context
149
150             * plans
151
152             * Personal
153
154                - calendar
155
156                - schedule
157
158
159       In this example, plans is an object reference and Personal is a naming
160       context that contains two object references: calendar and schedule.
161
162       import java.util.Properties;
163       import org.omg.CORBA.*;
164       import org.omg.CosNaming.*;
165
166       public class NameClient
167       {
168          public static void main(String args[])
169          {
170             try {
171
172
173       In the above section, Starting the Java IDL Transient Naming Service,
174       the nameserver was started on port 1050. The following code ensures
175       that the client program is aware of this port number.
176               Properties props = new Properties();
177               props.put("org.omg.CORBA.ORBInitialPort", "1050");
178               ORB orb = ORB.init(args, props);
179
180
181
182       This code obtains the initial naming context and assigns it to ctx. The
183       second line copies ctx into a dummy object reference objref that we'll
184       attach to various names and add into the namespace.
185               NamingContext ctx =
186       NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
187               NamingContext objref = ctx;
188
189
190
191       This code creates a name "plans" of type "text" and binds it to our
192       dummy object reference. "plans" is then added under the initial naming
193       context using rebind. The rebind method allows us to run this program
194       over and over again without getting the exceptions we'd get from using
195       bind.
196               NameComponent nc1 = new NameComponent("plans", "text");
197               NameComponent[] name1 = {nc1};
198               ctx.rebind(name1, objref);
199               System.out.println("plans rebind successful!");
200
201
202
203       This code creates a naming context called "Personal" of type "direc‐
204       tory". The resulting object reference, ctx2, is bound to the name and
205       added under the initial naming context.
206               NameComponent nc2 = new NameComponent("Personal", "directory");
207               NameComponent[] name2 = {nc2};
208               NamingContext ctx2 = ctx.bind_new_context(name2);
209               System.out.println("new naming context added..");
210
211
212
213       The remainder of the code binds the dummy object reference using the
214       names "schedule" and "calendar" under the "Personal" naming context
215       (ctx2).
216               NameComponent nc3 = new NameComponent("schedule", "text");
217               NameComponent[] name3 = {nc3};
218               ctx2.rebind(name3, objref);
219               System.out.println("schedule rebind successful!");
220
221               NameComponent nc4 = new NameComponent("calender", "text");
222               NameComponent[] name4 = {nc4};
223               ctx2.rebind(name4, objref);
224               System.out.println("calender rebind successful!");
225
226
227           } catch (Exception e) {
228               e.printStackTrace(System.err);
229           }
230         }
231       }
232
233

Sample Client: Browsing the Namespace

235       The following sample program illustrates how to browse the namespace.
236
237       import java.util.Properties;
238       import org.omg.CORBA.*;
239       import org.omg.CosNaming.*;
240
241       public class NameClientList
242       {
243          public static void main(String args[])
244          {
245             try {
246
247
248       In the above section, Starting the Java IDL Transient Naming Service,
249       the nameserver was started on port 1050. The following code ensures
250       that the client program is aware of this port number.
251
252               Properties props = new Properties();
253               props.put("org.omg.CORBA.ORBInitialPort", "1050");
254               ORB orb = ORB.init(args, props);
255
256
257
258
259       The following code obtains the initial naming context.
260               NamingContext nc =
261       NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
262
263
264
265       The list method lists the bindings in the naming context. In this case,
266       up to 1000 bindings from the initial naming context will be returned in
267       the BindingListHolder; any remaining bindings are returned in the
268       BindingIteratorHolder.
269               BindingListHolder bl = new BindingListHolder();
270               BindingIteratorHolder blIt= new BindingIteratorHolder();
271               nc.list(1000, bl, blIt);
272
273
274
275       This code gets the array of bindings out of the returned Bind‐
276       ingListHolder. If there are no bindings, the program ends.
277               Binding bindings[] = bl.value;
278               if (bindings.length == 0) return;
279
280
281
282       The remainder of the code loops through the bindings and prints the
283       names out.
284               for (int i=0; i < bindings.length; i++) {
285
286                   // get the object reference for each binding
287                   org.omg.CORBA.Object obj = nc.resolve(bindings[i].binding_name);
288                   String objStr = orb.object_to_string(obj);
289                   int lastIx = bindings[i].binding_name.length-1;
290
291                   // check to see if this is a naming context
292                   if (bindings[i].binding_type == BindingType.ncontext) {
293                     System.out.println( "Context: " +
294       bindings[i].binding_name[lastIx].id);
295                   } else {
296                       System.out.println("Object: " +
297       bindings[i].binding_name[lastIx].id);
298                   }
299               }
300
301              } catch (Exception e) {
302               e.printStackTrace(System.err);
303              }
304          }
305       }
306
307
308                                  16 Mar 2012                     tnameserv(1)
Impressum