KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jass > hls > ont > ONTCompletionSS


1 /**
2  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3  -
4  - JASS: Java Advanced tranSaction Support
5  -
6  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7  -
8  - This module was originally developed by
9  -
10  - LSD (Distributed Systems Lab, http://lsd.ls.fi.upm.es/lsd/lsd.htm)
11  - at Universidad Politecnica de Madrid (UPM) as an ObjectWeb Consortium
12  - (http://www.objectweb.org) project.
13  -
14  - This project has been partially funded by the European Commission under
15  - the IST programme of V FP grant IST-2001-37126 and by the Spanish
16  - Ministry of Science & Technology (MCyT) grants TIC2002-10376-E and
17  - TIC2001-1586-C03-02
18  -
19  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20  - The original code and portions created by LSD are
21  - Copyright (c) 2004 LSD (UPM)
22  - All rights reserved.
23  -
24  - Redistribution and use in source and binary forms, with or without
25  - modification, are permitted provided that the following conditions are met:
26  -
27  - -Redistributions of source code must retain the above copyright notice, this
28  - list of conditions and the following disclaimer.
29  -
30  - -Redistributions in binary form must reproduce the above copyright notice,
31  - this list of conditions and the following disclaimer in the documentation
32  - and/or other materials provided with the distribution.
33  -
34  - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
35  - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36  - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37  - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
38  - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
39  - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
40  - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
41  - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
42  - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
43  - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  - POSSIBILITY OF SUCH DAMAGE.
45  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
46  -
47  - Author: Francisco Perez Sorrosal (frperezs)
48  -
49  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50 */

51
52 package org.objectweb.jass.hls.ont;
53
54 import org.jboss.logging.Logger;
55
56 import javax.activity.coordination.SignalSet;
57 import javax.activity.*;
58
59 /**
60  * Implements the ONT completion signal set. It is triggered when a ONT
61  * activity ends. The ONT signal set provides the activity_committed and
62  * activity_rolledback signals, and responds appropriately to the outcomes
63  * that are generated in response to those signals.
64  * @author fran
65  * Date: Feb 12, 2004
66  * org.objectweb.jass.hls.ontONTCompletionSS.java
67  */

