4
%% Copyright Ericsson AB 1999-2010. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
20
-module(etrap_test_server_impl).
22
%%--------------- INCLUDES -----------------------------------
23
-include_lib("orber/include/corba.hrl").
24
-include_lib("orber/include/ifr_types.hrl").
26
-include_lib("cosTransactions/src/ETraP_Common.hrl").
27
-include_lib("cosTransactions/include/CosTransactions.hrl").
28
%%--------------- IMPORTS-------------------------------------
29
%%--------------- EXPORTS-------------------------------------
35
% before_completion/2,
37
commit_subtransaction/3,
38
rollback_subtransaction/2]).
41
%%--------------- gen_server specific ------------------------
42
-export([init/1, terminate/2]).
43
-export([handle_call/3, handle_cast/2, handle_info/2, code_change/3]).
45
%%------------------------------------------------------------
46
%% function : init, terminate
47
%%------------------------------------------------------------
49
process_flag(trap_exit,true),
50
io:format("etrap_test_server:init ~p~n", [State]),
51
?debug_print("STARTING etrap_test_server( ~p )~n", [State]),
54
terminate(Reason, _State) ->
55
io:format("etrap_test_server:terminate ~p~n", [Reason]),
56
?debug_print("STOPREASON etrap_test_server( ~p )~n", [Reason]),
59
code_change(_OldVsn, State, _Extra) ->
61
handle_call(_,_, State) ->
63
handle_cast(_, State) ->
65
handle_info(_Info, State) ->
68
%%-- Inherit from CosTransactions::SubtransactionAwareResource --
69
prepare(_Self, State) ->
70
case ?is_debug_compiled of
72
io:format("etrap_test_server:prepare ~p~n", [State]);
76
% ?debug_print("etrap_test_server:prepare ~p~n", [State]),
77
action(prepare, State, {reply, 'VoteCommit', State}).
79
rollback(_Self, State) ->
80
case ?is_debug_compiled of
82
io:format("etrap_test_server:rollback ~p~n", [State]);
86
% ?debug_print("etrap_test_server:rollback ~p~n", [State]),
87
case sync_test(State) of
89
action(rollback, State, {reply, ok, State});
91
action(rollback, State, {stop, normal, ok, State})
94
commit(_Self, State) ->
95
case ?is_debug_compiled of
97
io:format("etrap_test_server:commit ~p~n", [State]);
101
% ?debug_print("etrap_test_server:commit ~p~n", [State]),
102
case sync_test(State) of
104
action(commit, State, {reply, ok, State});
106
action(commit, State, {stop, normal, ok, State})
109
commit_one_phase(_Self, State) ->
110
case ?is_debug_compiled of
112
io:format("etrap_test_server:commit_one_phase ~p~n", [State]);
116
% ?debug_print("etrap_test_server:commit_one_phase ~p~n", [State]),
117
case sync_test(State) of
121
{stop, normal, ok, State}
124
forget(_Self, State) ->
125
case ?is_debug_compiled of
127
io:format("etrap_test_server:forget ~p~n", [State]);
131
% ?debug_print("etrap_test_server:forget ~p~n", [State]),
132
case sync_test(State) of
136
{stop, normal, ok, State}
139
commit_subtransaction(_Self, State, Parent) ->
140
case ?is_debug_compiled of
142
io:format("etrap_test_server:commit_subtransaction( ~p )~n", [Parent]);
146
% ?debug_print("etrap_test_server:commit_subtransaction( ~p )~n", [Parent]),
148
rollback_subtransaction(_Self, State) ->
149
case ?is_debug_compiled of
151
io:format("etrap_test_server:rollback_subtransaction()~n", []);
155
% ?debug_print("etrap_test_server:rollback_subtransaction()~n", []),
158
%before_completion(_Self, State) ->
159
% case ?is_debug_compiled of
161
% io:format("etrap_test_server:before_completion()~n", []);
165
%% ?debug_print("etrap_test_server:before_completion()~n", []),
166
% {reply, ok, State}.
167
%after_completion(_Self, State, Status) ->
168
% case ?is_debug_compiled of
170
% io:format("etrap_test_server:after_completion( ~p )~n", [Status]);
174
%% ?debug_print("etrap_test_server:after_completion( ~p )~n", [Status]),
175
% {stop, normal, ok, State}.
177
%%--------------- LOCAL FUNCTIONS ----------------------------
178
action(Key, State, Default) ->
179
case catch lists:keysearch(Key, 1, State) of
180
{value,{Key, stop_reply, R}} ->
181
case sync_test(State) of
185
{stop, normal, R, State}
187
{value,{Key, reply, R}} ->
189
{value,{Key, exc, E}} ->
191
{value,{Key, delay, Time}} ->
192
timer:sleep(Time*1000),
194
{value,{Key,Value}} ->
201
case catch lists:keysearch(sync, 1, State) of
202
{value,{sync, true}} ->
209
%%--------------- END OF MODULE ------------------------------