home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / JBuilder8.iso / Solaris / resource / jre / man / sman1 / tnameserv.1 < prev   
Encoding:
Text File  |  2002-09-06  |  12.5 KB  |  184 lines

  1. <!DOCTYPE REFENTRY PUBLIC "-//Sun Microsystems//DTD DocBook V3.0-Based SolBook Subset V2.0//EN" [
  2. <!--ArborText, Inc., 1988-1999, v.4002-->
  3. <!ENTITY % javaents SYSTEM "javaman.ent">
  4. %javaents;
  5. ]>
  6. <refentry id="tnameserv-1">
  7. <!--@(#)tnameserv.1 1.9 01/03/14 SMI;-->
  8. <refmeta><refentrytitle>tnameserv</refentrytitle><manvolnum>1</manvolnum>
  9. <refmiscinfo class="date">23 Apr 2001</refmiscinfo>
  10. <refmiscinfo class="sectdesc">&man1;</refmiscinfo>
  11. <refmiscinfo class="software">&java-release;</refmiscinfo>
  12. <refmiscinfo class="arch">generic</refmiscinfo>
  13. <refmiscinfo class="copyright"> Copyright 2001 Sun Microsystems, Inc. All rights reserved.  Copyright 2001 Sun Microsystems, Inc. Tous droits réservés.  </refmiscinfo>
  14. </refmeta>
  15. <refnamediv><refname>tnameserv</refname><refpurpose>Java IDL name server starter script</refpurpose></refnamediv>
  16. <refsynopsisdiv><title>&synp-tt;</title>
  17. <cmdsynopsis><command>tnameserv</command><arg choice="plain"><option><replaceable>ORBInitialPort</replaceable></option></arg><arg choice="plain"><replaceable>port_number</replaceable></arg>
  18. </cmdsynopsis></refsynopsisdiv>
  19. <refsect1><title>&desc-tt;</title>
  20. <indexterm id="tnameserv-1-indx-1"><primary sortas="Java IDL name server starter script">Java IDL name server starter script — tnameserv</primary></indexterm><indexterm id="tnameserv-1-indx-2"><primary sortas="tnameserv">tnameserv — Java IDL name server starter script</primary></indexterm><para>The <acronym>CORBA</acronym> <acronym>COS</acronym> (Common Object Services) Naming Service provides
  21. a tree-like directory for object references much like a filesystem provides a directory structure for files. The Naming Service provided with Java <acronym remap="small">IDL</acronym> is a simple implementation of the <acronym remap="small">COS</acronym> Naming Service specification.</para>
  22. <para>Object references are stored in the namespace by name and each object reference-name pair is called a name binding. Name bindings may be organized under naming contexts. Naming contexts are themselves 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
  23. binding in the namespace; the rest of the namespace is lost if the Java <acronym>IDL</acronym> name server process halts and restarts.</para>
  24. <para>For an applet or application to use <acronym>COS</acronym> naming, its <acronym>ORB</acronym> must know the name and port of a host running a naming service or have access to a stringified initial naming context for that name server. The naming service can either be the Java <acronym>IDL</acronym> name server or another <acronym>COS</acronym>-compliant name service.</para>
  25. </refsect1>
  26. <refsect1><title>&usge-tt;</title>
  27. <refsect2><title>Starting the Java IDL Name Server</title>
  28. <indexterm id="tnameserv-1-indx-3"><primary sortas="tnameserv">tnameserv — Java IDL name server starter script</primary><secondary>Starting the Java IDL Name Server</secondary></indexterm><para>You must start the Java <acronym>IDL</acronym> name server before an application or applet that uses its naming service. Installation of the Java <acronym>IDL</acronym> product creates a script named <literal>
  29. tnameserv</literal>  that starts the Java <acronym>IDL</acronym> name server. Start the name server so it runs in the background.</para>
  30. <para>If you do not specify otherwise, the Java <acronym>IDL</acronym> name server listens on port 900 for the bootstrap protocol used to implement the <acronym>ORB</acronym> <function>resolve_initial_references</function> and <function>list_initial_references</function> methods. Specify a different port, for example <literal>1050</literal>, as follows:<informalexample><para><screen>example% <userinput>
  31. tnameserv –ORBInitialPort 1050</userinput></screen></para>
  32. </informalexample></para>
  33. <para>Clients of the name server must be made aware of the new port number. Do this by setting the <literal>org.omg.CORBA.ORBInitialPort</literal> property to the new port number when creating the <acronym>ORB</acronym> object.</para>
  34. </refsect2>
  35. <refsect2><title>Stopping the Java IDL Name Server</title>
  36. <indexterm id="tnameserv-1-indx-4"><primary sortas="tnameserv">tnameserv — Java IDL name server starter script</primary><secondary>Stopping the Java IDL Name Server</secondary></indexterm><para>To stop the Java <acronym remap="small">IDL</acronym> name server, use the relevant operating system command, such as <citerefentry><refentrytitle>kill</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
  37. Notice that names registered with the Java <acronym remap="small">IDL</acronym> name service disappear when the server is terminated.</para>
  38. </refsect2>
  39. <refsect2><title>Sample Client: Adding Objects</title>
  40. <indexterm id="tnameserv-1-indx-5"><primary sortas="tnameserv">tnameserv — Java IDL name server starter script</primary><secondary>Sample Client: Browsing the Namespace</secondary></indexterm><indexterm id="tnameserv-1-indx-6"><primary sortas="tnameserv">tnameserv — Java IDL name server starter script</primary><secondary>Sample Client: Adding Objects to the Namespace</secondary></indexterm>
  41. <para>The following sample program illustrates how to add names to the namespace. It is a self-contained Name Server client that creates the following simple tree.<informalexample><screen>        Initial
  42.      Naming Context
  43.       /      \
  44.      /        \
  45.    plans      personal
  46.                /\
  47.               /  \
  48.         calendar   schedule
  49.  
  50. </screen>
  51. </informalexample>In this example, <literal>plans</literal> is an object reference and <literal>personal</literal> is a naming context that contains two object references, <literal>calendar</literal> and <literal>schedule</literal>.<informalexample><screen>import java.util.Properties;
  52. import org.omg.CORBA.*;
  53. import org.omg.CosNaming.*;
  54.  
  55. public class NameClient
  56. {
  57.    public static void main(String args[])
  58.    {
  59.       try {
  60.  
  61. </screen>
  62. </informalexample>In the above section, <literal>Starting the Java IDL Name Server</literal>, the nameserver was started on port <literal>1050</literal>. The following code ensures that the client program is aware of this port number.<informalexample><screen>        Properties props = new Properties();
  63.         props.put("org.omg.CORBA.ORBInitialPort", "1050");
  64.         ORB orb = ORB.init(args, props);
  65.  
  66. </screen>
  67. </informalexample>The following code obtains the initial naming context and assigns it to <literal>ctx</literal>. The second line copies <literal>ctx</literal> into a dummy object reference, <literal>objref</literal>, that we will attach to various names and add into the namespace.<informalexample><screen>        NamingContext ctx = NamingContextHelper.narrow
  68.             (orb.resolve_initial_references("NameService"));
  69.         NamingContext objref = ctx;
  70.  
  71. </screen>
  72. </informalexample>The following code creates a name <literal>plans</literal> of type <literal>text</literal> and binds it to our dummy object reference. <literal>plans</literal> is then added under the initial naming context using <literal>rebind</literal>. The <literal>rebind</literal> method allows us to run this program over and over again without getting the exceptions we would get from using <literal>
  73. bind</literal>.<informalexample><screen>        NameComponent nc1 = new NameComponent("plans", "text");
  74.         NameComponent[] name1 = {nc1};
  75.         ctx.rebind(name1, objref);
  76.         System.out.println("plans rebind sucessful!");
  77.  
  78. </screen>
  79. </informalexample>The following code creates a naming context called <literal>Personal</literal> of type <literal>directory</literal>. The resulting object reference, <literal>ctx2</literal>, is bound to the name and added under the initial naming context.<informalexample><screen>        NameComponent nc2 = new NameComponent("Personal", "directory");
  80.         NameComponent[] name2 = {nc2};
  81.         NamingContext ctx2 = ctx.bind_new_context(name2);
  82.         System.out.println("new naming context added..");
  83.  
  84. </screen>
  85. </informalexample>The remainder of the code binds the dummy object reference using the names <literal>schedule</literal> and <literal>calendar</literal> under the <literal>Personal</literal> naming context (<literal>ctx2</literal>).<informalexample><screen>        NameComponent nc3 = new NameComponent("schedule", "text");
  86.         NameComponent[] name3 = {nc3};
  87.         ctx2.rebind(name3, objref);
  88.         System.out.println("schedule rebind sucessful!");
  89.  
  90.         NameComponent nc4 = new NameComponent("calender", "text");
  91.         NameComponent[] name4 = {nc4};
  92.         ctx2.rebind(name4, objref);
  93.         System.out.println("calender rebind sucessful!");
  94.  
  95.     } catch (Exception e) {
  96.         e.printStackTrace(System.err);
  97.     }
  98.   }
  99. }
  100.  
  101. </screen>
  102. </informalexample></para>
  103. </refsect2>
  104. <refsect2><title>Sample Client: Browsing the Namespace</title>
  105. <para>The following sample program illustrates how to browse the namespace.<informalexample><?Pub Caret><screen>import java.util.Properties;
  106. import org.omg.CORBA.*;
  107. import org.omg.CosNaming.*;
  108.  
  109. public class NameClientList
  110. {
  111.    public static void main(String args[])
  112.    {
  113.       try {
  114.  
  115. </screen>
  116. </informalexample>In the above section, <literal>Starting the Java IDL Name Server</literal>, the nameserver was started on port <literal>1050</literal>. The following code ensures that the client program is aware of this port number.<informalexample><screen>        Properties props = new Properties();
  117.         props.put("org.omg.CORBA.ORBInitialPort", "1050");
  118.         ORB orb = ORB.init(args, props);
  119.  
  120. </screen>
  121. </informalexample>The following code obtains the initial naming context.<informalexample><screen>        NamingContext nc = NamingContextHelper.narrow
  122.            (orb.resolve_initial_references("NameService"));
  123.  
  124. </screen>
  125. </informalexample>The list 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 <literal>BindingListHolder</literal>. Any remaining bindings are returned in the <literal>BindingIteratorHolder</literal>.<informalexample><screen>        BindingListHolder bl = new BindingListHolder();
  126.         BindingIteratorHolder blIt= new BindingIteratorHolder();
  127.         nc.list(1000, bl, blIt);
  128.  
  129. </screen>
  130. </informalexample>The following code gets the array of bindings out of the returned <literal>BindingListHolder</literal>. If there are no bindings, the program ends.<informalexample><screen>        Binding bindings[] = bl.value;
  131.         if (bindings.length == 0) return;
  132.  
  133. </screen>
  134. </informalexample>The remainder of the code loops through the bindings and prints the names out. <screen>        for (int i=0; i < bindings.length; i++) {
  135.  
  136.             // get the object reference for each binding
  137.             org.omg.CORBA.Object obj = nc.resolve
  138.                  (bindings[i].binding_name);
  139.             String objStr = orb.object_to_string(obj);
  140.             int lastIx = bindings[i].binding_name.length-1;
  141.  
  142.             // check to see if this is a naming context
  143.             if (bindings[i].binding_type == BindingType.ncontext) {
  144.               System.out.println
  145.                  ("Context: " + bindings[i].binding_name[lastIx].id);
  146.             } else {
  147.                 System.out.println
  148.                    ("Object: " + bindings[i].binding_name[lastIx].id);
  149.             }
  150.         }
  151.  
  152.        } catch (Exception e) {
  153.         e.printStackTrace(System.err);
  154.        }
  155.    }
  156. }
  157.  
  158. </screen></para>
  159. </refsect2>
  160. </refsect1>
  161. <refsect1><title>&attr-tt;</title>
  162. <para>See <olink targetdocent="REFMAN5" localinfo="attributes-5"><citerefentry><refentrytitle>attributes</refentrytitle><manvolnum>5</manvolnum></citerefentry></olink> for a description of the following attributes:</para>
  163. <informaltable frame="all" orient="port">
  164. <tgroup cols="2" colsep="1" rowsep="1"><colspec colnum="1" colname="col1" colwidth="1*" colsep="1" align="left"><colspec colnum="2" colname="col2" colwidth="1*" align="left">
  165. <thead>
  166. <row><entry colname="col1" align="center" valign="top">ATTRIBUTE TYPE</entry><entry colname="col2" align="center" valign="top">ATTRIBUTE VALUE</entry></row>
  167. </thead>
  168. <tbody>
  169. <row><entry>Availability</entry><entry>SUNWj3dev</entry></row>
  170. </tbody>
  171. </tgroup>
  172. </informaltable>
  173. </refsect1>
  174. <refsect1><title>&also-tt;</title>
  175. <para><citerefentry><refentrytitle>kill</refentrytitle><manvolnum>1</manvolnum></citerefentry>, <citerefentry><refentrytitle>attributes</refentrytitle><manvolnum>5</manvolnum></citerefentry> </para>
  176. </refsect1>
  177. <!--+ 07/27/00 08:36:13
  178.     | tagMorph:  $Id: tagMorph-engine 1.54 1998/01/19 05:44:48 $
  179.     | tagMorph library:  $Id: libtagMorph.a 1.50 1998/01/19 22:02:51 $
  180.     | sunman-to-solbook 1.17
  181.     +-->
  182. </refentry>
  183. <?Pub *0000012859 0>
  184.