use of org.omg.CosTransactions.HeuristicHazard in project narayana by jbosstm.
the class ArjunaTransactionImple method commit.
/**
* If the transaction has already been committed (by another thread, for
* example) then we do nothing - could throw TransactionRequired or
* INVALID_TRANSACTION. However, if it was rolledback then we throw
* TRANSACTION_ROLLEDBACK. Seems like an inconsistency.
*
* OTS is vague as to what to do if the transaction has been terminated,
* so we make a sensible choice.
*
* report_heuristics is ignored if we are a subtransaction.
*/
public void commit(boolean report_heuristics) throws HeuristicMixed, HeuristicHazard, SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple::commit for " + get_uid());
}
if (ArjunaTransactionImple._checkedTransactions && !checkAccess()) {
throw new NO_PERMISSION(0, CompletionStatus.COMPLETED_NO);
}
int outcome = super.status();
if ((outcome == ActionStatus.RUNNING) || // have we already been
(outcome == ActionStatus.ABORT_ONLY)) // committed?
{
try {
if (_synchs != null) {
if (outcome == ActionStatus.RUNNING || (outcome == ActionStatus.ABORT_ONLY && TxControl.isBeforeCompletionWhenRollbackOnly())) {
doBeforeCompletion();
}
}
} catch (Exception e) {
/*
* Don't do anything, since we will have marked the transaction
* as rollback only.
*/
}
if (parentTransaction != null) {
parentTransaction.removeChildAction(this);
}
outcome = super.End(report_heuristics);
try {
if (_synchs != null) {
currentStatus = determineStatus(this);
doAfterCompletion(currentStatus);
_synchs = null;
}
} catch (Exception e) {
}
destroyAction();
} else if (outcome == ActionStatus.ABORTED || outcome == ActionStatus.H_ROLLBACK) {
throw new TRANSACTION_ROLLEDBACK(ExceptionCodes.FAILED_TO_COMMIT, CompletionStatus.COMPLETED_NO);
} else {
throw new INVALID_TRANSACTION(0, CompletionStatus.COMPLETED_NO);
}
switch(outcome) {
case ActionStatus.COMMITTED:
case ActionStatus.H_COMMIT:
case // in case asynchronous commit!
ActionStatus.COMMITTING:
return;
case ActionStatus.ABORTED:
// in case of asynchronous abort!
case ActionStatus.ABORTING:
case ActionStatus.H_ROLLBACK:
throw new TRANSACTION_ROLLEDBACK(ExceptionCodes.FAILED_TO_COMMIT, CompletionStatus.COMPLETED_NO);
case ActionStatus.H_MIXED:
if (report_heuristics)
throw new HeuristicMixed();
break;
case ActionStatus.H_HAZARD:
default:
if (report_heuristics)
throw new HeuristicHazard();
break;
}
}
use of org.omg.CosTransactions.HeuristicHazard in project narayana by jbosstm.
the class ServerNestedAction method commit_subtransaction.
public void commit_subtransaction(Coordinator parent) throws SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ServerNestedAction::commit_subtransaction : " + _theUid);
}
if (_theControl == null) {
jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_nullcontrol_1("ServerNestedAction.commit_subtransaction");
throw new INVALID_TRANSACTION(ExceptionCodes.SERVERAA_NO_CONTROL, CompletionStatus.COMPLETED_NO);
}
if (_theControl.isWrapper()) {
destroyResource();
return;
}
ServerTransaction theTransaction = (ServerTransaction) _theControl.getImplHandle();
try {
theTransaction.commit(false);
} catch (TRANSACTION_ROLLEDBACK e1) {
jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e1);
throw e1;
} catch (INVALID_TRANSACTION e5) {
jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e5);
throw e5;
} catch (HeuristicMixed e2) {
jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e2);
throw new BAD_OPERATION(ExceptionCodes.HEURISTIC_COMMIT, CompletionStatus.COMPLETED_MAYBE);
} catch (HeuristicHazard e3) {
jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e3);
throw new BAD_OPERATION(ExceptionCodes.HEURISTIC_COMMIT, CompletionStatus.COMPLETED_MAYBE);
} catch (SystemException e4) {
jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e4);
throw e4;
} catch (Exception e5) {
jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_generror_2("ServerNestedAction.commit_subtransaction", e5);
throw new UNKNOWN(e5.toString());
} finally {
ThreadActionData.popAction();
destroyResource();
}
}
use of org.omg.CosTransactions.HeuristicHazard in project narayana by jbosstm.
the class ServerTopLevelAction method commit_one_phase.
public void commit_one_phase() throws HeuristicHazard, SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ServerTopLevelAction::commit_one_phase 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();
if (theTransaction == null) {
jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_arjuna_notx("ServerTopLevelAction.commit_one_phase");
throw new INVALID_TRANSACTION(ExceptionCodes.NO_TRANSACTION, CompletionStatus.COMPLETED_NO);
}
// LockManager needs to know if there is a transaction
ThreadActionData.pushAction(theTransaction);
try {
/*
* This will commit and do any before/after_completion calls
* on registered synchronizations.
*/
theTransaction.doCommit(true);
} catch (HeuristicHazard e1) {
/*
* Is a heuristic, then don't remove the
* transaction information.
*/
ThreadActionData.popAction();
throw e1;
} catch (TRANSACTION_ROLLEDBACK e4) {
ThreadActionData.popAction();
throw e4;
} catch (INVALID_TRANSACTION e5) {
ThreadActionData.popAction();
throw e5;
} catch (SystemException e6) {
ThreadActionData.popAction();
throw e6;
} catch (Exception e7) {
ThreadActionData.popAction();
throw new UNKNOWN(e7.toString());
} finally {
destroyResource();
}
ThreadActionData.popAction();
destroyResource();
}
use of org.omg.CosTransactions.HeuristicHazard in project narayana by jbosstm.
the class RCTest method test.
@Test
public void test() {
boolean shouldCommit = true;
boolean passed = false;
Coordinator coord = null;
ORB myORB = null;
RootOA myOA = null;
try {
myORB = ORB.getInstance("test");
myOA = OA.getRootOA(myORB);
myORB.initORB(new String[] {}, null);
myOA.initOA();
ORBManager.setORB(myORB);
ORBManager.setPOA(myOA);
CurrentImple current = OTSImpleManager.current();
AtomicResource aImpl = new AtomicResource(shouldCommit);
Resource atomicObject = aImpl.getReference();
System.out.println("beginning top-level transaction.");
current.begin();
Control myControl = current.get_control();
assertNotNull(myControl);
System.out.println("getting coordinator");
coord = myControl.get_coordinator();
myControl = null;
System.out.println("registering resources.");
RecoveryCoordinator rc = null;
try {
rc = coord.register_resource(atomicObject);
} catch (Exception ex) {
fail("Failed to register resources: " + ex);
ex.printStackTrace();
}
if (rc == null)
System.out.println("No recovery coordinator reference.");
else {
Status s = Status.StatusUnknown;
try {
System.out.println("Attempting to use recovery coordinator.");
s = rc.replay_completion(atomicObject);
} catch (NotPrepared e) {
s = Status.StatusActive;
} catch (Exception ex) {
fail("Caught: " + ex);
ex.printStackTrace();
}
System.out.println("Got: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
if (s == Status.StatusActive)
passed = true;
}
System.out.println("committing top-level transaction.");
if (shouldCommit)
current.commit(true);
else
current.rollback();
if (rc == null)
System.out.println("No recovery coordinator reference.");
else {
Status s = Status.StatusUnknown;
try {
System.out.println("Attempting to use recovery coordinator.");
s = rc.replay_completion(atomicObject);
} catch (NotPrepared e) {
s = Status.StatusActive;
} catch (Exception ex) {
fail("Caught: " + ex);
}
System.out.println("Got: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
if (passed && (s == Status.StatusRolledBack))
passed = true;
else
passed = false;
}
} catch (TRANSACTION_ROLLEDBACK e1) {
System.out.println("\nTransaction RolledBack exception");
} catch (HeuristicMixed e2) {
System.out.println("\nTransaction HeuristicMixed exception");
} catch (HeuristicHazard e3) {
System.out.println("\nTransaction HeuristicHazard exception");
} catch (Exception e4) {
System.out.println("Caught unexpected exception: " + e4);
}
System.out.println("Trying to determing final transaction outcome.");
org.omg.CosTransactions.Status status = Status.StatusUnknown;
try {
if (coord != null) {
status = coord.get_status();
coord = null;
} else
System.out.println("\nCould not determine action status.");
} catch (SystemException ex1) {
// assume invalid reference - tx may have been garbage collected
} catch (Exception e5) {
System.out.println("Caught unexpected exception:" + e5);
}
System.out.println("\nFinal action status: " + com.arjuna.ats.jts.utils.Utility.stringStatus(status));
assertTrue(passed);
myOA.destroy();
myORB.shutdown();
}
Aggregations