NAME
tnameserv - Java IDL name server starter script
SYNOPSIS
ttnnaammeesseerrvv -OORRBBIInniittiiaallPPoorrtt portNumber
DESCRIPTION
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 Naming Service provided with Java IDL is a simple implementation of the COS Naming Service specification. Object references are stored in the namespace by name and each objectreference-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 systemsubdirectory. All bindings are stored under the initial naming con-
text. The initial naming context is the only persistent binding in the namespace; the rest of the namespace is lost if the Java IDL name server process halts and restarts. For an applet or application to use COS naming, its ORB 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 namingservice can either be the Java IDL name server or another COS-compliant
name service. UUSSAAGGEE SSttaarrttiinngg tthhee JJaavvaa IIDDLL NNaammee SSeerrvveerr You must start the Java IDL name server before an application or applet that uses its naming service. Installation of the Java IDL productcreates a script named tnameserv that starts the Java IDL name server.
Start the name server so it runs in the background. If you do not specify otherwise, the Java IDL name server listens on port 900 for the bootstrap protocol used to implement the ORB rreessoollvveeiinniittiiaallrreeffeerreenncceess(()) and lliissttiinniittiiaallrreeffeerreenncceess(()) methods. Specify a different port, for example, 11005500, as follows:eexxaammppllee%% ttnnaammeesseerrvv -OORRBBIInniittiiaallPPoorrtt 11005500
Clients of the name server must be made aware of the new port number. Do this by setting the oorrgg..oommgg..CCOORRBBAA..OORRBBIInniittiiaallPPoorrtt property to the new port number when creating the ORB object. SSttooppppiinngg tthhee JJaavvaa IIDDLL NNaammee SSeerrvveerr To stop the Java IDL name server, use the relevant operating system command, such as kkiillll(1). Note that names registered with the Java IDL name service disappear when the server is terminated. SSaammppllee CClliieenntt:: AAddddiinngg OObbjjeeccttssThe following sample program illustrates how to add names to the names-
pace. It is a self-contained Name Server client that creates the fol-
lowing simple tree. IInniittiiaall NNaammiinngg CCoonntteexxtt // \\ // \\ ppllaannss ppeerrssoonnaall //\\ // \\ ccaalleennddaarr sscchheedduullee In this example, "plans" is an object reference and "personal" is a naming context that contains two object references: "calendar" and "schedule". iimmppoorrtt jjaavvaa..uuttiill..PPrrooppeerrttiieess;; iimmppoorrtt oorrgg..oommgg..CCOORRBBAA..**;; iimmppoorrtt oorrgg..oommgg..CCoossNNaammiinngg..**;; ppuubblliicc ccllaassss NNaammeeCClliieenntt {{ ppuubblliicc ssttaattiicc vvooiidd mmaaiinn((SSttrriinngg aarrggss[[]])) {{ ttrryy {{ In the above section, SSttaarrttiinngg tthhee JJaavvaa IIDDLL NNaammee SSeerrvveerr, the nameserver was started on port 11005500. The following code ensures that the client program is aware of this port number. PPrrooppeerrttiieess pprrooppss == nneeww PPrrooppeerrttiieess(());; pprrooppss..ppuutt((""oorrgg..oommgg..CCOORRBBAA..OORRBBIInniittiiaallPPoorrtt"",, ""11005500""));; OORRBB oorrbb == OORRBB..iinniitt((aarrggss,, pprrooppss));; The following code obtains the initial naming context and assigns it to ccttxx. The second line copies ccttxx into a dummy object reference, oobbjjrreeff, that we will attach to various names and add into the namespace. NNaammiinnggCCoonntteexxtt ccttxx == NNaammiinnggCCoonntteexxttHHeellppeerr..nnaarrrrooww ((oorrbb..rreessoollvveeiinniittiiaallrreeffeerreenncceess((""NNaammeeSSeerrvviiccee""))));; NNaammiinnggCCoonntteexxtt oobbjjrreeff == ccttxx;; The following 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 rreebbiinndd. The rreebbiinndd method allows us to run this program over and over again without getting the exceptions we would get from using bbiinndd. NNaammeeCCoommppoonneenntt nncc11 == nneeww NNaammeeCCoommppoonneenntt((""ppllaannss"",, ""tteexxtt""));; NNaammeeCCoommppoonneenntt[[]] nnaammee11 == {{nncc11}};; ccttxx..rreebbiinndd((nnaammee11,, oobbjjrreeff));; SSyysstteemm..oouutt..pprriinnttllnn((""ppllaannss rreebbiinndd ssuucceessssffuull!!""));; The following code creates a naming context called "Personal" of type "directory". The resulting object reference, ccttxx22, is bound to the name and added under the initial naming context. NNaammeeCCoommppoonneenntt nncc22 == nneeww NNaammeeCCoommppoonneenntt((""PPeerrssoonnaall"",, ""ddiirreeccttoorryy""));; NNaammeeCCoommppoonneenntt[[]] nnaammee22 == {{nncc22}};; NNaammiinnggCCoonntteexxtt ccttxx22 == ccttxx..bbiinnddnneewwccoonntteexxtt((nnaammee22));; SSyysstteemm..oouutt..pprriinnttllnn((""nneeww nnaammiinngg ccoonntteexxtt aaddddeedd....""));; The remainder of the code binds the dummy object reference using the names "schedule" and "calendar" under the "Personal" naming context (ccttxx22). NNaammeeCCoommppoonneenntt nncc33 == nneeww NNaammeeCCoommppoonneenntt((""sscchheedduullee"",, ""tteexxtt""));; NNaammeeCCoommppoonneenntt[[]] nnaammee33 == {{nncc33}};; ccttxx22..rreebbiinndd((nnaammee33,, oobbjjrreeff));; SSyysstteemm..oouutt..pprriinnttllnn((""sscchheedduullee rreebbiinndd ssuucceessssffuull!!""));; NNaammeeCCoommppoonneenntt nncc44 == nneeww NNaammeeCCoommppoonneenntt((""ccaalleennddeerr"",, ""tteexxtt""));; NNaammeeCCoommppoonneenntt[[]] nnaammee44 == {{nncc44}};; ccttxx22..rreebbiinndd((nnaammee44,, oobbjjrreeff));; SSyysstteemm..oouutt..pprriinnttllnn((""ccaalleennddeerr rreebbiinndd ssuucceessssffuull!!""));; }} ccaattcchh ((EExxcceeppttiioonn ee)) {{ ee..pprriinnttSSttaacckkTTrraaccee((SSyysstteemm..eerrrr));; }} }} }} SSaammppllee CClliieenntt:: BBrroowwssiinngg tthhee NNaammeessppaaccee The following sample program illustrates how to browse the namespace. iimmppoorrtt jjaavvaa..uuttiill..PPrrooppeerrttiieess;; iimmppoorrtt oorrgg..oommgg..CCOORRBBAA..**;; iimmppoorrtt oorrgg..oommgg..CCoossNNaammiinngg..**;; ppuubblliicc ccllaassss NNaammeeCClliieennttLLiisstt {{ ppuubblliicc ssttaattiicc vvooiidd mmaaiinn((SSttrriinngg aarrggss[[]])) {{ ttrryy {{ In the above section, SSttaarrttiinngg tthhee JJaavvaa IIDDLL NNaammee SSeerrvveerr, the nameserver was started on port 11005500. The following code ensures that the client program is aware of this port number. PPrrooppeerrttiieess pprrooppss == nneeww PPrrooppeerrttiieess(());; pprrooppss..ppuutt((""oorrgg..oommgg..CCOORRBBAA..OORRBBIInniittiiaallPPoorrtt"",, ""11005500""));; OORRBB oorrbb == OORRBB..iinniitt((aarrggss,, pprrooppss));; The following code obtains the initial naming context. NNaammiinnggCCoonntteexxtt nncc == NNaammiinnggCCoonntteexxttHHeellppeerr..nnaarrrrooww ((oorrbb..rreessoollvveeiinniittiiaallrreeffeerreenncceess((""NNaammeeSSeerrvviiccee""))));; 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 BBiinnddiinnggLLiissttHHoollddeerr; any remaining bindings are returned in the BBiinnddiinnggIItteerraattoorrHHoollddeerr. BBiinnddiinnggLLiissttHHoollddeerr bbll == nneeww BBiinnddiinnggLLiissttHHoollddeerr(());; BBiinnddiinnggIItteerraattoorrHHoollddeerr bbllIItt== nneeww BBiinnddiinnggIItteerraattoorrHHoollddeerr(());; nncc..lliisstt((11000000,, bbll,, bbllIItt));;The following code gets the array of bindings out of the returned BBiinndd-
iinnggLLiissttHHoollddeerr. If there are no bindings, the program ends. BBiinnddiinngg bbiinnddiinnggss[[]] == bbll..vvaalluuee;; iiff ((bbiinnddiinnggss..lleennggtthh ==== 00)) rreettuurrnn;; The remainder of the code loops through the bindings and prints the names out. ffoorr ((iinntt ii==00;; ii << bbiinnddiinnggss..lleennggtthh;; ii++++)) {{ //// ggeett tthhee oobbjjeecctt rreeffeerreennccee ffoorr eeaacchh bbiinnddiinngg oorrgg..oommgg..CCOORRBBAA..OObbjjeecctt oobbjj == nncc..rreessoollvvee ((bbiinnddiinnggss[[ii]]..bbiinnddiinnggnnaammee));; SSttrriinngg oobbjjSSttrr == oorrbb..oobbjjeeccttttoossttrriinngg((oobbjj));;iinntt llaassttIIxx == bbiinnddiinnggss[[ii]]..bbiinnddiinnggnnaammee..lleennggtthh-11;;
//// cchheecckk ttoo sseeee iiff tthhiiss iiss aa nnaammiinngg ccoonntteexxtt iiff ((bbiinnddiinnggss[[ii]]..bbiinnddiinnggttyyppee ==== BBiinnddiinnggTTyyppee..nnccoonntteexxtt)) {{ SSyysstteemm..oouutt..pprriinnttllnn ((""CCoonntteexxtt:: "" ++ bbiinnddiinnggss[[ii]]..bbiinnddiinnggnnaammee[[llaassttIIxx]]..iidd));; }} eellssee {{ SSyysstteemm..oouutt..pprriinnttllnn ((""OObbjjeecctt:: "" ++ bbiinnddiinnggss[[ii]]..bbiinnddiinnggnnaammee[[llaassttIIxx]]..iidd));; }} }} }} ccaattcchh ((EExxcceeppttiioonn ee)) {{ ee..pprriinnttSSttaacckkTTrraaccee((SSyysstteemm..eerrrr));; }} }} }}SEE ALSO
kkiillll(1)13 June 2000 tnameserv(1)