68 public class ONTCompletionSS implements SignalSet {
69
70     private static Logger log = Logger.getLogger(ONTCompletionSS.class);
71     
72     // Constants --------------------------------------------------------------
73

74     public static final String JavaDoc COMPLETION_SS_NAME = "javax.activity.opennested.ONT";
75
76     // Attributes -------------------------------------------------------------
77

78     private int completionStatus;
79     private int status;
80     private boolean started;
81     private boolean finished;
82     private ActivityCoordinator ac;
83     private Outcome outcome = null;
84
85     // Constructors ---------------------------------------------------------------
86

87     /**
88      * ONT completion signal set constructor.
89      * @param name signal set name.
90      */

91     public ONTCompletionSS() {
92         started = false;
93         finished = false;
94     }
95
96     // Public ---------------------------------------------------------------------
97

98     // SignalSet implementation -----------------------------------------------
99

100     // OK
101
/**
102      * Returns the name of the target SignalSet.
103      */

104     public String JavaDoc getSignalSetName() {
105         return COMPLETION_SS_NAME;
106     }
107
108     /**
109      * Returns the next signal to be sent to the actions registered for the ONT
110      * completion signal set. If the completion status is success then the
111      * activity_committed signal is returned. In this case, if the completing
112      * activity is nested the parent is attached to the signal. If completion
113      * status is fail, then activity_rollback is returned.
114      */

115     public Signal getSignal() {
116         Signal signal = null;
117         started = true;
118
119         if (!finished) {
120             if (completionStatus == CompletionStatus.CompletionStatusSuccess) {
121
122                 try {
123                     log.debug("Signal: activity_committed with parent");
124                     signal =
125                         new Signal(
126                             "activity_committed",
127                             null,
128                             (java.io.Serializable JavaDoc) ac.getParent());
129
130                 } catch (SystemException e) {
131                     log.debug("Signal: activity_committed without parent");
132                     signal =
133                         new Signal(
134                             "activity_committed",
135                             null,
136                             (java.io.Serializable JavaDoc) null);
137                 }
138
139             } else if (
140                 (completionStatus == CompletionStatus.CompletionStatusFail)
141                     || (completionStatus
142                         == CompletionStatus.CompletionStatusFailOnly)) {
143                 log.debug("Signal: activity_rolledback");
144                 signal =
145                     new Signal(
146                         "activity_rolledback",
147                         null,
148                         (java.io.Serializable JavaDoc) null);
149             }
150             //finished = true;
151
}
152         return signal;
153     }
154     
155     /**
156      * Called by an ActivityCoordinator to notify the target SignalSet of the
157      * Outcome returned by an Action in response to a signal produced
158      * by the ONT signal set. If parent_has_completed is received, the signal
159      * set indicates to the ActivityCoordinator that a subsequent signal
160      * (activity_rolledback signal) shall be distributed. It returns the
161      * parent_has_completed outcome. If parent_add_failed is received, the
162      * signal set indicates to the ActivityCoordinator that a subsequent signal
163      * (activity_rolledback signal) shall be distributed. It returns the
164      * parent_add_failed outcome. If compensate_failed is received, the signal
165      * set indicates to the ActivityCoordinator that the same sinal (remember
166      * it was activity_rolledback) must be sent to any remaining actions, but
167      * no further signals are distributed.
168      */

169     public CoordinationInformation setResponse(Outcome response)
170         throws SignalSetInactiveException {
171
172         if (!started)
173             throw new SignalSetInactiveException();
174
175         CoordinationInformation coordInfo = null;
176         String JavaDoc resName = response.getName();
177         log.debug("Response: " + resName);
178
179         if (resName.equals("parent_has_completed")
180             || resName.equals("parent_has_failed")) {
181             outcome = new Outcome(resName, (java.io.Serializable JavaDoc) null);
182             completionStatus = CompletionStatus.CompletionStatusFail;
183             coordInfo = new CoordinationInformation(true, true);
184         } else if (resName.equals("compensate_failed")) {
185             outcome =
186                 new Outcome(
187                     "heuristic_cannot_compensate",
188                     (java.io.Serializable JavaDoc) null);
189             coordInfo = new CoordinationInformation(false, false);
190         } else
191             finished=true;
192                     
193         return coordInfo;
194     }
195
196     /**
197      * Returns the consolidated outcome of the signal set following the
198      * completion of signaling.
199      */

200     public Outcome getOutcome() throws SignalSetActiveException {
201         if ((started) && (!finished))
202             throw new SignalSetActiveException();
203         return outcome;
204     }
205
206     /**
207      * Set both the completion status and status before any signals are
208      * requested. The signals produced may be influenced by these two statuses.
209      */

210     public void setCompletionStatus(int completionStatus, int status) {
211         this.completionStatus = completionStatus;
212         this.status = status;
213     }
214
215     /**
216      * Returns the completion status for the activity as the SignalSet has
217      * recorded it.
218      */

219     public int getCompletionStatus() throws SignalSetActiveException {
220         if (!started)
221             throw new SignalSetActiveException();
222         return completionStatus;
223     }
224
225     /**
226      * Sets the activity coordinator for this instance.
227      */

228     public void setActivityCoordinator(ActivityCoordinator coord)
229         throws SignalSetActiveException {
230         if (started)
231             throw new SignalSetActiveException();
232         ac = coord;
233     }
234
235     /**
236      * Clears the main attributes.
237      */

238     public void destroy() {
239         log.debug("Destroying SignalSet -> " + COMPLETION_SS_NAME);
240         ac = null;
241         started = false;
242         finished = false;
243     }
244 }
245
Popular Tags