tnameserv.1 13.2 KB
Newer Older
1
." Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
."
." This code is free software; you can redistribute it and/or modify it
." under the terms of the GNU General Public License version 2 only, as
." published by the Free Software Foundation.
."
." This code is distributed in the hope that it will be useful, but WITHOUT
." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
." version 2 for more details (a copy is included in the LICENSE file that
." accompanied this code).
."
." You should have received a copy of the GNU General Public License version
." 2 along with this work; if not, write to the Free Software Foundation,
." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
."
." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
." or visit www.oracle.com if you need additional information or have any
." questions.
."
.TH tnameserv 1 "10 May 2011"

.LP
.SH "Name"
Java IDL: Transient Naming Service \- \f2tnameserv\fP
.LP
.LP
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
.na
\f2Java IDL Naming Service Included with ORBD\fP @
.fi
http://download.oracle.com/javase/7/docs/technotes/guides/idl/jidlNaming.html topic.
.LP
.LP
Topics in this section include:
.LP
.RS 3
.TP 2
o
Java\ IDL Transient Naming Service
.TP 2
o
Starting the Java\ IDL Transient Naming Service
.TP 2
o
Stopping the Java\ IDL Transient Naming Service
.TP 2
o
Sample Client: Adding Objects to the Namespace
.TP 2
o
Sample Client: Browsing the Namespace
.RE

.LP
.SH "Java\ IDL Transient Naming Service"
.LP
.LP
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.
.LP
.LP
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.
.LP
.LP
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.
.LP
.SH "Starting the Java\ IDL Transient Naming Service"
.LP
.LP
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.
.LP
.LP
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:
.LP
.nf
\f3
.fl
        tnameserv \-ORBInitialPort \fP\f4nameserverport\fP\f3&
.fl
\fP
.fi

.LP
.LP
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:
.LP
.nf
\f3
.fl
        tnameserv \-ORBInitialPort 1050&
.fl
\fP
.fi

.LP
.LP
From an MS\-DOS system prompt (Windows), enter:
.LP
.nf
\f3
.fl
        start tnameserv \-ORBInitialPort 1050
.fl
\fP
.fi

.LP
.LP
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.
.LP
.SS
Running the server and client on different hosts
.LP
.LP
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.
.LP
.LP
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
.na
\f2The Hello World Example Using RMI\-IIOP\fP @
.fi
http://download.oracle.com/javase/7/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.
.na
\f2Java IDL: Running the Hello World Example on TWO Machines\fP @
.fi
http://download.oracle.com/javase/7/docs/technotes/guides/idl/tutorial/jidl2machines.html shows one way of doing this using the command line option.
.LP
.LP
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.
.LP
.RS 3
.TP 2
o
Start \f2tnameserv\fP on the host \f2nameserverhost\fP, as follows:
.nf
\f3
.fl
     tnameserv \-ORBInitialPort 1050
.fl

.fl
\fP
.fi
.TP 2
o
Start the server on the \f2serverhost\fP, as follows:
.nf
\f3
.fl
     java Server \-ORBInitialPort 1050 \-ORBInitialHost nameserverhost
.fl
\fP
.fi
.TP 2
o
Start the client on the \f2clienthost\fP, as follows:
.nf
\f3
.fl
     java Client \-ORBInitialPort 1050 \-ORBInitialHost nameserverhost
.fl
\fP
.fi
.RE

.LP
.SS
The \-J option
.LP
This command\-line option is available for use with \f2tnameserve\fP:
.RS 3
.TP 3
\-Joption
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.
.RE

.LP
.SH "Stopping the Java\ IDL Transient Naming Service"
.LP
.LP
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.
.LP
.SH "Sample Client: Adding Objects to the Namespace"
.LP
.LP
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.
.LP
.RS 3
.TP 2
o
\f4Initial Naming Context\fP
.RS 3
.TP 2
*
\f3plans\fP
.TP 2
*
\f4Personal\fP
.RS 3
.TP 2
-
\f3calendar\fP
.TP 2
-
\f3schedule\fP
.RE
.RE
.RE

.LP
.LP
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.
.LP
.nf
\f3
.fl
import java.util.Properties;
.fl
import org.omg.CORBA.*;
.fl
import org.omg.CosNaming.*;
.fl

