1 51 52 package org.objectweb.jass.hls.ont; 53 54 import org.jboss.logging.Logger; 55 56 import javax.activity.coordination.Action; 57 import javax.activity.*; 58 import javax.activity.opennested.Compensator; 59 60 68 public class CompensatingAction implements Action { 69 70 72 74 private static Logger log = Logger.getLogger(CompensatingAction.class); 75 76 private Compensator compensator; 77 private int priority; 78 79 81 87 public CompensatingAction(Compensator compensator, int priority) { 88 this.compensator = compensator; 89 this.priority = priority; 90 } 91 92 94 96 113 public Outcome processSignal(Signal signal) throws ActionErrorException { 114 Outcome result = null; 115 116 if (signal.getName().equals("activity_committed")) { 117 ActivityCoordinator parentAC = 118 (ActivityCoordinator) signal.getExtendedValue(); 119 if (parentAC != null) { 120 try { 121 int priority = 122 parentAC.getNumberRegisteredActions(ONTCompletionSS.COMPLETION_SS_NAME); 123 parentAC.addAction( 124 new CompensatingAction(compensator, 0), 125 ONTCompletionSS.COMPLETION_SS_NAME, 126 priority); 127 result = 128 new Outcome( 129 "parent_add_successful", 130 (java.io.Serializable ) null); 131 log.debug("OUTCOME: parent_add_successful"); 132 } catch (IllegalStateException e) { 133 result = 134 new Outcome( 135 "parent_has_completed", 136 (java.io.Serializable ) null); 137 log.debug("OUTCOME: parent_has_completed"); 138 } catch (Exception e) { 139 result = 140 new Outcome("parent_add_failed", (java.io.Serializable ) null); 141 log.debug("OUTCOME: parent_add_failed"); 142 } 143 } else { 144 compensator.forget(); 145 result = 146 new Outcome( 147 "compensate_successful", 148 (java.io.Serializable ) null); 149 log.debug("OUTCOME: compensate_successful (forget)"); 150 } 151 } 152 153 if (signal.getName().equals("activity_rolledback")) { 155 try { 156 compensator.compensate(); 157 result = 158 new Outcome( 159 "compensate_successful", 160 (java.io.Serializable ) null); 161 log.debug("OUTCOME: compensate_successful (compensation)"); 162 } catch (Exception e) { 163 e.printStackTrace(); 164 result = 165 new Outcome("compensate_failed", (java.io.Serializable ) null); 166 log.debug("OUTCOME: compensate_failed"); 167 } 168 } 169 return result; 170 } 171 172 175 public void destroy() { 176 compensator = null; 177 } 178 } 179 | Popular Tags |