~rdoering/ubuntu/karmic/erlang/fix-535090

« back to all changes in this revision

Viewing changes to lib/orber/doc/src/ch_stubs.xml

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (1.1.13 upstream)
  • mto: (3.3.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: james.westby@ubuntu.com-20090215164252-dxpjjuq108nz4noa
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="latin1" ?>
 
2
<!DOCTYPE chapter SYSTEM "chapter.dtd">
 
3
 
 
4
<chapter>
 
5
  <header>
 
6
    <copyright>
 
7
      <year>1999</year>
 
8
      <year>2007</year>
 
9
      <holder>Ericsson AB, All Rights Reserved</holder>
 
10
    </copyright>
 
11
    <legalnotice>
 
12
  The contents of this file are subject to the Erlang Public License,
 
13
  Version 1.1, (the "License"); you may not use this file except in
 
14
  compliance with the License. You should have received a copy of the
 
15
  Erlang Public License along with this software. If not, it can be
 
16
  retrieved online at http://www.erlang.org/.
 
17
 
 
18
  Software distributed under the License is distributed on an "AS IS"
 
19
  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
20
  the License for the specific language governing rights and limitations
 
21
  under the License.
 
22
 
 
23
  The Initial Developer of the Original Code is Ericsson AB.
 
24
    </legalnotice>
 
25
 
 
26
    <title>Orber Stubs/Skeletons</title>
 
27
    <prepared></prepared>
 
28
    <docno></docno>
 
29
    <date>1999-09-03</date>
 
30
    <rev>A</rev>
 
31
  </header>
 
32
 
 
33
  <section>
 
34
    <title>Orber Stubs and Skeletons Description</title>
 
35
    <p>This example describes the API and behavior of Orber stubs and skeletons.
 
36
      </p>
 
37
 
 
38
    <section>
 
39
      <title>Server Start</title>
 
40
      <p>Orber servers can be started in several ways. The chosen start functions determines
 
41
        how the server can be accessed and its behavior.
 
42
        </p>
 
43
      <p>Using <c>Module_Interface:oe_create()</c> or <c>oe_create_link()</c>:
 
44
        </p>
 
45
      <list type="bulleted">
 
46
        <item>No initial data can be passed.</item>
 
47
        <item>Cannot be used as a supervisor child start function.</item>
 
48
        <item>Only accessible through the object reference returned by the start function.
 
49
         The object reference is no longer valid if the server dies and is restarted.</item>
 
50
      </list>
 
51
      <p>Using <c>Module_Interface:oe_create(Env)</c> or <c>oe_create_link(Env)</c>:</p>
 
52
      <list type="bulleted">
 
53
        <item>Initial data can be passed using <c>Env</c>.</item>
 
54
        <item>Cannot be used as a supervisor child start function.</item>
 
55
        <item>Only accessible through the object reference returned by the start function.
 
56
         The object reference is no longer valid if the server dies and is restarted.</item>
 
57
      </list>
 
58
      <p>Using <c>Module_Interface:oe_create(Env, Options)</c>:</p>
 
59
      <list type="bulleted">
 
60
        <item>Initial data can be passed using <c>Env</c>.</item>
 
61
        <item>Cannot be used as a supervisor child start function.</item>
 
62
        <item>Accessible through the object reference returned by the start function. If the option 
 
63
        <c>{regname, RegName}</c> is used the object reference stays valid even if the 
 
64
         server has been restarted.</item>
 
65
        <item>If the options <c>{persistent, true}</c> and <c>{regname, {global, Name}}</c> is used, 
 
66
         the result from an object invocation will be the exception 'OBJECT_NOT_EXIST' 
 
67
         only if the object has terminated with reason 
 
68
        <c>normal</c> or <c>shutdown</c>. If the object is in the process of restarting, the result 
 
69
         will be <c>{error, Reason}</c> or a system exception is raised.</item>
 
70
        <item>The option <c>{pseudo, true}</c> makes it possible to start create non-server objects.
 
71
         There are, however, some limitations, which are further described in the
 
72
        <c>Pseudo objects</c> section.</item>
 
73
      </list>
 
74
      <p>Using <c>Module_Interface:oe_create_link(Env, Options)</c>:</p>
 
75
      <list type="bulleted">
 
76
        <item>Initial data can be passed using <c>Env</c>.</item>
 
77
        <item>Can be used as a supervisor child start function if the option <c>{sup_child, true}</c> used.</item>
 
78
        <item>Accessible through the object reference returned by the start function. If the option 
 
79
        <c>{regname, RegName}</c> is used the object reference stays valid even if the 
 
80
         server has been restarted.</item>
 
81
        <item>If the options <c>{persistent, true}</c> and <c>{regname, {global, Name}}</c> is used, 
 
82
         the result from an object invocation will be the exception 'OBJECT_NOT_EXIST' 
 
83
         only if the object has terminated with reason 
 
84
        <c>normal</c> or <c>shutdown</c>. If the object is in the process of restarting, the result 
 
85
         will be <c>{error, Reason}</c> or a system exception is raised.</item>
 
86
        <item>For starting a server as a supervisor child you should use the options 
 
87
        <c>[{persistent, true}, {regname, {global, Name}}, {sup_child, true}]</c> and of type <em>transient</em>.
 
88
         This configuration allows you to delegate restarts to the supervisor and still be able to
 
89
         use the same object reference and be able to see if the server is permanently terminated.
 
90
         Please note you must use <em>supervisor/stdlib-1.7</em> or later and that the it returns 
 
91
        <c>{ok, Pid, Object}</c> instead of just <c>Object</c>.</item>
 
92
        <item>Using the option <c>{pseudo, true}</c> have the same effect as using
 
93
        <c>oe_create/2</c>.</item>
 
94
      </list>
 
95
      <warning>
 
96
        <p>To avoid flooding Orber with old object references start erlang using the flag 
 
97
          <em>-orber objectkeys_gc_time Time</em>, which will remove all object references
 
98
          related to servers being dead for Time seconds. To avoid extra overhead, i.e., performing
 
99
          garbage collect if no persistent objects are started, the objectkeys_gc_time default value 
 
100
          is <em>infinity</em>. For more information, see the orber and corba documentation.</p>
 
101
      </warning>
 
102
      <warning>
 
103
        <p>Orber still allow <c>oe_create(Env, {Type,RegName})</c> and <c>oe_create_link(Env, {Type,RegName})</c> to be used,
 
104
          but may not in future releases.</p>
 
105
      </warning>
 
106
    </section>
 
107
 
 
108
    <section>
 
109
      <title>Pseudo Objects</title>
 
110
      <p>This section describes Orber pseudo objects.
 
111
        </p>
 
112
      <p>The Orber stub can be used to start a <c>pseudo object</c>, which will create a non-server implementation.
 
113
        A pseudo object introduce some limitations:</p>
 
114
      <list type="bulleted">
 
115
        <item>The functions <c>oe_create_link/2</c> is equal to <c>oe_create/2</c>, i.e.,
 
116
         no link can or will be created.</item>
 
117
        <item>The <c>BIF:s self()</c> and <c>process_flag(trap_exit,true)</c> behaves incorrectly.</item>
 
118
        <item>The <c>IC</c> option <c>{{impl, "M::I"}, "other_impl"}</c> has no effect. The call-back
 
119
         functions must be implemented in a file called <c>M_I_impl.erl</c></item>
 
120
        <item>The call-back functions must be implemented as if the <c>IC</c> option 
 
121
        <c>{this, "M::I"}</c> was used.</item>
 
122
        <item>The gen_server <c>State</c> changes have no effect. The user can provide information via
 
123
         the <c>Env</c> start parameter and the State returned from <c>init/2</c> will be the State
 
124
         passed in following invocations.</item>
 
125
        <item>The server reply <c>Timeout</c> has no effect.</item>
 
126
        <item>The compile option <c>from</c> has no effect.</item>
 
127
        <item>The option <c>{pseudo, true}</c> overrides all other start options.</item>
 
128
        <item>Only the functions, besides own definitions, <c>init/2</c> (called via oe_create*/2) and 
 
129
        <c>terminate/2</c> (called via corba:dispose/1) must be implemented.</item>
 
130
      </list>
 
131
      <p>By adopting the rules for <c>pseudo</c> objects described above we can use <c>oe_create/2</c>
 
132
        to create <c>server</c> or <c>pseudo</c> objects, by excluding or including the 
 
133
        option <c>{pseudo, true}</c>, without changing the call-back module.</p>
 
134
      <p>To create a pseudo object do the following:</p>
 
135
      <code type="none">
 
136
fingolfin 127> erl 
 
137
Erlang (BEAM) emulator version 4.9
 
138
 
 
139
Eshell V4.9  (abort with ^G)
 
140
1> ic:gen(myDefinition, [{this, "MyModule::MyInterface"}]).
 
141
Erlang IDL compiler version 20
 
142
ok
 
143
2> make:all().
 
144
Recompile: oe_MyDefinition
 
145
Recompile: MyModule_MyInterface
 
146
Recompile: MyModule_MyInterface_impl
 
147
up_to_date
 
148
3> PseudoObj = MyModule_MyInterface:oe_create(Env, [{pseudo, true}]).
 
149
      </code>
 
150
      <p>The call-back functions must be implemented as <c>MyFunction(OE_THIS, State, Args)</c>,
 
151
        and called by <c>MyModule_MyInterface:MyFunction(PseudoObj, Args)</c>.</p>
 
152
    </section>
 
153
 
 
154
    <section>
 
155
      <title>Call-back Module</title>
 
156
      <p>This section provides an example of how a call-back module may be implemented.</p>
 
157
      <note>
 
158
        <p>Arguments and Replies are determined by the IDL-code and, hence, not
 
159
          further described here.</p>
 
160
      </note>
 
161
      <code type="none">
 
162
%%%-----------------------------------------------------------
 
163
%%% File    : Module_Interface_impl.erl
 
164
%%% Author  : 
 
165
%%% Purpose : 
 
166
%%% Created : 
 
167
%%%-----------------------------------------------------------
 
168
 
 
169
-module('Module_Interface_impl').
 
170
 
 
171
%%--------------- INCLUDES -----------------------------------
 
172
-include_lib("orber/include/corba.hrl").
 
173
-include_lib(".. ..").
 
174
 
 
175
%%--------------- EXPORTS-------------------------------------
 
176
%% Arity depends on IC configuration parameters and the IDL
 
177
%% specification.
 
178
-export([own_function/X]).
 
179
 
 
180
 
 
181
%%--------------- gen_server specific ------------------------
 
182
-export([init/1, terminate/2, code_change/3, handle_info/2]).
 
183
 
 
184
%%------------------------------------------------------------
 
185
%% function : server specific
 
186
%%------------------------------------------------------------
 
187
init(InitialData) ->
 
188
    %% 'trap_exit' optional (have no effect if pseudo object).
 
189
    process_flag(trap_exit,true),
 
190
 
 
191
    %%--- Possible replies ---
 
192
    %% Reply and await next request
 
193
    {ok, State}.
 
194
 
 
195
    %% Reply and if no more requests within Time the special 
 
196
    %% timeout message should be handled in the 
 
197
    %% Module_Interface_impl:handle_info/2 call-back function (use the 
 
198
    %% IC option {{handle_info, "Module::Interface"}, true}).
 
199
    {ok, State, Timeout} 
 
200
 
 
201
    %% Return ignore in order to inform the parent, especially if it is a 
 
202
    %% supervisor, that the server, as an example, did not start in 
 
203
    %% accordance with the configuration data. 
 
204
    ignore 
 
205
    %% If the initializing procedure fails, the reason 
 
206
    %% is supplied as StopReason.
 
207
    {stop, StopReason}
 
208
 
 
209
terminate(Reason, State) ->
 
210
    ok.
 
211
 
 
212
code_change(OldVsn, State, Extra) ->
 
213
    {ok, NewState}.
 
214
 
 
215
%% If use IC option {{handle_info, "Module::Interface"}, true}. 
 
216
%% (have no effect if pseudo object).
 
217
handle_info(Info, State) ->
 
218
    %%--- Possible replies ---
 
219
    %% Await the next invocation.
 
220
    {noreply, State}.
 
221
    %% Stop with Reason.
 
222
    {stop, Reason, State}.
 
223
 
 
224
%%--- two-way ------------------------------------------------
 
225
%% If use IC option {this, "Module:Interface"} 
 
226
%% (Required for pseudo objects)
 
227
own_function(This, State, .. Arguments ..) ->
 
228
%% IC options this and from
 
229
own_function(This, From, State, .. Arguments ..) ->
 
230
%% IC option from
 
231
own_function(From, State, .. Arguments ..) ->
 
232
    %% Send explicit reply to client.
 
233
    corba:reply(From, Reply),
 
234
    %%--- Possible replies ---
 
235
    {noreply, State}
 
236
    {noreply, State, Timeout}
 
237
 
 
238
 
 
239
%% If not use IC option {this, "Module:Interface"}
 
240
own_function(State, .. Arguments ..) ->
 
241
    %%--- Possible replies ---
 
242
    %% Reply and await next request
 
243
    {reply, Reply, State}
 
244
 
 
245
    %% Reply and if no more requests within Time the special 
 
246
    %% timeout message should be handled in the 
 
247
    %% Module_Interface_impl:handle_info/2 call-back function (use the
 
248
    %% IC option {{handle_info, "Module::Interface"}, true}).
 
249
    {reply, Reply, State, Timeout}
 
250
 
 
251
    %% Stop the server and send Reply to invoking object.
 
252
    {stop, StopReason, Reply, State}
 
253
 
 
254
    %% Stop the server and send no reply to invoking object.
 
255
    {stop, StopReason, State}
 
256
 
 
257
    %% Raise exception. Any changes to the internal State is lost.
 
258
    corba:raise(Exception).
 
259
 
 
260
%%--- one-way ------------------------------------------------
 
261
%% If use IC option {this, "Module:Interface"}
 
262
%% (Required for pseudo objects)
 
263
own_function(This, State, .. Arguments ..) ->
 
264
 
 
265
%% If not use IC option {this, "Module:Interface"}
 
266
own_function(State, .. Arguments ..) ->
 
267
    %%--- Possible results ---
 
268
    {noreply, State}
 
269
 
 
270
    %% Release and if no more requests within Time the special 
 
271
    %% timeout message should be handled in the 
 
272
    %% Module_Interface_impl:handle_info/2 call-back function (use the
 
273
    %%  IC option {{handle_info, "Module::Interface"}, true}).
 
274
    {noreply, State, Timeout}
 
275
 
 
276
    %% Stop the server with StopReason.
 
277
    {stop, StopReason, State}
 
278
 
 
279
%%--------------- END OF MODULE ------------------------------
 
280
      </code>
 
281
    </section>
 
282
  </section>
 
283
</chapter>
 
284