Sophie

Sophie

distrib > Fedora > 17 > x86_64 > by-pkgid > 675c8c8167236dfcf8d66da674f931e8 > files > 461

erlang-doc-R15B-03.3.fc17.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:fn="http://www.w3.org/2005/02/xpath-functions">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../../../doc/otp_doc.css" type="text/css">
<title>Erlang -- Resource Skeletons</title>
</head>
<body bgcolor="white" text="#000000" link="#0000ff" vlink="#ff00ff" alink="#ff0000"><div id="container">
<script id="js" type="text/javascript" language="JavaScript" src="../../../../doc/js/flipmenu/flipmenu.js"></script><script id="js2" type="text/javascript" src="../../../../doc/js/erlresolvelinks.js"></script><script language="JavaScript" type="text/javascript">
            <!--
              function getWinHeight() {
                var myHeight = 0;
                if( typeof( window.innerHeight ) == 'number' ) {
                  //Non-IE
                  myHeight = window.innerHeight;
                } else if( document.documentElement && ( document.documentElement.clientWidth ||
                                                         document.documentElement.clientHeight ) ) {
                  //IE 6+ in 'standards compliant mode'
                  myHeight = document.documentElement.clientHeight;
                } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                  //IE 4 compatible
                  myHeight = document.body.clientHeight;
                }
                return myHeight;
              }

              function setscrollpos() {
                var objf=document.getElementById('loadscrollpos');
                 document.getElementById("leftnav").scrollTop = objf.offsetTop - getWinHeight()/2;
              }

              function addEvent(obj, evType, fn){
                if (obj.addEventListener){
                obj.addEventListener(evType, fn, true);
                return true;
              } else if (obj.attachEvent){
                var r = obj.attachEvent("on"+evType, fn);
                return r;
              } else {
                return false;
              }
             }

             addEvent(window, 'load', setscrollpos);

             //--></script><div id="leftnav"><div class="innertube">
<img alt="Erlang logo" src="../../../../doc/erlang-logo.png"><br><small><a href="users_guide.html">User's Guide</a><br><a href="index.html">Reference Manual</a><br><a href="release_notes.html">Release Notes</a><br><a href="../pdf/cosTransactions-1.2.12.pdf">PDF</a><br><a href="../../../../doc/index.html">Top</a></small><p><strong>cosTransactions</strong><br><strong>User's Guide</strong><br><small>Version 1.2.12</small></p>
<br><a href="javascript:openAllFlips()">Expand All</a><br><a href="javascript:closeAllFlips()">Contract All</a><p><small><strong>Chapters</strong></small></p>
<ul class="flipMenu" imagepath="../../../../doc/js/flipmenu">
<li id="no" title="The cosTransactions Application" expanded="false">The cosTransactions Application<ul>
<li><a href="ch_contents.html">
              Top of chapter
            </a></li>
<li title="Content Overview"><a href="ch_contents.html#id61154">Content Overview</a></li>
<li title="Brief Description of the User's Guide"><a href="ch_contents.html#id57422">Brief Description of the User's Guide</a></li>
</ul>
</li>
<li id="no" title="Introduction to cosTransactions" expanded="false">Introduction to cosTransactions<ul>
<li><a href="ch_introduction.html">
              Top of chapter
            </a></li>
<li title="Overview"><a href="ch_introduction.html#id60972">Overview</a></li>
</ul>
</li>
<li id="no" title="Installing cosTransactions" expanded="false">Installing cosTransactions<ul>
<li><a href="ch_install.html">
              Top of chapter
            </a></li>
<li title="Installation Process "><a href="ch_install.html#id61216">Installation Process </a></li>
</ul>
</li>
<li id="no" title="cosTransactions Examples" expanded="false">cosTransactions Examples<ul>
<li><a href="ch_example.html">
              Top of chapter
            </a></li>
<li title="A Tutorial on How to Create a Simple Service"><a href="ch_example.html#id58308">A Tutorial on How to Create a Simple Service</a></li>
</ul>
</li>
<li id="loadscrollpos" title="Resource Skeletons" expanded="true">Resource Skeletons<ul>
<li><a href="ch_skeletons.html">
              Top of chapter
            </a></li>
<li title="Resource Skeletons"><a href="ch_skeletons.html#id56632">Resource Skeletons</a></li>
</ul>
</li>
</ul>
</div></div>
<div id="content">
<div class="innertube">
<h1>5 Resource Skeletons</h1>
  

  <h3><a name="id56632">5.1 
        Resource Skeletons</a></h3>
    
    <p>This chapter provides a skeleton for application Resources. For more information
      see the Orber documentation.</p>
    <div class="example"><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) -&gt;
    %% '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) -&gt;
    ok.

code_change(OldVsn, State, Extra) -&gt;
    {ok, NewState}.

%% If use IC option {{handle_info, "Module::Interface"}, true}
handle_info(Info, State) -&gt;
     %%--- Possible replies ---
     %% Await the next invocation.
     {noreply, State}.
     %% Stop with Reason.
     {stop, Reason, State}.

 
%%- Inherit from CosTransactions::Resource -------------------
prepare(State) -&gt;

    %%% 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) -&gt;

    %%% 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) -&gt;

    %%% 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) -&gt;

    %%% 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) -&gt;

    %%% 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) -&gt;
    %%% Do application specific actions here %%%

    %%-- Reply: --
    {reply, ok, State}.
    %% .. or (for example): 
    {stop, normal, ok, State}.

rollback_subtransaction(State) -&gt;
    %%% Do application specific actions here %%%

    %%-- Reply: --
    {reply, ok, State}.
    %% .. or (for example): 
    {stop, normal, ok, State}.
 
%%--------------- END OF MODULE ------------------------------
    </pre></div>
  
</div>
<div class="footer">
<hr>
<p>Copyright © 1999-2012 Ericsson AB. All Rights Reserved.</p>
</div>
</div>
</div></body>
</html>