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
|
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
<header>
<copyright>
<year>1999</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>Resource Skeletons</title>
<prepared>Niclas Eklund</prepared>
<docno></docno>
<date>1999-04-29</date>
<rev></rev>
<file>ch_skeletons.xml</file>
</header>
<section>
<title>Resource Skeletons</title>
<p>This chapter provides a skeleton for application Resources. For more information
see the Orber documentation.</p>
<code type="none">
%%%-----------------------------------------------------------
%%% File : Module_Interface_impl.erl
%%% Author :
%%% Purpose :
%%% Created :
%%%-----------------------------------------------------------
-module('Module_Interface_impl').
%%--------------- INCLUDES -----------------------------------
-include_lib("orber/include/corba.hrl").
-include_lib("cosTransactions/include/CosTransactions.hrl").
%%--------------- EXPORTS-------------------------------------
%%- Inherit from CosTransactions::Resource -------------------
-export([prepare/2,
rollback/2,
commit/2,
commit_one_phase/2,
forget/2]).
%%- Inherit from CosTransactions::SubtransactionAwareResource
-export([commit_subtransaction/3,
rollback_subtransaction/2]).
%%--------------- gen_server specific ------------------------
-export([init/1, terminate/2, code_change/3, handle_info/2]).
%%------------------------------------------------------------
%% function : gen_server specific
%%------------------------------------------------------------
init(Env) ->
%% 'trap_exit' optional
process_flag(trap_exit,true),
%%--- Possible replies ---
%% Reply and await next request
{ok, State}.
%% Reply and if no more requests within Time the special
%% timeout message should be handled in the
%% Module_Interface_impl:handle_info/2 call-back function (use the
%% IC option {{handle_info, "Module::Interface"}, true}).
{ok, State, TimeOut}.
%% Return ignore in order to inform the parent, especially if it is a
%% supervisor, that the server, as an example, did not start in
%% accordance with the configuration data.
ignore.
%% If the initializing procedure fails, the reason
%% is supplied as StopReason.
{stop, StopReason}.
terminate(Reason, State) ->
ok.
code_change(OldVsn, State, Extra) ->
{ok, NewState}.
%% If use IC option {{handle_info, "Module::Interface"}, true}
handle_info(Info, State) ->
%%--- Possible replies ---
%% Await the next invocation.
{noreply, State}.
%% Stop with Reason.
{stop, Reason, State}.
%%- Inherit from CosTransactions::Resource -------------------
prepare(State) ->
%%% Do application specific actions here %%%
%%-- Reply: --
%% If no data related to the transaction changed.
{reply, 'VoteReadOnly', State}
%% .. or (for example):
{stop, normal, 'VoteReadOnly', State}.
%% If able to commit
{reply, 'VoteCommit', State}
%% If not able to commit
{reply, 'VoteRollback', State}
%% .. or (for example):
{stop, normal, 'VoteRollback', State}.
rollback(State) ->
%%% Do application specific actions here %%%
%%-- Reply: --
%% If able to rollback successfully
{reply, ok, State}
%% .. or (for example):
{stop, normal, ok, State}.
%% If Heuristic Decision. Raise exception:
corba:raise(#'CosTransactions_HeuristicMixed' {})
corba:raise(#'CosTransactions_HeuristicHazard' {})
corba:raise(#'CosTransactions_HeuristicCommit'{})
commit(State) ->
%%% Do application specific actions here %%%
%%-- Reply: --
%% If able to commit successfully
{reply, ok, State}
%% .. or (for example):
{stop, normal, ok, State}.
%% If the prepare operation never been invoked:
corba:raise(#'CosTransactions_NotPrepared'{})
%% If Heuristic Decision. Raise exception:
corba:raise(#'CosTransactions_HeuristicMixed' {})
corba:raise(#'CosTransactions_HeuristicHazard' {})
corba:raise(#'CosTransactions_HeuristicRollback'{})
commit_one_phase(State) ->
%%% Do application specific actions here %%%
%%-- Reply: --
%% If able to commit successfully
{reply, ok, State}
%% .. or (for example):
{stop, normal, ok, State}.
%% If fails. Raise exception:
corba:raise(#'CosTransactions_HeuristicHazard' {})
%% If able to rollback successfully
corba:raise(#'CosTransactions_TransactionRolledBack' {})
forget(State) ->
%%% Do application specific actions here %%%
%%-- Reply: --
{reply, ok, State}.
%% .. or (for example):
{stop, normal, ok, State}.
%%%%%% If the Resource is also supposed to be a %%%%%%
%%%%%% SubtransactionAwareResource implement these. %%%%%%
%%- Inherit from CosTransactions::SubtransactionAwareResource
commit_subtransaction(State, Parent) ->
%%% Do application specific actions here %%%
%%-- Reply: --
{reply, ok, State}.
%% .. or (for example):
{stop, normal, ok, State}.
rollback_subtransaction(State) ->
%%% Do application specific actions here %%%
%%-- Reply: --
{reply, ok, State}.
%% .. or (for example):
{stop, normal, ok, State}.
%%--------------- END OF MODULE ------------------------------
</code>
</section>
</chapter>
|