use of com.arjuna.webservices11.wsat.State in project narayana by jbosstm.
the class CoordinatorCompletionParticipantEngine method completed.
/**
* Handle the completed event.
*
* Active -> Active (invalid state)
* Canceling -> Canceling (invalid state)
* Completing -> Completed
* Completed -> Completed
* Closing -> Closing (invalid state)
* Compensating -> Compensating (invalid state)
* Failing-Active -> Failing-Active (invalid state)
* Failing-Canceling -> Failing-Canceling (invalid state)
* Failing-Completing -> Failing-Completing (invalid state)
* Failing-Compensating -> Failing-Compensating (invalid state)
* Exiting -> Exiting (invalid state)
* NotCompleting -> NotCompleting (invalid state)
* Ended -> Ended (invalid state)
*/
public State completed() {
// TODO -- check. not sure this can or should ever be called for a coordinator completion participant
State current;
boolean failRequired = false;
boolean deleteRequired = false;
boolean confirm = (participant instanceof ConfirmCompletedParticipant);
synchronized (this) {
current = state;
}
if (current == State.STATE_COMPLETING) {
// ok we need to write the participant details to disk because it has just completed
BAParticipantRecoveryRecord recoveryRecord = new BAParticipantRecoveryRecord(id, participant, false, coordinator);
if (!XTSBARecoveryManager.getRecoveryManager().writeParticipantRecoveryRecord(recoveryRecord)) {
// hmm, could not write entry log warning
WSTLogger.i18NLogger.warn_wst11_messaging_engines_ParticipantCompletionParticipantEngine_completed_1(id);
// we need to fail this transaction
failRequired = true;
}
}
synchronized (this) {
current = state;
if (current == State.STATE_COMPLETING) {
if (!failRequired) {
changeState(State.STATE_COMPLETED);
// record the fact that we have persisted this object so later operations will delete
// the log record
persisted = true;
// sent back and we cannot allow that until after the confirm
if (confirm) {
((ConfirmCompletedParticipant) participant).confirmCompleted(true);
}
} else {
// we must force a fail but we don't have a log record to delete
changeState(State.STATE_FAILING_COMPLETING);
}
} else {
// we need to delete the log record here as the cancel would not have known it was persisted
deleteRequired = true;
}
}
if (failRequired) {
current = fail(BusinessActivityConstants.WSBA_ELEMENT_FAIL_QNAME);
// we can safely do this now
if (confirm) {
((ConfirmCompletedParticipant) participant).confirmCompleted(false);
}
} else if (deleteRequired) {
if (!XTSBARecoveryManager.getRecoveryManager().deleteParticipantRecoveryRecord(id)) {
// hmm, could not delete entry log warning
WSTLogger.i18NLogger.warn_wst11_messaging_engines_ParticipantCompletionParticipantEngine_completed_2(id);
}
// we can safely do this now
if (confirm) {
((ConfirmCompletedParticipant) participant).confirmCompleted(false);
}
} else if ((current == State.STATE_COMPLETING) || (current == State.STATE_COMPLETED)) {
sendCompleted();
}
return current;
}
use of com.arjuna.webservices11.wsat.State in project narayana by jbosstm.
the class CoordinatorCompletionCoordinatorEngine method fail.
/**
* Handle the fail event.
* @param fail The fail exception.
* @param map The addressing context.
* @param arjunaContext The arjuna context.
*
* Active -> Failing-Active
* Canceling-Active -> Failing-Canceling
* Canceling-Completing -> Failing-Canceling
* Completing -> Failing-Completing
* Completed -> Completed (invalid state)
* Closing -> Closing (invalid state)
* Compensating -> Failing-Compensating
* Failing-Active -> Failing-Active
* Failing-Canceling -> Failing-Canceling
* Failing-Completing -> Failing-Completing
* Failing-Compensating -> Failing-Compensating
* NotCompleting -> NotCompleting (invalid state)
* Exiting -> Exiting (invalid state)
* Ended -> Ended (resend Failed)
*
* In fact we only execute the transition to FAILING_ACTIVE and in this case we send a message to the
* coordinator by calling executeFail. This propagates the failure back thorugh the activityy hierarchy
* to the relevant participant and also marks the acivity as ABORT_ONLY.
*
* In the other failure cases we do not change to a FAILING_XXX state but instead go straight to ENDED
* and save the failing state in a field failureState. In these cases there will be a coordinator
* close/cancel/compensate thread waiting on the change to state FAILING_XXX. The change to FAILING_XXX
* will wake it up and, if the state is still FAILING_XXX, return a fault to the coordinator, However,
* the failing thread also sends a failed response and then call ended. This means the state might be
* transitioned to ENDED before the coordinator thread is scheduled. So, we have to avoid this race by
* going straight to ENDED and saving a failureState which the coordinator thread can check.
*
* The failureState also avoids another race condition for these (non-ACTIVE) cases. It means we don't have
* to send a message to the coordinator to notify the failure. We would need to do this after the state
* change as we need to exclude threads handling resent messages. However, the waiting coordinator thread
* is woken by the state change and so it might complete and remove the activity before the message is sent
* causing a NoSuchActivity exception in this thread. Settign the failureState ensures that the failure is
* detected cleanly by any waiting coordinator thread.
*
* Fortuitously, this also avoids problems during recovery. During recovery we have no link to our
* coordinator available since there is no activity hierarchy in the current context. So, communicating
* failures via the failureState is the only way to ensure that the recovreed coordinator sees a failure.
* There is a further wrinkle here too. If a recovered coordinator times out waiting for a response we need
* to leave the engine in place when we ditch the recovered coordinator and then reestablish a link to it
* next time we recreate the coordinator. We cannot afford to miss a failure during this interval but the]
* engine must transition to ENDED after handling the failure. Saving the failure state ensures that the
* next time the coordinator calls cancel, compensate or close it receives a fault indicating a failure
* rather than just detecting that the pariticpant has ended.
*/
public void fail(final ExceptionType fail, final MAP map, final ArjunaContext arjunaContext) {
final State current;
synchronized (this) {
current = state;
if (current == State.STATE_ACTIVE) {
changeState(State.STATE_FAILING_ACTIVE);
} else if ((current == State.STATE_CANCELING_ACTIVE) || (current == State.STATE_CANCELING_COMPLETING)) {
failureState = State.STATE_FAILING_CANCELING;
ended();
} else if (current == State.STATE_COMPLETING) {
failureState = State.STATE_FAILING_COMPLETING;
ended();
} else if (current == State.STATE_COMPENSATING) {
failureState = State.STATE_FAILING_COMPENSATING;
ended();
}
}
if (current == State.STATE_ACTIVE) {
executeFail(fail.getExceptionIdentifier());
} else if ((current == State.STATE_CANCELING_ACTIVE) || (current == State.STATE_CANCELING_COMPLETING) || (current == State.STATE_COMPLETING) || (current == State.STATE_COMPENSATING) || (current == State.STATE_ENDED)) {
sendFailed();
}
}
use of com.arjuna.webservices11.wsat.State in project narayana by jbosstm.
the class CoordinatorCompletionCoordinatorEngine method compensate.
/**
* Handle the compensate event.
* @return The state.
*
* Active -> Active (invalid state)
* Canceling-Active -> Canceling-Active (invalid state)
* Canceling-Completing -> Canceling-Completing (invalid state)
* Completing -> Completing (invalid state)
* Completed -> Compensating
* Closing -> Closing (invalid state)
* Compensating -> Compensating
* Failing-Active -> Failing-Active (invalid state)
* Failing-Canceling -> Failing-Canceling (invalid state)
* Failing-Completing -> Failing-Completing (invalid state)
* Failing-Compensating -> Failing-Compensating (invalid state)
* NotCompleting -> NotCompleting (invalid state)
* Exiting -> Exiting (invalid state)
* Ended -> Ended (invalid state)
*/
public State compensate() {
State current;
synchronized (this) {
current = state;
if (current == State.STATE_COMPLETED) {
changeState(State.STATE_COMPENSATING);
}
}
if (current == State.STATE_COMPLETED) {
sendCompensate();
waitForState(State.STATE_COMPENSATING, TransportTimer.getTransportTimeout());
}
synchronized (this) {
if (state != State.STATE_COMPENSATING) {
if (recovered) {
CoordinatorCompletionCoordinatorProcessor.getProcessor().deactivateCoordinator(this);
}
if (state == State.STATE_ENDED && failureState != null) {
return failureState;
}
return state;
} else {
// timeout -- leave participant in place as this TX will get retried later
return State.STATE_COMPENSATING;
}
}
}
use of com.arjuna.webservices11.wsat.State in project narayana by jbosstm.
the class CoordinatorCompletionCoordinatorEngine method cancel.
/**
* Handle the cancel event.
* @return The state.
*
* Active -> Canceling-Active
* Canceling-Active -> Canceling-Active
* Canceling-Completing -> Canceling-Completing
* Completing -> Canceling-Completing
* Completed -> Completed (invalid state)
* Closing -> Closing (invalid state)
* Compensating -> Compensating (invalid state)
* Failing-Active -> Failing-Active (invalid state)
* Failing-Canceling -> Failing-Canceling (invalid state)
* Failing-Completing -> Failing-Completing (invalid state)
* Failing-Compensating -> Failing-Compensating (invalid state)
* NotCompleting -> NotCompleting (invalid state)
* Exiting -> Exiting (invalid state)
* Ended -> Ended (invalid state)
*/
public State cancel() {
State current;
synchronized (this) {
current = state;
if (current == State.STATE_ACTIVE) {
changeState(State.STATE_CANCELING_ACTIVE);
} else if (current == State.STATE_COMPLETING) {
changeState(State.STATE_CANCELING_COMPLETING);
}
}
if (current == State.STATE_ACTIVE) {
sendCancel();
current = waitForState(State.STATE_CANCELING_ACTIVE, TransportTimer.getTransportTimeout());
} else if (current == State.STATE_COMPLETING) {
sendCancel();
current = waitForState(State.STATE_CANCELING_COMPLETING, TransportTimer.getTransportTimeout());
}
if (current == State.STATE_ENDED && failureState != null) {
return failureState;
}
return current;
}
use of com.arjuna.webservices11.wsat.State in project narayana by jbosstm.
the class ParticipantCompletionCoordinatorEngine method getStatus.
/**
* Handle the getStatus event.
* @param getStatus The getStatus notification.
* @param map The addressing context.
* @param arjunaContext The arjuna context.
*/
public void getStatus(final NotificationType getStatus, final MAP map, final ArjunaContext arjunaContext) {
if (WSTLogger.logger.isTraceEnabled()) {
WSTLogger.logger.trace(getClass() + ".getStatus");
}
final State current;
synchronized (this) {
current = state;
}
if (WSTLogger.logger.isTraceEnabled()) {
WSTLogger.logger.trace(getClass() + ".getStatus. State: " + current);
}
sendStatus(current);
}
Aggregations