aboutsummaryrefslogtreecommitdiffstats
path: root/lib/orber/doc/src/ch_naming_service.xml
blob: bcbab2a5976000c0bf1563c8347adbb933e45edb (plain) (blame)
1
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
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">

<chapter>
  <header>
    <copyright>
      <year>1997</year><year>2016</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
 
          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    
    </legalnotice>

    <title>CosNaming Service</title>
    <prepared></prepared>
    <docno></docno>
    <date>1998-10-10</date>
    <rev></rev>
    <file>ch_naming_service.xml</file>
  </header>

  <section>
    <title>Overview of the CosNaming Service</title>
    <p>The CosNaming Service is a service developed to help users and
      programmers identify objects by human readable names rather than by a
      reference.  By  binding a name to a naming context (another object), a
      contextual reference is formed. This is helpful when navigating in the
      object space. In addition, identifying objects by name allows you to evolve
      and/or relocate objects without client code modification.</p>
    <p>The CosNaming service has some concepts that are important:</p>
    <list type="bulleted">
      <item>
        <p><em>name binding</em> - a name to object association.</p>
      </item>
      <item>
        <p><em>naming context</em> - is an object that contains a set of
          name bindings in which each name is unique. Different names can be
          bound to the same object.  
          </p>
      </item>
      <item>
        <p><em>to bind a name</em> - is to create a name binding in a given
          context.</p>
      </item>
      <item>
        <p><em>to resolve a name</em> - is to determine the object associated
          with the name in a given context.</p>
      </item>
    </list>
    <p>A name is always resolved in a context, there no absolute names exist.
      Because a context is like any other object, it can also be bound to
      a name
      in a naming context. 
      This will result in a naming graph (a directed graph with notes and 
      labeled edges). The graph allows more complex names to refer to an
      object. Given a context, you can use a sequence to reference an object.
      This sequence is henceforth referred to as <em>name</em> and the
      individual
      elements in the sequence as <em>name components</em>. All but the 
      last name component are bound to naming contexts.
      </p>
    <p>The diagram in figure 1 illustrates how the Naming Service provides a
      contextual relationship between objects, NamingContexts and
      NameBindings to create an object locality, as the
      object itself, has no name.
      </p>
    <marker id="name"></marker>
    <image file="name.gif">
      <icaption>
Figure 1: Contextual object relationships using the Naming Service.</icaption>
    </image>
    <p>The naming contexts provide a directory of contextual
      reference and naming for objects (an object can appear to 
      have more than one name).
      </p>
    <p>In figure 1 the object to the right can either be
      called <c>alpha</c> from one context or <c>gamma</c> from another.  
      </p>
    <p>The Naming Service has an initial naming context, which is shown 
      in the diagram as the top-most object in the naming graph.
      It has two names <c>beta</c> and <c>epsilon</c>, which are bound to other
      naming contexts. The initial naming context is a well known location 
      used to share a common name space between multiple programs.
      You can traverse the naming graph until you reach a name, which is
      bound to an object, which is not a naming context.
      </p>
    <p>We recommend reading <em>chapter 12, CORBA Fundamentals and Programming</em>, for detailed information regarding the 
      Naming Service. </p>
  </section>

  <section>
    <title>The Basic Use-cases of the Naming Service</title>
    <p>The basic use-cases of the Naming Service are:
      </p>
    <list type="bulleted">
      <item>Fetch initial reference to the naming service.</item>
      <item>Creating a naming context.</item>
      <item>Binding and unbinding names to objects.</item>
      <item>Resolving a name to an object.</item>
      <item>Listing the bindings of a naming context.</item>
      <item>Destroying a naming context.</item>
    </list>

    <section>
      <title>Fetch Initial Reference to the Naming Service</title>
      <p>In order to use the naming service you have to fetch an 
        initial reference to it. This is done with:</p>
      <code type="none">
NS = corba:resolve_initial_references("NameService").
      </code>
      <note>
        <p>NS in the other use-cases refers to this initial reference.</p>
      </note>
    </section>

    <section>
      <title>Creating a Naming Context</title>
      <p>There are two functions for creating a naming context.
        The first function, which only creates a naming context object is:</p>
      <code type="none">
NC = 'CosNaming_NamingContext':new_context(NS).
      </code>
      <p>The other function creates a naming context and binds it to a name in 
        an already existing naming context (the initial context in this 
        example):
        </p>
      <code type="none">
NC = 'CosNaming_NamingContext':bind_new_context(NS, lname:new(["new"])).
      </code>
    </section>

    <section>
      <title>Binding and Unbinding Names to Objects</title>
      <p>The following steps illustrate how to bind/unbind an object reference 
        to/from a name. For the example below, assume that the NamingContexts 
        in the path are already bound to the name <c>/workgroup/services</c>, 
        and that reference to the services context are in the variable 
        <c>Sc</c>.</p>
      <list type="ordered">
        <item>
          <p>Use the naming library functions to create a name</p>
          <code type="none">
