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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.2 -->
<HTML>
<HEAD>
<TITLE>Resource Skeletons</TITLE>
<SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
ALINK="#FF0000">
<CENTER>
<A HREF="http://www.erlang.se"><IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif"></A>
</CENTER>
<A NAME="5"><!-- Empty --></A>
<H2>5 Resource Skeletons</H2>
<A NAME="5.1"><!-- Empty --></A>
<H3>5.1 Resource Skeletons</H3>
<P> This chapter provides a skeleton for application Resources. For more information
see the Orber documentation.
<PRE>
%%%-----------------------------------------------------------
%%% 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 failes. 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 ------------------------------
</PRE>
<CENTER>
<HR>
<SMALL>
Copyright © 1991-2004
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>
|