use of com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction in project narayana by jbosstm.
the class ServerTopLevelAction method prepare.
/*
* Will only be called by the remote top-level transaction.
*/
public org.omg.CosTransactions.Vote prepare() throws HeuristicMixed, HeuristicHazard, SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ServerTopLevelAction::prepare for " + _theUid);
}
if (_theControl == null) {
throw new INVALID_TRANSACTION(ExceptionCodes.SERVERAA_NO_CONTROL, CompletionStatus.COMPLETED_NO);
}
if (_theControl.isWrapper()) {
// won't necessarily get another invocation!
destroyResource();
return Vote.VoteReadOnly;
}
ServerTransaction theTransaction = (ServerTransaction) _theControl.getImplHandle();
// ThreadActionData.pushAction(theTransaction); // LockManager needs to know if there is a transaction
int result = TwoPhaseOutcome.PREPARE_NOTOK;
/*
* Transaction may have locally timed out and been rolled back.
*/
int s = theTransaction.status();
if ((s == ActionStatus.RUNNING) || (s == ActionStatus.ABORT_ONLY))
result = theTransaction.doPrepare();
else {
switch(s) {
case ActionStatus.COMMITTING:
case ActionStatus.COMMITTED:
case ActionStatus.H_COMMIT:
result = TwoPhaseOutcome.PREPARE_OK;
break;
case ActionStatus.H_MIXED:
result = TwoPhaseOutcome.HEURISTIC_MIXED;
break;
case ActionStatus.H_HAZARD:
result = TwoPhaseOutcome.HEURISTIC_HAZARD;
break;
}
}
ThreadActionData.popAction();
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ServerTopLevelAction::prepare for " + _theUid + " : " + TwoPhaseOutcome.stringForm(result));
}
if (result == TwoPhaseOutcome.PREPARE_NOTOK) {
try {
rollback();
} catch (HeuristicCommit ex1) {
result = TwoPhaseOutcome.HEURISTIC_COMMIT;
} catch (HeuristicMixed ex2) {
result = TwoPhaseOutcome.HEURISTIC_MIXED;
} catch (HeuristicHazard ex3) {
result = TwoPhaseOutcome.HEURISTIC_HAZARD;
} catch (SystemException ex4) {
result = TwoPhaseOutcome.HEURISTIC_HAZARD;
}
}
switch(result) {
case TwoPhaseOutcome.INVALID_TRANSACTION:
throw new INVALID_TRANSACTION(ExceptionCodes.INVALID_ACTION, CompletionStatus.COMPLETED_NO);
case TwoPhaseOutcome.PREPARE_OK:
return Vote.VoteCommit;
case TwoPhaseOutcome.PREPARE_NOTOK:
// won't necessarily get another invocation!
destroyResource();
return Vote.VoteRollback;
case TwoPhaseOutcome.PREPARE_READONLY:
// won't necessarily get another invocation!
destroyResource();
return Vote.VoteReadOnly;
case TwoPhaseOutcome.HEURISTIC_MIXED:
if (TxControl.getMaintainHeuristics())
destroyResource();
// will eventually get forget
throw new HeuristicMixed();
case TwoPhaseOutcome.HEURISTIC_HAZARD:
default:
if (TxControl.getMaintainHeuristics())
destroyResource();
throw new HeuristicHazard();
}
}
use of com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction in project narayana by jbosstm.
the class ServerTopLevelAction method rollback.
public void rollback() throws HeuristicCommit, HeuristicMixed, HeuristicHazard, SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ServerTopLevelAction::rollback for " + _theUid);
}
if (_theControl == null) {
throw new INVALID_TRANSACTION(ExceptionCodes.SERVERAA_NO_CONTROL, CompletionStatus.COMPLETED_NO);
}
if (_theControl.isWrapper()) {
destroyResource();
return;
}
ServerTransaction theTransaction = (ServerTransaction) _theControl.getImplHandle();
// LockManager needs to know if there is a transaction
ThreadActionData.pushAction(theTransaction);
int actionStatus = theTransaction.status();
if (actionStatus == ActionStatus.PREPARED) {
/*
* This will also call any after_completions on
* registered synchronizations.
*/
actionStatus = theTransaction.doPhase2Abort();
} else {
if ((actionStatus == ActionStatus.RUNNING) || (actionStatus == ActionStatus.ABORT_ONLY)) {
try {
if (!valid())
// must rollback
theTransaction.doPhase2Abort();
else
theTransaction.rollback();
actionStatus = ActionStatus.ABORTED;
} catch (SystemException ex) {
actionStatus = ActionStatus.ABORTED;
throw ex;
} finally {
destroyResource();
}
}
}
ThreadActionData.popAction();
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ServerTopLevelAction::rollback for " + _theUid + " : " + ActionStatus.stringForm(actionStatus));
}
switch(actionStatus) {
case ActionStatus.PREPARED:
throw new INVALID_TRANSACTION(ExceptionCodes.INVALID_ACTION, CompletionStatus.COMPLETED_NO);
case ActionStatus.ABORTED:
case ActionStatus.H_ROLLBACK:
destroyResource();
break;
case ActionStatus.COMMITTED:
case ActionStatus.H_COMMIT:
destroyResource();
throw new HeuristicCommit();
case ActionStatus.H_MIXED:
if (TxControl.getMaintainHeuristics())
destroyResource();
throw new HeuristicMixed();
case ActionStatus.H_HAZARD:
if (TxControl.getMaintainHeuristics())
destroyResource();
throw new HeuristicHazard();
default:
destroyResource();
break;
}
}
use of com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction in project narayana by jbosstm.
the class ServerTopLevelAction method commit.
public void commit() throws NotPrepared, HeuristicRollback, HeuristicMixed, HeuristicHazard, SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ServerTopLevelAction::commit for " + _theUid);
}
if (_theControl == null) {
throw new INVALID_TRANSACTION(ExceptionCodes.SERVERAA_NO_CONTROL, CompletionStatus.COMPLETED_NO);
}
if (_theControl.isWrapper()) {
destroyResource();
return;
}
ServerTransaction theTransaction = (ServerTransaction) _theControl.getImplHandle();
// LockManager needs to know if there is a transaction
ThreadActionData.pushAction(theTransaction);
int actionStatus = theTransaction.status();
boolean notPrepared = false;
if (actionStatus == ActionStatus.PREPARED) {
/*
* This will also call any after_completions on
* registered synchronizations.
*/
actionStatus = theTransaction.doPhase2Commit();
} else {
if (actionStatus == ActionStatus.RUNNING) {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ServerTopLevelAction::commit for " + _theUid + " : NotPrepared");
}
notPrepared = true;
}
}
ThreadActionData.popAction();
if (notPrepared)
throw new NotPrepared();
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ServerTopLevelAction::commit for " + _theUid + " : " + ActionStatus.stringForm(actionStatus));
}
switch(actionStatus) {
case ActionStatus.PREPARED:
throw new INVALID_TRANSACTION(ExceptionCodes.SERVERAA_NO_CONTROL, CompletionStatus.COMPLETED_NO);
case ActionStatus.COMMITTED:
case ActionStatus.H_COMMIT:
destroyResource();
break;
case ActionStatus.ABORTED:
case ActionStatus.H_ROLLBACK:
if (TxControl.getMaintainHeuristics())
destroyResource();
throw new HeuristicRollback();
case ActionStatus.H_MIXED:
if (TxControl.getMaintainHeuristics())
destroyResource();
throw new HeuristicMixed();
case ActionStatus.H_HAZARD:
if (TxControl.getMaintainHeuristics())
destroyResource();
throw new HeuristicHazard();
default:
destroyResource();
break;
}
}
use of com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction in project narayana by jbosstm.
the class GenericRecoveryCreator method create.
/**
* Create a new RecoveryCoordinator for Resource res. The params
* array is used to pass additional data. Currently params[0] is
* the ArjunaTransactionImple ref. When create returns additional data is
* passed back using params. Currently returned params[0] is the
* RecoveryCoordinator Uid.
*/
public RecoveryCoordinator create(Resource res, Object[] params) throws SystemException {
RecoveryCoordinator recoveryCoordinator = null;
if (jtsLogger.logger.isDebugEnabled()) {
jtsLogger.logger.debug("GenericRecoveryCreator.create()");
}
// we dont use the res parameter in this version
if ((params != null) && (params[0] != null)) {
int index = 0;
ArjunaTransactionImple otsTransaction = (ArjunaTransactionImple) params[index++];
// Get the Uid of the top-level transaction. This will be
// the top-level interposed transaction in the case of
// interposition.
BasicAction rootAction = otsTransaction;
while ((rootAction.parent()) != null) rootAction = rootAction.parent();
Uid rootActionUid = rootAction.getSavingUid();
// Uid processUid = Utility.getProcessUid();
Uid processUid = com.arjuna.ats.arjuna.utils.Utility.getProcessUid();
// Create a Uid for the new RecoveryCoordinator
Uid RCUid = new Uid();
// Is this transaction a ServerTransaction?
boolean isServerTransaction = (otsTransaction instanceof ServerTransaction);
// Now ask the orb-specific bit to make the RecoveryCoordinator IOR
// (it may or may not actually make the RC itself)
recoveryCoordinator = _orbSpecificManager.makeRC(RCUid, rootActionUid, processUid, isServerTransaction);
// Tidy up
otsTransaction = null;
rootAction = null;
// Pass the RecoveryCoordinator Uid back
params[0] = RCUid;
} else {
jtsLogger.i18NLogger.warn_recovery_recoverycoordinators_GenericRecoveryCreator_1();
}
return recoveryCoordinator;
}
use of com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction in project narayana by jbosstm.
the class SubordinateAtomicTransaction method doCommit.
/**
* @return ActionStatus
* @throws SystemException
*/
public int doCommit() throws SystemException {
ServerTransaction stx = getTransaction();
int outcome = ActionStatus.INVALID;
try {
if (stx != null)
return stx.doPhase2Commit();
} catch (final Exception ex) {
ex.printStackTrace();
}
return ActionStatus.H_HAZARD;
}
Aggregations