mfang | f2cf006 | 2015-07-15 12:12:46 -0700 | [diff] [blame] | 1 | '\" t |
| 2 | .\" Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
| 3 | .\" DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | .\" |
| 5 | .\" This code is free software; you can redistribute it and/or modify it |
| 6 | .\" under the terms of the GNU General Public License version 2 only, as |
| 7 | .\" published by the Free Software Foundation. |
| 8 | .\" |
| 9 | .\" This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | .\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | .\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | .\" version 2 for more details (a copy is included in the LICENSE file that |
| 13 | .\" accompanied this code). |
| 14 | .\" |
| 15 | .\" You should have received a copy of the GNU General Public License version |
| 16 | .\" 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | .\" Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | .\" |
| 19 | .\" Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | .\" or visit www.oracle.com if you need additional information or have any |
| 21 | .\" questions. |
| 22 | .\" |
| 23 | .\" Arch: generic |
| 24 | .\" Software: JDK 8 |
| 25 | .\" Date: 21 November 2013 |
| 26 | .\" SectDesc: Java IDL and RMI-IIOP Tools |
| 27 | .\" Title: tnameserv.1 |
| 28 | .\" |
| 29 | .if n .pl 99999 |
| 30 | .TH tnameserv 1 "21 November 2013" "JDK 8" "Java IDL and RMI-IIOP Tools" |
| 31 | .\" ----------------------------------------------------------------- |
| 32 | .\" * Define some portability stuff |
| 33 | .\" ----------------------------------------------------------------- |
| 34 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 35 | .\" http://bugs.debian.org/507673 |
| 36 | .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html |
| 37 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 38 | .ie \n(.g .ds Aq \(aq |
| 39 | .el .ds Aq ' |
| 40 | .\" ----------------------------------------------------------------- |
| 41 | .\" * set default formatting |
| 42 | .\" ----------------------------------------------------------------- |
| 43 | .\" disable hyphenation |
| 44 | .nh |
| 45 | .\" disable justification (adjust text to left margin only) |
| 46 | .ad l |
| 47 | .\" ----------------------------------------------------------------- |
| 48 | .\" * MAIN CONTENT STARTS HERE * |
| 49 | .\" ----------------------------------------------------------------- |
| 50 | |
| 51 | .SH NAME |
| 52 | tnameserv \- Interface Definition Language (IDL)\&. |
| 53 | .SH SYNOPSIS |
| 54 | .sp |
| 55 | .nf |
| 56 | |
| 57 | \fBtnameserve\fR \fB\-ORBInitialPort\fR [ \fInameserverport\fR ] |
| 58 | .fi |
| 59 | .sp |
| 60 | .TP |
| 61 | -ORBInitialPort \fInameserverport\fR |
| 62 | .br |
| 63 | The initial port where the naming service listens for the bootstrap protocol used to implement the ORB \f3resolve_initial_references\fR and \f3list_initial_references\fR methods\&. |
| 64 | .SH DESCRIPTION |
| 65 | Java IDL includes the Object Request Broker Daemon (ORBD)\&. ORBD is a daemon process that contains a Bootstrap Service, a Transient Naming Service, a Persistent Naming Service, and a Server Manager\&. The Java IDL tutorials all use ORBD, but you can substitute the \f3tnameserv\fR command for the \f3orbd\fR command in any of the examples that use a Transient Naming Service\&. |
| 66 | .PP |
| 67 | See orbd(1) or Naming Service at http://docs\&.oracle\&.com/javase/8/docs/technotes/guides/idl/jidlNaming\&.html |
| 68 | .PP |
| 69 | The CORBA Common Object Services (COS) Naming Service provides a tree-structure directory for object references similar to a file system that provides a directory structure for files\&. The Transient Naming Service provided with Java IDL, \f3tnameserv\fR, is a simple implementation of the COS Naming Service specification\&. |
| 70 | .PP |
| 71 | Object references are stored in the name space by name and each object reference-name pair is called a name binding\&. Name bindings can be organized under naming contexts\&. Naming contexts are name bindings and serve the same organizational function as a file system subdirectory\&. All bindings are stored under the initial naming context\&. The initial naming context is the only persistent binding in the name space\&. The rest of the name space is lost when the Java IDL naming service process stops and restarts\&. |
| 72 | .PP |
| 73 | 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 an initial naming context string for that naming service\&. The naming service can either be the Java IDL naming service or another COS-compliant naming service\&. |
| 74 | .SS START\ THE\ NAMING\ SERVICE |
| 75 | 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 (Oracle Solaris: \f3tnameserv\fR) or executable file (Windows: \f3tnameserv\&.exe\fR) that starts the Java IDL naming service\&. Start the naming service so it runs in the background\&. |
| 76 | .PP |
| 77 | If you do not specify otherwise, then the Java IDL naming service listens on port 900 for the bootstrap protocol used to implement the ORB \f3resolve_initial_references\fR and \f3list_initial_references methods\fR, as follows: |
| 78 | .sp |
| 79 | .nf |
| 80 | \f3tnameserv \-ORBInitialPort nameserverport&\fP |
| 81 | .fi |
| 82 | .nf |
| 83 | \f3\fP |
| 84 | .fi |
| 85 | .sp |
| 86 | If you do not specify the name server port, then port 900 is used by default\&. When running Oracle Solaris software, you must become the root user to start a process on a port below 1024\&. For this reason, it is recommended 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 | .sp |
| 88 | .nf |
| 89 | \f3tnameserv \-ORBInitialPort 1050&\fP |
| 90 | .fi |
| 91 | .nf |
| 92 | \f3\fP |
| 93 | .fi |
| 94 | .sp |
| 95 | From an MS-DOS system prompt (Windows), enter: |
| 96 | .sp |
| 97 | .nf |
| 98 | \f3start tnameserv \-ORBInitialPort 1050\fP |
| 99 | .fi |
| 100 | .nf |
| 101 | \f3\fP |
| 102 | .fi |
| 103 | .sp |
| 104 | Clients of the name server must be made aware of the new port number\&. Do this by setting the \f3org\&.omg\&.CORBA\&.ORBInitialPort\fR property to the new port number when you create the ORB object\&. |
| 105 | .SS RUN\ THE\ SERVER\ AND\ CLIENT\ ON\ DIFFERENT\ HOSTS |
| 106 | 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, the client and server probably run on different host machines from the Naming Service\&. |
| 107 | .PP |
| 108 | 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 \f3org\&.omg\&.CORBA\&.ORBInitialPort\fR and \f3org\&.omg\&.CORBA\&.ORBInitialHost\fR 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 Getting Started Using RMI-IIOP at http://docs\&.oracle\&.com/javase/8/docs/technotes/guides/rmi-iiop/rmiiiopexample\&.html |
| 109 | .PP |
| 110 | You could also use the command-line options \f3-ORBInitialPort nameserverport#\fR and \f3-ORBInitialHost nameserverhostname\fR to tell the client and server where to find the naming service\&. For one example of doing this using the command-line option, see Java IDL: The Hello World Example on Two Machines at http://docs\&.oracle\&.com/javase/8/docs/technotes/guides/idl/tutorial/jidl2machines\&.html |
| 111 | .PP |
| 112 | For example, suppose the Transient Naming Service, \f3tnameserv\fR is running on port 1050 on host \f3nameserverhost\fR\&. The client is running on host \f3clienthost,\fR and the server is running on host \f3serverhost\fR\&. |
| 113 | .PP |
| 114 | Start \f3tnameserv\fR on the host \f3nameserverhost\fR: |
| 115 | .sp |
| 116 | .nf |
| 117 | \f3tnameserv \-ORBInitialPort 1050\fP |
| 118 | .fi |
| 119 | .nf |
| 120 | \f3\fP |
| 121 | .fi |
| 122 | .sp |
| 123 | Start the server on the \f3serverhost\fR: |
| 124 | .sp |
| 125 | .nf |
| 126 | \f3java Server \-ORBInitialPort 1050 \-ORBInitialHost nameserverhost\fP |
| 127 | .fi |
| 128 | .nf |
| 129 | \f3\fP |
| 130 | .fi |
| 131 | .sp |
| 132 | Start the client on the \f3clienthost\fR: |
| 133 | .sp |
| 134 | .nf |
| 135 | \f3java Client \-ORBInitialPort 1050 \-ORBInitialHost nameserverhost\fP |
| 136 | .fi |
| 137 | .nf |
| 138 | \f3\fP |
| 139 | .fi |
| 140 | .sp |
| 141 | .SS STOP\ THE\ NAMING\ SERVICE |
| 142 | To stop the Java IDL naming service, use the relevant operating system command, such as \f3kill\fR for a Unix process or \f3Ctrl+C\fR for a Windows process\&. The naming service continues to wait for invocations until it is explicitly shut down\&. Note that names registered with the Java IDL naming service disappear when the service is terminated\&. |
| 143 | .SH OPTIONS |
| 144 | .TP |
| 145 | -J\fIoption\fR |
| 146 | .br |
| 147 | Passes \f3option\fR to the Java Virtual Machine, where \f3option\fR is one of the options described on the reference page for the Java application launcher\&. For example, \f3-J-Xms48m\fR sets the startup memory to 48 MB\&. See java(1)\&. |
| 148 | .SH EXAMPLES |
| 149 | .SS ADD\ OBJECTS\ TO\ THE\ NAME\ SPACE |
| 150 | The following example shows how to add names to the name space\&. It is a self-contained Transient Naming Service client that creates the following simple tree\&. |
| 151 | .sp |
| 152 | .nf |
| 153 | \f3Initial Naming Context\fP |
| 154 | .fi |
| 155 | .nf |
| 156 | \f3 plans\fP |
| 157 | .fi |
| 158 | .nf |
| 159 | \f3 Personal\fP |
| 160 | .fi |
| 161 | .nf |
| 162 | \f3 calendar\fP |
| 163 | .fi |
| 164 | .nf |
| 165 | \f3 schedule\fP |
| 166 | .fi |
| 167 | .nf |
| 168 | \f3\fP |
| 169 | .fi |
| 170 | .sp |
| 171 | In this example, \f3plans\fR is an object reference and \f3Personal\fR is a naming context that contains two object references: \f3calendar\fR and \f3schedule\fR\&. |
| 172 | .sp |
| 173 | .nf |
| 174 | \f3import java\&.util\&.Properties;\fP |
| 175 | .fi |
| 176 | .nf |
| 177 | \f3import org\&.omg\&.CORBA\&.*;\fP |
| 178 | .fi |
| 179 | .nf |
| 180 | \f3import org\&.omg\&.CosNaming\&.*;\fP |
| 181 | .fi |
| 182 | .nf |
| 183 | \f3\fP |
| 184 | .fi |
| 185 | .nf |
| 186 | \f3public class NameClient {\fP |
| 187 | .fi |
| 188 | .nf |
| 189 | \f3\fP |
| 190 | .fi |
| 191 | .nf |
| 192 | \f3 public static void main(String args[]) {\fP |
| 193 | .fi |
| 194 | .nf |
| 195 | \f3\fP |
| 196 | .fi |
| 197 | .nf |
| 198 | \f3 try {\fP |
| 199 | .fi |
| 200 | .nf |
| 201 | \f3\fP |
| 202 | .fi |
| 203 | .sp |
| 204 | In Start the Naming Service, the \f3nameserver\fR was started on port 1050\&. The following code ensures that the client program is aware of this port number\&. |
| 205 | .sp |
| 206 | .nf |
| 207 | \f3 Properties props = new Properties();\fP |
| 208 | .fi |
| 209 | .nf |
| 210 | \f3 props\&.put("org\&.omg\&.CORBA\&.ORBInitialPort", "1050");\fP |
| 211 | .fi |
| 212 | .nf |
| 213 | \f3 ORB orb = ORB\&.init(args, props);\fP |
| 214 | .fi |
| 215 | .nf |
| 216 | \f3\fP |
| 217 | .fi |
| 218 | .sp |
| 219 | This code obtains the initial naming context and assigns it to \f3ctx\fR\&. The second line copies \f3ctx\fR into a dummy object reference \f3objref\fR that is attached to various names and added into the name space\&. |
| 220 | .sp |
| 221 | .nf |
| 222 | \f3 NamingContext ctx =\fP |
| 223 | .fi |
| 224 | .nf |
| 225 | \f3 NamingContextHelper\&.narrow(\fP |
| 226 | .fi |
| 227 | .nf |
| 228 | \f3 orb\&.resolve_initial_references("NameService"));\fP |
| 229 | .fi |
| 230 | .nf |
| 231 | \f3 NamingContext objref = ctx;\fP |
| 232 | .fi |
| 233 | .nf |
| 234 | \f3\fP |
| 235 | .fi |
| 236 | .sp |
| 237 | This code creates a name \f3plans\fR of type \f3text\fR and binds it to the dummy object reference\&. \f3plans\fR is then added under the initial naming context using the \f3rebind\fR method\&. The \f3rebind\fR method enables you to run this program over and over again without getting the exceptions from using the \f3bind\fR method\&. |
| 238 | .sp |
| 239 | .nf |
| 240 | \f3 NameComponent nc1 = new NameComponent("plans", "text");\fP |
| 241 | .fi |
| 242 | .nf |
| 243 | \f3 NameComponent[] name1 = {nc1};\fP |
| 244 | .fi |
| 245 | .nf |
| 246 | \f3 ctx\&.rebind(name1, objref);\fP |
| 247 | .fi |
| 248 | .nf |
| 249 | \f3 System\&.out\&.println("plans rebind successful!");\fP |
| 250 | .fi |
| 251 | .nf |
| 252 | \f3\fP |
| 253 | .fi |
| 254 | .sp |
| 255 | This code creates a naming context called \f3Personal\fR of type \f3directory\fR\&. The resulting object reference, \f3ctx2\fR, is bound to the \f3name\fR and added under the initial naming context\&. |
| 256 | .sp |
| 257 | .nf |
| 258 | \f3 NameComponent nc2 = new NameComponent("Personal", "directory");\fP |
| 259 | .fi |
| 260 | .nf |
| 261 | \f3 NameComponent[] name2 = {nc2};\fP |
| 262 | .fi |
| 263 | .nf |
| 264 | \f3 NamingContext ctx2 = ctx\&.bind_new_context(name2);\fP |
| 265 | .fi |
| 266 | .nf |
| 267 | \f3 System\&.out\&.println("new naming context added\&.\&.");\fP |
| 268 | .fi |
| 269 | .nf |
| 270 | \f3\fP |
| 271 | .fi |
| 272 | .sp |
| 273 | The remainder of the code binds the dummy object reference using the names \f3schedule\fR and \f3calendar\fR under the \f3Personal\fR naming context (\f3ctx2\fR)\&. |
| 274 | .sp |
| 275 | .nf |
| 276 | \f3 NameComponent nc3 = new NameComponent("schedule", "text");\fP |
| 277 | .fi |
| 278 | .nf |
| 279 | \f3 NameComponent[] name3 = {nc3};\fP |
| 280 | .fi |
| 281 | .nf |
| 282 | \f3 ctx2\&.rebind(name3, objref);\fP |
| 283 | .fi |
| 284 | .nf |
| 285 | \f3 System\&.out\&.println("schedule rebind successful!");\fP |
| 286 | .fi |
| 287 | .nf |
| 288 | \f3\fP |
| 289 | .fi |
| 290 | .nf |
| 291 | \f3 NameComponent nc4 = new NameComponent("calender", "text");\fP |
| 292 | .fi |
| 293 | .nf |
| 294 | \f3 NameComponent[] name4 = {nc4};\fP |
| 295 | .fi |
| 296 | .nf |
| 297 | \f3 ctx2\&.rebind(name4, objref);\fP |
| 298 | .fi |
| 299 | .nf |
| 300 | \f3 System\&.out\&.println("calender rebind successful!");\fP |
| 301 | .fi |
| 302 | .nf |
| 303 | \f3 } catch (Exception e) {\fP |
| 304 | .fi |
| 305 | .nf |
| 306 | \f3 e\&.printStackTrace(System\&.err);\fP |
| 307 | .fi |
| 308 | .nf |
| 309 | \f3 }\fP |
| 310 | .fi |
| 311 | .nf |
| 312 | \f3 }\fP |
| 313 | .fi |
| 314 | .nf |
| 315 | \f3}\fP |
| 316 | .fi |
| 317 | .nf |
| 318 | \f3\fP |
| 319 | .fi |
| 320 | .sp |
| 321 | .SS BROWSING\ THE\ NAME\ SPACE |
| 322 | The following sample program shoes how to browse the name space\&. |
| 323 | .sp |
| 324 | .nf |
| 325 | \f3import java\&.util\&.Properties;\fP |
| 326 | .fi |
| 327 | .nf |
| 328 | \f3import org\&.omg\&.CORBA\&.*;\fP |
| 329 | .fi |
| 330 | .nf |
| 331 | \f3import org\&.omg\&.CosNaming\&.*;\fP |
| 332 | .fi |
| 333 | .nf |
| 334 | \f3\fP |
| 335 | .fi |
| 336 | .nf |
| 337 | \f3public class NameClientList {\fP |
| 338 | .fi |
| 339 | .nf |
| 340 | \f3\fP |
| 341 | .fi |
| 342 | .nf |
| 343 | \f3 public static void main(String args[]) {\fP |
| 344 | .fi |
| 345 | .nf |
| 346 | \f3\fP |
| 347 | .fi |
| 348 | .nf |
| 349 | \f3 try {\fP |
| 350 | .fi |
| 351 | .nf |
| 352 | \f3\fP |
| 353 | .fi |
| 354 | .sp |
| 355 | In Start the Naming Service, the \f3nameserver\fR was started on port 1050\&. The following code ensures that the client program is aware of this port number\&. |
| 356 | .sp |
| 357 | .nf |
| 358 | \f3 Properties props = new Properties();\fP |
| 359 | .fi |
| 360 | .nf |
| 361 | \f3 props\&.put("org\&.omg\&.CORBA\&.ORBInitialPort", "1050");\fP |
| 362 | .fi |
| 363 | .nf |
| 364 | \f3 ORB orb = ORB\&.init(args, props);\fP |
| 365 | .fi |
| 366 | .nf |
| 367 | \f3\fP |
| 368 | .fi |
| 369 | .sp |
| 370 | The following code obtains the initial naming context\&. |
| 371 | .sp |
| 372 | .nf |
| 373 | \f3 NamingContext nc =\fP |
| 374 | .fi |
| 375 | .nf |
| 376 | \f3 NamingContextHelper\&.narrow(\fP |
| 377 | .fi |
| 378 | .nf |
| 379 | \f3 orb\&.resolve_initial_references("NameService"));\fP |
| 380 | .fi |
| 381 | .nf |
| 382 | \f3\fP |
| 383 | .fi |
| 384 | .sp |
| 385 | The \f3list\fR 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 \f3BindingListHolder\fR; any remaining bindings are returned in the \f3BindingIteratorHolder\fR\&. |
| 386 | .sp |
| 387 | .nf |
| 388 | \f3 BindingListHolder bl = new BindingListHolder();\fP |
| 389 | .fi |
| 390 | .nf |
| 391 | \f3 BindingIteratorHolder blIt= new BindingIteratorHolder();\fP |
| 392 | .fi |
| 393 | .nf |
| 394 | \f3 nc\&.list(1000, bl, blIt);\fP |
| 395 | .fi |
| 396 | .nf |
| 397 | \f3\fP |
| 398 | .fi |
| 399 | .sp |
| 400 | This code gets the array of bindings out of the returned \f3BindingListHolder\fR\&. If there are no bindings, then the program ends\&. |
| 401 | .sp |
| 402 | .nf |
| 403 | \f3 Binding bindings[] = bl\&.value;\fP |
| 404 | .fi |
| 405 | .nf |
| 406 | \f3 if (bindings\&.length == 0) return;\fP |
| 407 | .fi |
| 408 | .nf |
| 409 | \f3\fP |
| 410 | .fi |
| 411 | .sp |
| 412 | The remainder of the code loops through the bindings and prints outs the names\&. |
| 413 | .sp |
| 414 | .nf |
| 415 | \f3 for (int i=0; i < bindings\&.length; i++) {\fP |
| 416 | .fi |
| 417 | .nf |
| 418 | \f3\fP |
| 419 | .fi |
| 420 | .nf |
| 421 | \f3 // get the object reference for each binding\fP |
| 422 | .fi |
| 423 | .nf |
| 424 | \f3 org\&.omg\&.CORBA\&.Object obj = nc\&.resolve(bindings[i]\&.binding_name);\fP |
| 425 | .fi |
| 426 | .nf |
| 427 | \f3 String objStr = orb\&.object_to_string(obj);\fP |
| 428 | .fi |
| 429 | .nf |
| 430 | \f3 int lastIx = bindings[i]\&.binding_name\&.length\-1;\fP |
| 431 | .fi |
| 432 | .nf |
| 433 | \f3\fP |
| 434 | .fi |
| 435 | .nf |
| 436 | \f3 // check to see if this is a naming context\fP |
| 437 | .fi |
| 438 | .nf |
| 439 | \f3 if (bindings[i]\&.binding_type == BindingType\&.ncontext) {\fP |
| 440 | .fi |
| 441 | .nf |
| 442 | \f3 System\&.out\&.println("Context: " +\fP |
| 443 | .fi |
| 444 | .nf |
| 445 | \f3 bindings[i]\&.binding_name[lastIx]\&.id);\fP |
| 446 | .fi |
| 447 | .nf |
| 448 | \f3 } else {\fP |
| 449 | .fi |
| 450 | .nf |
| 451 | \f3 System\&.out\&.println("Object: " +\fP |
| 452 | .fi |
| 453 | .nf |
| 454 | \f3 bindings[i]\&.binding_name[lastIx]\&.id);\fP |
| 455 | .fi |
| 456 | .nf |
| 457 | \f3 }\fP |
| 458 | .fi |
| 459 | .nf |
| 460 | \f3 }\fP |
| 461 | .fi |
| 462 | .nf |
| 463 | \f3 } catch (Exception e) {\fP |
| 464 | .fi |
| 465 | .nf |
| 466 | \f3 e\&.printStackTrace(System\&.err)\fP |
| 467 | .fi |
| 468 | .nf |
| 469 | \f3 }\fP |
| 470 | .fi |
| 471 | .nf |
| 472 | \f3 }\fP |
| 473 | .fi |
| 474 | .nf |
| 475 | \f3}\fP |
| 476 | .fi |
| 477 | .nf |
| 478 | \f3\fP |
| 479 | .fi |
| 480 | .sp |
| 481 | .SH SEE\ ALSO |
| 482 | .TP 0.2i |
| 483 | \(bu |
| 484 | orbd(1) |
| 485 | .RE |
| 486 | .br |
| 487 | 'pl 8.5i |
| 488 | 'bp |