use of com.arjuna.webservices11.wsba.State in project narayana by jbosstm.
the class ParticipantCompletionCoordinatorEngine 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 -> Failing-Canceling
* Completed -> Completed (invalid state)
* Closing -> Closing (invalid state)
* Compensating -> Failing-Compensating
* Failing-Active -> Failing-Active
* Failing-Canceling -> Failing-Canceling
* 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) {
if (WSTLogger.logger.isTraceEnabled()) {
WSTLogger.logger.trace(getClass() + ".fail");
}
final State current;
synchronized (this) {
current = state;
if (current == State.STATE_ACTIVE) {
changeState(State.STATE_FAILING_ACTIVE);
} else if (current == State.STATE_CANCELING) {
failureState = State.STATE_FAILING_CANCELING;
ended();
} else if (current == State.STATE_COMPENSATING) {
failureState = State.STATE_FAILING_COMPENSATING;
ended();
}
}
if (WSTLogger.logger.isTraceEnabled()) {
WSTLogger.logger.trace(getClass() + ".fail. State: " + current);
}
if (current == State.STATE_ACTIVE) {
executeFail(fail.getExceptionIdentifier());
} else if ((current == State.STATE_CANCELING) || (current == State.STATE_COMPENSATING) || (current == State.STATE_ENDED)) {
sendFailed();
}
}
use of com.arjuna.webservices11.wsba.State in project narayana by jbosstm.
the class ParticipantEngine method prepare.
/**
* Handle the prepare event.
* @param prepare The prepare notification.
* @param map The addressing context.
* @param arjunaContext The arjuna context.
*
* None -> None (send aborted)
* Active -> Preparing (execute prepare)
* Preparing -> Preparing (do nothing)
* PreparedSuccess -> PreparedSuccess (resend prepared)
* Committing -> Committing (ignore)
* Aborting -> Aborting (send aborted and forget)
*/
public void prepare(final Notification prepare, final MAP map, final ArjunaContext arjunaContext) {
final State current;
synchronized (this) {
current = state;
if (current == State.STATE_ACTIVE) {
state = State.STATE_PREPARING;
}
}
if (current == State.STATE_ACTIVE) {
executePrepare();
} else if (current == State.STATE_PREPARED_SUCCESS) {
sendPrepared();
} else if ((current == State.STATE_ABORTING) || (current == null)) {
sendAborted();
forget();
}
}
use of com.arjuna.webservices11.wsba.State in project narayana by jbosstm.
the class CoordinatorCompletionParticipantProcessorImpl method getStatus.
/**
* Get Status.
* @param getStatus The get status notification.
* @param map The addressing context.
* @param arjunaContext The arjuna context.
*/
public void getStatus(final NotificationType getStatus, final MAP map, final ArjunaContext arjunaContext) {
final InstanceIdentifier instanceIdentifier = arjunaContext.getInstanceIdentifier();
final CoordinatorCompletionParticipantInboundEvents participant = getParticipant(instanceIdentifier);
if (participant != null) {
try {
participant.getStatus(getStatus, map, arjunaContext);
} catch (final Throwable th) {
if (WSTLogger.logger.isTraceEnabled()) {
WSTLogger.logger.tracev("Unexpected exception thrown from getStatus:", th);
}
}
} else {
if (WSTLogger.logger.isTraceEnabled()) {
WSTLogger.logger.tracev("GetStatus called on unknown participant: {0}", new Object[] { instanceIdentifier });
}
// send an invalid state fault
final String messageId = MessageId.getMessageId();
final MAP faultMAP = AddressingHelper.createFaultContext(map, messageId);
try {
final SoapFault11 soapFault = new SoapFault11(SoapFaultType.FAULT_SENDER, CoordinationConstants.WSCOOR_ERROR_CODE_INVALID_STATE_QNAME, WSTLogger.i18NLogger.get_wst11_messaging_CoordinatorCompletionParticipantProcessorImpl_getStatus_4());
CoordinatorCompletionCoordinatorClient.getClient().sendSoapFault(soapFault, null, faultMAP, getFaultAction());
} catch (final Throwable th) {
WSTLogger.i18NLogger.info_wst11_messaging_CoordinatorCompletionParticipantProcessorImpl_getStatus_3(instanceIdentifier.toString(), th);
}
}
}
use of com.arjuna.webservices11.wsba.State in project narayana by jbosstm.
the class CoordinatorCompletionParticipantEngine method executeCompensate.
/**
* Execute the compensate transition.
*/
private void executeCompensate() {
try {
participant.compensate();
} catch (final FaultedException fe) {
WSTLogger.i18NLogger.warn_messaging_engines_CoordinatorCompletionParticipantEngine_executeCompensate_1(fe);
if (WSTLogger.logger.isTraceEnabled()) {
WSTLogger.logger.tracev(fe, "Faulted exception from participant compensate for WS-BA participant");
}
// fail here because the participant doesn't want to retry the compensate
fail(BusinessActivityConstants.WSBA_ELEMENT_FAIL_QNAME);
} catch (final Throwable th) {
final State current;
synchronized (this) {
current = state;
if (current == State.STATE_COMPENSATING) {
changeState(State.STATE_COMPLETED);
}
}
if (current == State.STATE_COMPENSATING) {
initiateTimer();
}
WSTLogger.i18NLogger.warn_messaging_engines_CoordinatorCompletionParticipantEngine_executeCompensate_2(th);
if (WSTLogger.logger.isTraceEnabled()) {
WSTLogger.logger.tracev(th, "Unexpected exception from participant compensate for WS-BA participant");
}
return;
}
final State current;
boolean failRequired = false;
synchronized (this) {
current = state;
if (current == State.STATE_COMPENSATING) {
if (persisted) {
if (!XTSBARecoveryManager.getRecoveryManager().deleteParticipantRecoveryRecord(id)) {
// we have to fail since we don't want to run the compensate method again
WSTLogger.i18NLogger.warn_wst11_messaging_engines_ParticipantCompletionParticipantEngine_executeCompensate_3(id);
failRequired = true;
changeState(State.STATE_FAILING_COMPENSATING);
}
}
// we will send the compensate after we exit the synchronized block
if (!failRequired) {
ended();
}
}
}
if (failRequired) {
fail(BusinessActivityConstants.WSBA_ELEMENT_FAIL_QNAME);
} else if (current == State.STATE_COMPENSATING) {
sendCompensated();
}
}
use of com.arjuna.webservices11.wsba.State in project narayana by jbosstm.
the class CoordinatorCompletionParticipantEngine 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) {
final State current;
synchronized (this) {
current = state;
}
sendStatus(current);
}
Aggregations