use of com.arjuna.webservices11.wsba.State in project narayana by jbosstm.
the class ParticipantStub method restoreState.
public boolean restoreState(final InputObjectState ios) {
State state;
try {
final String id = ios.unpackString();
final boolean durable = ios.unpackBoolean();
final int stateTag = ios.unpackInt();
switch(stateTag) {
case 0:
state = State.STATE_ACTIVE;
break;
case 1:
state = State.STATE_PREPARING;
break;
case 2:
state = State.STATE_PREPARED_SUCCESS;
break;
case 3:
state = State.STATE_ABORTING;
break;
default:
state = State.STATE_COMMITTING;
break;
}
final String eprValue = ios.unpackString();
// this should successfully reverse the save process
final XMLStreamReader reader = SoapUtils.getXMLStreamReader(new StringReader(eprValue));
StreamHelper.checkNextStartTag(reader, QNAME_TWO_PC_PARTICIPANT);
String eprefText = reader.getElementText();
StreamSource source = new StreamSource(new StringReader(eprefText));
final W3CEndpointReference endpointReference = new W3CEndpointReference(source);
// if we already have a coordinator from a previous recovery scan or because
// we had a heuristic outcoe then reuse it with luck it will have been committed
// or aborted between the last scan and this one
// note that whatever happens it will not have been removed from the table
// because it is marked as recovered
coordinator = (CoordinatorEngine) CoordinatorProcessorImpl.getProcessor().getCoordinator(id);
if (coordinator == null) {
// no entry found so recreate one with the saved state
coordinator = new CoordinatorEngine(id, durable, endpointReference, true, state);
}
return true;
} catch (final Throwable th) {
WSTLogger.i18NLogger.error_wst11_stub_ParticipantStub_2(th);
return false;
}
}
use of com.arjuna.webservices11.wsba.State in project narayana by jbosstm.
the class CoordinatorEngine method rollback.
/**
* Handle the rollback event.
*
* None -> None (invalid state)
* Active -> Aborting (send rollback)
* Preparing -> Aborting (send rollback)
* PreparedSuccess -> Aborting (send rollback)
* Committing -> Committing (invalid state)
* Aborting -> Aborting (do nothing)
*/
public State rollback() {
final State current;
synchronized (this) {
current = state;
if ((current == State.STATE_ACTIVE) || (current == State.STATE_PREPARING) || (current == State.STATE_PREPARED_SUCCESS)) {
changeState(State.STATE_ABORTING);
}
}
if ((current == State.STATE_ACTIVE) || (current == State.STATE_PREPARING) || (current == State.STATE_PREPARED_SUCCESS)) {
sendRollback();
} else if (current == State.STATE_ABORTING) {
forget();
}
waitForState(State.STATE_ABORTING, TransportTimer.getTransportTimeout());
synchronized (this) {
if (state != State.STATE_ABORTING) {
return state;
}
// the participant has not confirmed that it is aborted so it will be written to the
// log in the transaction's heuristic list. it needs to be deactivated here
// so that subsequent ABORTED messages are handled correctly, either by sending
// an UnknownTransaction fault or a rollback depending upon whether it is
// volatile or durable, respectively
forget();
return State.STATE_ABORTING;
}
}
use of com.arjuna.webservices11.wsba.State in project narayana by jbosstm.
the class CoordinatorEngine method commit.
/**
* Handle the commit event.
*
* None -> None (invalid state)
* Active -> Active (invalid state)
* Preparing -> Preparing (invalid state)
* PreparedSuccess -> Committing (send commit)
* Committing -> Committing (resend commit)
* Aborting -> Aborting (invalid state)
*/
public State commit() {
final State current;
synchronized (this) {
current = state;
if (current == State.STATE_PREPARED_SUCCESS) {
changeState(State.STATE_COMMITTING);
}
}
if ((current == State.STATE_PREPARED_SUCCESS) || (current == State.STATE_COMMITTING)) {
sendCommit();
}
waitForState(State.STATE_COMMITTING, TransportTimer.getTransportTimeout());
synchronized (this) {
if (state != State.STATE_COMMITTING) {
if (recovered) {
CoordinatorProcessor.getProcessor().deactivateCoordinator(this);
}
return state;
}
// the participant is still uncommitted so it will be rewritten to the log.
// it remains activated in case a committed message comes in between now and
// the next scan. the recovery code will detect this active participant when
// rescanning the log and use it instead of recreating a new one.
// we need to mark this one as recovered so it does not get deleted until
// the next scan
recovered = true;
return State.STATE_COMMITTING;
}
}
use of com.arjuna.webservices11.wsba.State in project narayana by jbosstm.
the class CoordinatorEngine method prepare.
/**
* Handle the prepare event.
*
* None -> None (invalid state)
* Active -> Preparing (send prepare)
* Preparing -> Preparing (resend prepare)
* PreparedSuccess -> PreparedSuccess (do nothing)
* Committing -> Committing (invalid state)
* Aborting -> Aborting (invalid state)
*/
public State prepare() {
final State current;
synchronized (this) {
current = state;
if (current == State.STATE_ACTIVE) {
changeState(State.STATE_PREPARING);
}
}
if ((current == State.STATE_ACTIVE) || (current == State.STATE_PREPARING)) {
sendPrepare();
}
waitForState(State.STATE_PREPARING, TransportTimer.getTransportTimeout());
synchronized (this) {
if (state != State.STATE_PREPARING) {
return state;
}
if (timerTask != null) {
timerTask.cancel();
timerTask = null;
}
return state;
}
}
use of com.arjuna.webservices11.wsba.State in project narayana by jbosstm.
the class ParticipantCompletionParticipantEngine method completed.
/**
* Handle the completed event.
*
* Active -> Completed
* Canceling -> Canceling (invalid state)
* Completed -> Completed
* Closing -> Closing (invalid state)
* Compensating -> Compensating (invalid state)
* Failing-Active -> Failing-Active (invalid state)
* Failing-Canceling -> Failing-Canceling (invalid state)
* Failing-Compensating -> Failing-Compensating (invalid state)
* NotCompleting -> NotCompleting (invalid state)
* Exiting -> Exiting (invalid state)
* Ended -> Ended (invalid state)
*/
public State completed() {
if (WSTLogger.logger.isTraceEnabled()) {
WSTLogger.logger.trace(getClass().getSimpleName() + ".completed");
}
State current;
boolean failRequired = false;
boolean deleteRequired = false;
boolean confirm = (participant instanceof ConfirmCompletedParticipant);
synchronized (this) {
current = state;
if (current == State.STATE_ACTIVE) {
// ok we need to write the participant details to disk because it has just completed
BAParticipantRecoveryRecord recoveryRecord = new BAParticipantRecoveryRecord(id, participant, true, coordinator);
if (XTSBARecoveryManager.getRecoveryManager().writeParticipantRecoveryRecord(recoveryRecord)) {
changeState(State.STATE_COMPLETED);
persisted = true;
// sent back and we cannot allow that until after the confirm
if (confirm) {
((ConfirmCompletedParticipant) participant).confirmCompleted(true);
}
} else {
// 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;
}
}
}
if (failRequired) {
current = fail(BusinessActivityConstants.WSBA_ELEMENT_FAIL_QNAME);
// we can safely do this now
if (confirm) {
((ConfirmCompletedParticipant) participant).confirmCompleted(false);
}
} else if ((current == State.STATE_ACTIVE) || (current == State.STATE_COMPLETED)) {
sendCompleted();
}
if (WSTLogger.logger.isTraceEnabled()) {
WSTLogger.logger.trace(getClass().getSimpleName() + ".completed. State: " + current);
}
return current;
}
Aggregations