use of org.omg.CosTransactions.HeuristicCommit 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 org.omg.CosTransactions.HeuristicCommit 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;
}
}
Aggregations