Name = lname:new(["object"]).
          </code>
        </item>
        <item>
          <p>Use CosNaming::NamingContext::bind() to bind a name to an object</p>
          <code type="none">
'CosNaming_NamingContext':bind(Sc, Name, Object).
          </code>
        </item>
        <item>
          <p>Use CosNaming::NamingContext::unbind() to remove the NameBinding from an object</p>
          <code type="none">
'CosNaming_NamingContext':unbind(Sc, Name).
          </code>
        </item>
      </list>
      <note>
        <p>Objects can have more than one name, to indicate different paths to 
          the same object.</p>
      </note>
    </section>

    <section>
      <title>Resolving a Name to an Object</title>
      <p>The following steps show how to  retrieve the object reference to the service context 
        above (/workgroup/services).    </p>
      <list type="ordered">
        <item>
          <p>Use the naming library functions to create a name path:</p>
          <code type="none">
Name = lname:new(["workgroup", "services"]).
          </code>
        </item>
        <item>
          <p>Use CosNaming::NamingContext::resolve() to to resolve the name to an object</p>
          <code type="none">
Sc = 'CosNaming_NamingContext':resolve(NS, Name).
          </code>
        </item>
      </list>
      <p>An alternative is to use:</p>
      <code type="none">
Sc = corba:string_to_object("corbaname:rir:/NameService#workgroup/services/").
      </code>
      <p>The <c>corbaname</c> schema is described further in the Interoperable
        Naming Service section.</p>
    </section>

    <section>
      <title>Listing the Bindings in a NamingContext</title>
      <list type="ordered">
        <item>
          <p>Use CosNaming::NamingContext::list() to list all the bindings in a context</p>
          <p>The following code retrieves and lists up to 10 bindings from a context.</p>
          <code type="none">
{BList, BIterator} = 'CosNaming_NamingContext':list(Sc, 10).

lists:foreach(fun({{Id, Kind},BindingType}) -> case BindingType of 
    nobject ->
        io:format("id: %s, kind: %s, type: object~n", [Id, Kind]);
    _ ->
        io:format("id: %s, kind: %s, type: ncontext~n", [Id, Kind])
    end end,
    Blist).
          </code>
        </item>
      </list>
      <note>
        <p>Normally a <term id="BindingIterator"><termdef>The binding iterator (Like a book mark) indicates which objects have been read from the list.</termdef></term>is helpful in situations where you have a large number of objects 
          in a list, as the programmer then can traverse it more easily.
          In Erlang it is not needed, because lists are easily handled in the 
          language itself.</p>
      </note>
      <warning>
        <p>Remember that the BindingIterator (BIterator in the example) is an object and therefore
          <em>must be removed</em> otherwise dangling processes will occur.
          Use <c>CosNaming::BindingIterator::destroy()</c> to remove it.</p>
      </warning>
      <code type="none">
      'CosNaming_NamingContext':destroy(BIterator).
      </code>
    </section>

    <section>
      <title>Destroying a Naming Context</title>
      <p>The naming contexts are persistent and must be explicitly removed.
        (they are also removed if all Orber nodes in the domain are stopped).</p>
      <list type="ordered">
        <item>
          <p>Use CosNaming::NamingContext::destroy() to remove a NamingContext</p>
          <code type="none">