.fl
public class NameClient
.fl
{
.fl
   public static void main(String args[])
.fl
   {
.fl
      try {
.fl
\fP
.fi

.LP
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.
.nf
\f3
.fl
        Properties props = new Properties();
.fl
        props.put("org.omg.CORBA.ORBInitialPort", "1050");
.fl
        ORB orb = ORB.init(args, props);
.fl

.fl
\fP
.fi

.LP
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.
.nf
\f3
.fl
        NamingContext ctx =
.fl
NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
.fl
        NamingContext objref = ctx;
.fl

.fl
\fP
.fi

.LP
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.
.nf
\f3
.fl
        NameComponent nc1 = new NameComponent("plans", "text");
.fl
        NameComponent[] name1 = {nc1};
.fl
        ctx.rebind(name1, objref);
.fl
        System.out.println("plans rebind sucessful!");
.fl

.fl
\fP
.fi

.LP
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.
.nf
\f3
.fl
        NameComponent nc2 = new NameComponent("Personal", "directory");
.fl
        NameComponent[] name2 = {nc2};
.fl
        NamingContext ctx2 = ctx.bind_new_context(name2);
.fl
        System.out.println("new naming context added..");
.fl

.fl
\fP
.fi

.LP
The remainder of the code binds the dummy object reference using the names "schedule" and "calendar" under the "Personal" naming context (\f3ctx2\fP).
.nf
\f3
.fl
        NameComponent nc3 = new NameComponent("schedule", "text");
.fl
        NameComponent[] name3 = {nc3};
.fl
        ctx2.rebind(name3, objref);
.fl
        System.out.println("schedule rebind sucessful!");
.fl

.fl
        NameComponent nc4 = new NameComponent("calender", "text");
.fl
        NameComponent[] name4 = {nc4};
.fl
        ctx2.rebind(name4, objref);
.fl
        System.out.println("calender rebind sucessful!");
.fl

.fl

.fl
    } catch (Exception e) {
.fl
        e.printStackTrace(System.err);
.fl
    }
.fl
  }
.fl
}
.fl
\fP
.fi

.LP
.SH "Sample Client: Browsing the Namespace"
.LP
.LP
The following sample program illustrates how to browse the namespace.
.LP
.nf
\f3
.fl
import java.util.Properties;
.fl
import org.omg.CORBA.*;
.fl
import org.omg.CosNaming.*;
.fl

.fl
public class NameClientList
.fl
{
.fl
   public static void main(String args[])
.fl
   {
.fl
      try {
.fl
\fP
.fi

.LP
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.
.nf
\f3
.fl

.fl
        Properties props = new Properties();
.fl
        props.put("org.omg.CORBA.ORBInitialPort", "1050");
.fl
        ORB orb = ORB.init(args, props);
.fl

.fl

.fl
\fP
.fi

.LP
The following code obtains the intial naming context.
.nf
\f3
.fl
        NamingContext nc =
.fl
NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
.fl

.fl
\fP
.fi

.LP
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.
.nf
\f3
.fl
        BindingListHolder bl = new BindingListHolder();
.fl
        BindingIteratorHolder blIt= new BindingIteratorHolder();
.fl
        nc.list(1000, bl, blIt);
.fl

.fl
\fP
.fi

.LP
This code gets the array of bindings out of the returned BindingListHolder. If there are no bindings, the program ends.
.nf
\f3
.fl
        Binding bindings[] = bl.value;
.fl
        if (bindings.length == 0) return;
.fl

.fl
\fP
.fi

.LP
The remainder of the code loops through the bindings and prints the names out.
.nf
\f3
.fl
        for (int i=0; i < bindings.length; i++) {
.fl

.fl
            // get the object reference for each binding
.fl
            org.omg.CORBA.Object obj = nc.resolve(bindings[i].binding_name);
.fl
            String objStr = orb.object_to_string(obj);
.fl
            int lastIx = bindings[i].binding_name.length\-1;
.fl

.fl
            // check to see if this is a naming context
.fl
            if (bindings[i].binding_type == BindingType.ncontext) {
.fl
              System.out.println( "Context: " +
.fl
bindings[i].binding_name[lastIx].id);
.fl
            } else {
.fl
                System.out.println("Object: " +
.fl
bindings[i].binding_name[lastIx].id);
.fl
            }
.fl
        }
.fl

.fl
       } catch (Exception e) {
.fl
        e.printStackTrace(System.err);
.fl
       }
.fl
   }
.fl
}
.fl
\fP
.fi

.LP