use of org.omg.CosTransactions.HeuristicHazard in project narayana by jbosstm.
the class XAResourceRecord method commit_one_phase.
/**
* For commit_one_phase we can do whatever we want since the transaction
* outcome is whatever we want. Therefore, we do not need to save any
* additional recoverable state, such as a reference to the transaction
* coordinator, since it will not have an intentions list anyway.
*/
public void commit_one_phase() throws HeuristicHazard, org.omg.CORBA.SystemException {
if (jtaxLogger.logger.isTraceEnabled()) {
jtaxLogger.logger.trace("XAResourceRecord.commit_one_phase for " + _tranID);
}
if (_tranID == null) {
jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_nulltransaction("XAResourceRecord.commit_one_phase");
throw new TRANSACTION_ROLLEDBACK();
} else {
if (_theXAResource != null) {
try {
switch(_heuristic) {
case TwoPhaseOutcome.HEURISTIC_HAZARD:
throw new org.omg.CosTransactions.HeuristicHazard();
default:
break;
}
/*
* TODO in Oracle, the end is not required. Is this
* common to other RM implementations?
*/
boolean commit = true;
XAException endRBOnly = null;
try {
endAssociation(XAResource.TMSUCCESS, TxInfo.NOT_ASSOCIATED);
} catch (XAException e1) {
switch(e1.errorCode) {
case XAException.XA_HEURHAZ:
case XAException.XA_HEURMIX:
case XAException.XA_HEURCOM:
case XAException.XA_HEURRB:
throw e1;
case XAException.XA_RBROLLBACK:
case XAException.XA_RBCOMMFAIL:
case XAException.XA_RBDEADLOCK:
case XAException.XA_RBINTEGRITY:
case XAException.XA_RBOTHER:
case XAException.XA_RBPROTO:
case XAException.XA_RBTIMEOUT:
case XAException.XA_RBTRANSIENT:
/*
* Has been marked as rollback-only. We still
* need to call rollback.
*/
endRBOnly = e1;
commit = false;
break;
case XAException.XAER_RMERR:
case XAException.XAER_NOTA:
case XAException.XAER_PROTO:
case XAException.XAER_INVAL:
case XAException.XAER_RMFAIL:
default:
{
throw new UNKNOWN();
}
}
}
if (commit)
_theXAResource.commit(_tranID, true);
else {
_theXAResource.rollback(_tranID);
throw endRBOnly;
}
} catch (XAException e1) {
if ((e1.errorCode >= XAException.XA_RBBASE) && (e1.errorCode <= XAException.XA_RBEND)) {
throw new TRANSACTION_ROLLEDBACK();
}
switch(e1.errorCode) {
case XAException.XA_HEURHAZ:
case XAException.XA_HEURMIX:
updateState(TwoPhaseOutcome.HEURISTIC_HAZARD);
throw new org.omg.CosTransactions.HeuristicHazard();
case XAException.XA_HEURCOM:
try {
handleForget();
} catch (SystemException ignore) {
}
break;
case XAException.XA_HEURRB:
try {
handleForget();
} catch (SystemException ignore) {
}
throw new TRANSACTION_ROLLEDBACK();
case XAException.XA_RBROLLBACK:
case XAException.XA_RBCOMMFAIL:
case XAException.XA_RBDEADLOCK:
case XAException.XA_RBINTEGRITY:
case XAException.XA_RBOTHER:
case XAException.XA_RBPROTO:
case XAException.XA_RBTIMEOUT:
case XAException.XA_RBTRANSIENT:
case XAException.XAER_RMERR:
throw new TRANSACTION_ROLLEDBACK();
case XAException.XAER_NOTA:
// RM unexpectedly lost track of the tx, outcome is uncertain
updateState(TwoPhaseOutcome.HEURISTIC_HAZARD);
throw new org.omg.CosTransactions.HeuristicHazard();
case XAException.XAER_PROTO:
case // not allowed to be thrown here by XA specification!
XAException.XA_RETRY:
// presumed abort (or we could be really paranoid and throw a heuristic)
throw new TRANSACTION_ROLLEDBACK();
case // resource manager failed, did it rollback?
XAException.XAER_INVAL:
throw new org.omg.CosTransactions.HeuristicHazard();
case // This was modified as part of JBTM-XYZ - although RMFAIL is not clear there is a rollback/commit we are flagging this to the user
XAException.XAER_RMFAIL:
throw new org.omg.CosTransactions.HeuristicHazard();
default:
// will cause log to be rewritten
_committed = true;
throw new UNKNOWN();
}
} catch (SystemException ex) {
jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_cant_commit_onephase(_tranID, ex.getClass(), ex);
throw ex;
} catch (org.omg.CosTransactions.HeuristicHazard ex) {
jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_cant_commit_onephase(_tranID, ex.getClass(), ex);
throw ex;
} catch (Exception e2) {
jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_coperror(e2);
throw new UNKNOWN();
} finally {
removeConnection();
}
} else
throw new TRANSACTION_ROLLEDBACK();
}
}
use of org.omg.CosTransactions.HeuristicHazard in project narayana by jbosstm.
the class AtomicTransaction method end.
/*
* public synchronized void begin () throws SubtransactionsUnavailable,
* SystemException { if (jtaxLogger.loggerI18N.isWarnEnabled()) {
* jtaxLogger.loggerI18N.warn("com.arjuna.ats.internal.jta.transaction.jts.atomictxnobegin"); }
*
* throw new INVALID_TRANSACTION(ExceptionCodes.ALREADY_BEGUN,
* CompletionStatus.COMPLETED_NO); }
*/
/**
* Does not change thread-to-tx association as base class commit does.
*/
public synchronized void end(boolean report_heuristics) throws NoTransaction, HeuristicMixed, HeuristicHazard, WrongTransaction, SystemException {
if (jtaxLogger.logger.isTraceEnabled()) {
jtaxLogger.logger.trace("AtomicTransaction::end ( " + report_heuristics + " ) for " + _theAction);
}
if (_theAction == null) {
throw new NoTransaction();
}
try {
_theAction.commit(report_heuristics);
_theStatus = Status.StatusCommitted;
} catch (Unavailable e) {
_theStatus = Status.StatusNoTransaction;
throw new NoTransaction();
} catch (HeuristicMixed e) {
_theStatus = getStatus();
throw e;
} catch (HeuristicHazard e) {
_theStatus = getStatus();
throw e;
} catch (TRANSACTION_ROLLEDBACK e) {
_theStatus = Status.StatusRolledBack;
throw e;
} catch (SystemException e) {
_theStatus = getStatus();
throw e;
} finally {
// now remove it from the reaper
TransactionReaper.transactionReaper().remove(_theAction);
}
}
use of org.omg.CosTransactions.HeuristicHazard in project narayana by jbosstm.
the class HeuristicTest method test.
@Test
public void test() throws Exception {
boolean shouldCommit = true;
boolean heuristicPrepare = false;
Coordinator coord = null;
ORB myORB = null;
RootOA myOA = null;
heuristic hImpl = null;
try {
myORB = ORB.getInstance("test");
myOA = OA.getRootOA(myORB);
myORB.initORB(new String[] {}, null);
myOA.initOA();
ORBManager.setORB(myORB);
ORBManager.setPOA(myOA);
Current current = OTSManager.get_current();
hImpl = new heuristic(heuristicPrepare);
Resource heuristicObject = hImpl.getReference();
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.");
try {
coord.register_resource(heuristicObject);
coord.register_resource(atomicObject);
} catch (Exception ex) {
fail("Failed to register resources: " + ex);
ex.printStackTrace(System.err);
}
System.out.println("committing top-level transaction.");
current.commit(true);
} 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) {
fail("Caught unexpected exception: " + e4);
e4.printStackTrace(System.err);
}
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 {
fail("\nCould not determine action status.");
}
} catch (SystemException ex1) {
// assume invalid reference - tx may have been garbage collected
} catch (Exception e5) {
fail("Caught unexpected exception:" + e5);
e5.printStackTrace(System.err);
}
System.out.println("\nFinal action status: " + Utility.stringStatus(status));
System.out.println("Test completed successfully.");
ResourceTrace trace = hImpl.getTrace();
if ((!heuristicPrepare) && (shouldCommit) && (trace.getTrace() == ResourceTrace.ResourceTracePrepareCommitHeurisiticRollbackForget)) {
// assertSuccess();
} else {
if ((!heuristicPrepare) && (!shouldCommit) && (trace.getTrace() == ResourceTrace.ResourceTracePrepareRollback)) {
// assertSuccess();
} else {
if ((heuristicPrepare) && (shouldCommit) && (trace.getTrace() == ResourceTrace.ResourceTracePrepareHeuristicHazardForget)) {
// assertSuccess();
} else {
fail();
}
}
}
myOA.destroy();
myORB.shutdown();
}
use of org.omg.CosTransactions.HeuristicHazard in project narayana by jbosstm.
the class AtomicTransaction method commit.
/*
* Commit the transaction. If the current transaction associated with the
* thread is not this transaction, then this transaction is rolled back and
* leave current alone.
*
* @param report_heuristics indicates whether heuristic reporting is
* desired.
*
* @exception org.omg.CosTransactions.NoTransaction if the transaction has
* already been terminated.
*
* @exception org.omg.CORBA.TRANSACTION_ROLLEDBACK if the transaction rolls
* back.
*
* @exception org.omg.CosTransactions.HeuristicMixed if some of the
* transaction participants committed, while some rolled back.
*
* @exception org.omg.CosTransactions.HeuristicHazard if some of the
* transaction participants committed, some rolled back, and the outcome of
* others is indeterminate.
*
* @exception org.omg.CORBA.WRONG_TRANSACTION if the current transaction is
* not this transaction.
*/
public void commit(boolean report_heuristics) throws NoTransaction, HeuristicMixed, HeuristicHazard, WrongTransaction, SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("AtomicTransaction::commit ( " + report_heuristics + " ) for " + _theAction);
}
synchronized (_theStatus) {
if (_theAction == null) {
throw new NoTransaction();
}
}
if (!validTransaction()) {
throw new WrongTransaction();
}
/*
* OK to use current since we have just guaranteed that the transaction
* is the same as current. Use current rather than saved control since
* it will do thread tracking for us.
*/
CurrentImple current = OTSImpleManager.current();
try {
current.commit(report_heuristics);
_theStatus = Status.StatusCommitted;
} catch (NoTransaction e) {
_theStatus = Status.StatusNoTransaction;
throw e;
} catch (HeuristicMixed e) {
_theStatus = getStatus();
throw e;
} catch (HeuristicHazard e) {
_theStatus = getStatus();
throw e;
} catch (TRANSACTION_ROLLEDBACK e) {
_theStatus = Status.StatusRolledBack;
throw e;
} catch (SystemException e) {
_theStatus = getStatus();
throw e;
}
}
use of org.omg.CosTransactions.HeuristicHazard in project narayana by jbosstm.
the class tx method tx_commit.
public static final synchronized int tx_commit() {
int toReturn = tx.TX_OK;
CurrentImple current = OTSImpleManager.current();
Boolean report_heuristics = (Boolean) __tx_report_heuristics.get(Thread.currentThread());
if (report_heuristics == null)
// default TRUE
report_heuristics = new Boolean(true);
try {
boolean when_return = report_heuristics.booleanValue();
current.commit(when_return);
} catch (NoTransaction e1) {
toReturn = tx.TX_NO_BEGIN;
} catch (HeuristicMixed e2) {
toReturn = tx.TX_HAZARD;
} catch (HeuristicHazard e3) {
toReturn = tx.TX_HAZARD;
} catch (TRANSACTION_ROLLEDBACK e4) {
toReturn = tx.TX_ROLLBACK;
} catch (Exception e5) {
toReturn = tx.TX_FAIL;
}
return toReturn;
}
Aggregations