1 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 68 public class ONTCompletionSS implements SignalSet { 69 70 private static Logger log = Logger.getLogger(ONTCompletionSS.class); 71 72 74 public static final String COMPLETION_SS_NAME = "javax.activity.opennested.ONT"; 75 76 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 87 91 public ONTCompletionSS() { 92 started = false; 93 finished = false; 94 } 95 96 98 100 104 public String getSignalSetName() { 105 return COMPLETION_SS_NAME; 106 } 107 108 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 ) 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 ) 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 ) null); 149 } 150 } 152 return signal; 153 } 154 155 169 public CoordinationInformation setResponse(Outcome response) 170 throws SignalSetInactiveException { 171 172 if (!started) 173 throw new SignalSetInactiveException(); 174 175 CoordinationInformation coordInfo = null; 176 String 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 ) 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 ) null); 189 coordInfo = new CoordinationInformation(false, false); 190 } else 191 finished=true; 192 193 return coordInfo; 194 } 195 196 200 public Outcome getOutcome() throws SignalSetActiveException { 201 if ((started) && (!finished)) 202 throw new SignalSetActiveException(); 203 return outcome; 204 } 205 206 210 public void setCompletionStatus(int completionStatus, int status) { 211 this.completionStatus = completionStatus; 212 this.status = status; 213 } 214 215 219 public int getCompletionStatus() throws SignalSetActiveException { 220 if (!started) 221 throw new SignalSetActiveException(); 222 return completionStatus; 223 } 224 225 228 public void setActivityCoordinator(ActivityCoordinator coord) 229 throws SignalSetActiveException { 230 if (started) 231 throw new SignalSetActiveException(); 232 ac = coord; 233 } 234 235 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 |