_startTime = System.currentTimeMillis();
}
public void run() {
if (_child != null || !_eventHandlers.isEmpty()) {
CompositeProcess mlSet = ProcessUtil.compose(new ReceiveProcess() {
private static final long serialVersionUID = 1913414844895865116L;
}.setChannel(_self.self).setReceiver(new Termination() {
public void terminate() {
_terminated = true;
// Forward the termination request to the nested activity.
if (_child != null && !_childTermRequested) {
replication(_child.self).terminate();
_childTermRequested = true;
}
// Forward the termination request to our event handlers.
terminateEventHandlers();
instance(ACTIVE.this);
}
}));
// Handle messages from the child if it is still alive
if (_child != null) {
mlSet.or(new ReceiveProcess() {
private static final long serialVersionUID = -6934246487304813033L;
}.setChannel(_child.parent).setReceiver(new ParentScope() {
public void compensate(OScope scope, Synch ret) {
// If this scope does not have available compensations, defer to
// parent scope, otherwise do compensation.
if (_scopeFrame.availableCompensations == null)
_self.parent.compensate(scope, ret);
else {
// TODO: Check if we are doing duplicate compensation
List<CompensationHandler> compensations = findCompensationData(scope);
_scopeFrame.availableCompensations.removeAll(compensations);
instance(new ORDEREDCOMPENSATOR(compensations, ret));
}
instance(ACTIVE.this);
}
public void completed(FaultData flt, Set<CompensationHandler> compensations) {
// Set the fault to the activity's choice, if and only if no previous fault
// has been detected (first fault wins).
if (flt != null && _fault == null)
_fault = flt;
_child = null;
_compensations.addAll(compensations);
if (flt == null)
stopEventHandlers();
else
terminateEventHandlers();
instance(ACTIVE.this);
}
public void cancelled() {
// Implicit scope holds links of the enclosed activity,
// they only get cancelled when we propagate upwards.
if (_oscope.implicitScope)
_self.parent.cancelled();
else
completed(null, CompensationHandler.emptySet());
}
public void failure(String reason, Element data) {
completed(createFault(OFailureHandling.FAILURE_FAULT_NAME, _self.o, null),
CompensationHandler.emptySet());
}
}) );
}
// Similarly, handle messages from the event handler, if one exists
// and if it has not completed.
for (Iterator<EventHandlerInfo> i = _eventHandlers.iterator();i.hasNext();) {
final EventHandlerInfo ehi = i.next();
mlSet.or(new ReceiveProcess() {
private static final long serialVersionUID = -4694721357537858221L;
}.setChannel(ehi.psc).setReceiver(new ParentScope() {
public void compensate(OScope scope, Synch ret) {
// ACTIVE scopes do not compensate, send request up to parent.
_self.parent.compensate(scope, ret);