'CosNaming_NamingContext':destroy(Sc).
          </code>
        </item>
      </list>
    </section>
  </section>

  <section>
    <title>Interoperable Naming Service</title>
    <marker id="interop_ns"></marker>
    <p>The OMG specifies URL schemes, which represent a CORBA object and a CORBA object
      bound in a NamingContext, for resolving references from other ORB:s. As of today,
      three schemes are defined:</p>
    <list type="bulleted">
      <item>IOR</item>
      <item>corbaloc</item>
      <item>corbaname</item>
    </list>

    <section>
      <title>IOR</title>
      <p>A stringified IOR is a valid URL format but difficult for humans to handle
        through non-electronic means. This URL format does not depend on a specific
        Name Service and, thus, is robust and insulates the client from the encapsulated
        transport information and object key used to reference the object.</p>
    </section>

    <section>
      <title>corbaloc</title>
      <p>The notation of this scheme is similar to the more well known URL <c>HTTP</c>, and
        the full <c>corbaloc</c> BNF is:</p>
      <code type="none"><![CDATA[
<corbaloc>            =  "corbaloc:"<obj_addr_list>["/"<key_string>] 
<obj_addr_list>       = [<obj_addr>","]*<obj_addr> 
<obj_addr>            = <prot_addr> | <future_prot_addr> 
<prot_addr>           = <rir_prot_addr> | <iiop_prot_addr> 
<rir_prot_addr>       = <rir_prot_token>":"  
<rir_prot_token>      = rir  
<future_prot_addr>    = <future_prot_id><future_prot_addr>
<future_prot_id>      = <future_prot_token>":" 
<iiop_prot_addr>      = <iiop_id><iiop_addr>
<iiop_id>             = <iiop_default> | <iiop_prot_token>":"  
<iiop_default>        = ":"  
<iiop_prot_token>     = "iiop"  
<iiop_addr>           = <version><host>[":"<port>] 
<host>                = <DNS-style Host Name> | <ip_v4_address> | "["<ip_v6_address>"]"
<version>             = <major>"."<minor>"@"  | empty_string 
<port>                = number 
<major>               = number 
<minor>               = number
<DNS-style Host Name> = string
<ip_v4_address>       = string
<ip_v6_address>       = string
<key_string>          = for example NameService
      ]]></code>
      <p>The <c>corbaloc</c> scheme consists of 3 parts:</p>
      <list type="bulleted">
        <item>Protocol - as of today <c>iiop</c> or <c>rir</c> is supported.
         Using <c>rir</c> means that we will resolve the given Key locally, i.e.,
         the same as using <c>corba:resolve_initial_references("NameService").</c></item>
        <item>IIOP address - this address can be divided into <c>Version</c>, <c>Host</c> 
         and <c>Port</c>. If the version or port are left out they will be set to the default
         values <c>1.0</c> and <c>2809</c> respectively.</item>
        <item>KeyString - an object key, e.g., "NameService". If no Key is 
         supplied the default value "NameService" will be used.</item>
      </list>
      <p>A <c>corbaloc</c> can be passed used together with 
        <c>corba:string_to_object("corbaloc::[email protected]:4001/NameService")</c> or set as the 
        configuration variables <c>orbInitilRef</c> or <c>orbDefaultInitilRef</c> and calling
        <c>corba:resolve_initial_references("NameService")</c>. For more information see the Orber
        installation chapter. <c>corbaloc</c> can also be used together with <c>corbaname</c>
        to gain an easy access to a Name Service.</p>
      <p>Currently, the OMG defines a set of reserved keys and the type of object,
        listed below, they should be associated with. The <c>NameService</c>
        key may <em>not</em> be changed in Orber. If you want to add one of the
        reserved keys as an initial service, simply use:</p>
      <code type="none">
1> Factory = cosNotificationApp:start_global_factory().
2> corba:add_initial_service("NotificationService", Factory).
      </code>
      <p>This object can then be easily resolved by any other ORB, supporting 
        the Interoperable Naming Service, by using:</p>
      <code type="none">
