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 man
15       page or the Java IDL Naming Service Included with ORBD @
16       http://java.sun.com/javase/6/docs/technotes/guides/idl/jidlNaming.html
17       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://java.sun.com/javase/6/docs/technotes/guides/rmi-iiop/rmiiiopex
102       ample.html. You could also use the command line options -ORBInitialPort
103       nameserverport# and -ORBInitialHost nameserverhostname to tell the
104       client and server where to find the Naming Service.  Java IDL: Running
105       the Hello World Example on TWO Machines @
106       http://java.sun.com/javase/6/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
129          -Joption
130             Pass option to the Java virtual machine, where option is one of
131             the options described on the reference page for the java applica‐
132             tion launcher @
133             http://java.sun.com/javase/6/docs/tech
134             notes/tools/solaris/java.html. For example, -J-Xms48m sets the
135             startup memory to 48 megabytes. It is a common convention for -J
136             to pass options to the underlying virtual machine.
137

Stopping the Java IDL Transient Naming Service

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

Sample Client: Adding Objects to the Namespace

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

Sample Client: Browsing the Namespace

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