3> NF = corba:string_to_object("corbaloc::[email protected]:4001/NotificationService").
      </code>
      <table>
        <row>
          <cell align="center" valign="middle"><em>String Name</em></cell>
          <cell align="center" valign="middle"><em>Object Type</em></cell>
        </row>
        <row>
          <cell align="left" valign="middle">RootPOA</cell>
          <cell align="left" valign="middle">PortableServer::POA</cell>
        </row>
        <row>
          <cell align="left" valign="middle">POACurrent</cell>
          <cell align="left" valign="middle">PortableServer::Current</cell>
        </row>
        <row>
          <cell align="left" valign="middle">InterfaceRepository</cell>
          <cell align="left" valign="middle">CORBA::Repository</cell>
        </row>
        <row>
          <cell align="left" valign="middle">NameService</cell>
          <cell align="left" valign="middle">CosNaming::NamingContext</cell>
        </row>
        <row>
          <cell align="left" valign="middle">TradingService</cell>
          <cell align="left" valign="middle">CosTrading::Lookup</cell>
        </row>
        <row>
          <cell align="left" valign="middle">SecurityCurrent</cell>
          <cell align="left" valign="middle">SecurityLevel1::Current/SecurityLevel2::Current</cell>
        </row>
        <row>
          <cell align="left" valign="middle">TransactionCurrent</cell>
          <cell align="left" valign="middle">CosTransaction::Current</cell>
        </row>
        <row>
          <cell align="left" valign="middle">DynAnyFactory</cell>
          <cell align="left" valign="middle">DynamicAny::DynAnyFactory</cell>
        </row>
        <row>
          <cell align="left" valign="middle">ORBPolicyManager</cell>
          <cell align="left" valign="middle">CORBA::PolicyManager</cell>
        </row>
        <row>
          <cell align="left" valign="middle">PolicyCurrent</cell>
          <cell align="left" valign="middle">CORBA::PolicyCurrent</cell>
        </row>
        <row>
          <cell align="left" valign="middle">NotificationService</cell>
          <cell align="left" valign="middle">CosNotifyChannelAdmin::EventChannelFactory</cell>
        </row>
        <row>
          <cell align="left" valign="middle">TypedNotificationService</cell>
          <cell align="left" valign="middle">CosTypedNotifyChannelAdmin::TypedEventChannelFactory</cell>
        </row>
        <row>
          <cell align="left" valign="middle">CodecFactory</cell>
          <cell align="left" valign="middle">IOP::CodecFactory</cell>
        </row>
        <row>
          <cell align="left" valign="middle">PICurrent</cell>
          <cell align="left" valign="middle">PortableInterceptors::Current</cell>
        </row>
        <tcaption>Currently reserved key strings</tcaption>
      </table>
    </section>

    <section>
      <title>corbaname</title>
      <p>The <c>corbaname</c> URL scheme is an extension of the <c>corbaloc</c> scheme, and
        the full <c>corbaname</c> BNF is:</p>
      <code type="none"><![CDATA[
<corbaname>     = "corbaname:"<obj_addr_list>["/"<key_string>]["#"<string_name>] 
<obj_addr_list> = as described above.
<key_string>    = as described above.
      ]]></code>
      <p>The <c>string_name</c>, concatenated to the <c>corbaloc</c> string, identifies
        a binding in a naming context. A name component consists of two parts, i.e.,
        <c>id</c> and <c>kind</c>, which is represented as follows:</p>
      <table>
        <row>
          <cell align="center" valign="middle"><em>String Name</em></cell>
          <cell align="center" valign="middle"><em>Name Sequence</em></cell>
          <cell align="center" valign="middle"><em>Comment</em></cell>
        </row>
        <row>
          <cell align="left" valign="middle">"id1/./id3.kind3"</cell>
          <cell align="left" valign="middle">[{"id1",""},{"",""},{"id3","kind3"}]</cell>
          <cell align="left" valign="middle">The first component has no kind defined while the second component's both fields are empty.</cell>
        </row>
        <row>
          <cell align="left" valign="middle">"id1//id3.kind3"</cell>
          <cell align="left" valign="middle">ERROR</cell>
          <cell align="left" valign="middle">Not allowed, must insert a '.' between the '//'.</cell>
        </row>
        <row>
          <cell align="left" valign="middle">"id1.kind1/."</cell>
          <cell align="left" valign="middle">[{"id1","kind1"},{"",""}]</cell>
          <cell align="left" valign="middle">The first component's fields are both set while the second component's both fields are empty.</cell>
        </row>
        <row>
          <cell align="left" valign="middle">"id1.kind1/id2."</cell>
          <cell align="left" valign="middle">ERROR</cell>
          <cell align="left" valign="middle">An Id with a trailing '.' is not allowed.</cell>
        </row>
        <row>
          <cell align="left" valign="middle">"i\\/d1/i\\.d2"</cell>
          <cell align="left" valign="middle">[{"i/d1",""},{"i.d2",""}]</cell>
          <cell align="left" valign="middle">Since '.' and '/' are used to separate the components, these tokens must be escaped to be correctly converted.</cell>
        </row>
        <tcaption>Stringified Name representation</tcaption>
      </table>
      <p>After creating a stringified Name we can either use:</p>
      <code type="none">
NameStr = "org.erlang",
NS      = corba:resolve_initial_references("NameService"),
Obj     = 'CosNaming_NamingContextExt':resolve_str(NS, NameStr),
      </code>
      <p>or concatenate the Name String using:</p>
      <code type="none">
NameStr = "Swedish/Soccer/Champions",
Address = "corbaname:iiop:[email protected]:2000/NameService",
NS      = corba:resolve_initial_references("NameService"),
URLStr  = 'CosNaming_NamingContextExt':to_url(NS, Address, NameStr),
Obj     = corba:string_to_object(URLStr),
      </code>
      <p>Using the first alternative, the configuration variables <c>orbInitilRef</c> and
        <c>orbDefaultInitilRef</c>, will determine which other ORB's or the local
        Name Service Orber will try to resolve the given string from. The second
        alternative allows us to override any settings of the configuration variables.</p>
      <p>The function <c>to_url/3</c> will perform any necessary escapes compliant with
        IETF/RFC 2396. US-ASCII alphanumeric characters and 
        <c><![CDATA["," | "/" | ":" | "?" | "@" | "&" | "=" | "+" | "$" | ";" | "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"]]></c>
        are not escaped.</p>
    </section>
  </section>
</chapter>