use of org.omg.CosTransactions.NoTransaction 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.NoTransaction in project narayana by jbosstm.
the class AtomicTransaction method rollback.
/*
* Rollback the transaction. If the current transaction associated with the
* thread is not this transaction, then this transaction is rolled back and
* leave current alone.
*
* @exception org.omg.CosTransactions.NoTransaction if the transaction has
* already been terminated.
*
* @exception org.omg.CORBA.WRONG_TRANSACTION if the current transaction is
* not this transaction.
*/
public void rollback() throws NoTransaction, WrongTransaction, SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("AtomicTransaction::rollback 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.rollback();
_theStatus = Status.StatusRolledBack;
} catch (NoTransaction e) {
_theStatus = Status.StatusNoTransaction;
throw e;
} catch (TRANSACTION_ROLLEDBACK e) {
_theStatus = Status.StatusRolledBack;
} catch (SystemException e) {
_theStatus = getStatus();
throw e;
}
}
use of org.omg.CosTransactions.NoTransaction 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;
}
use of org.omg.CosTransactions.NoTransaction in project narayana by jbosstm.
the class TransactionFactoryImple method getChildTransactions.
/**
* @return the list of child transactions.
*/
public org.omg.CosTransactions.otid_t[] getChildTransactions(otid_t parent) throws Inactive, NoTransaction, SystemException {
Uid u = Utility.otidToUid(parent);
org.omg.CosTransactions.otid_t[] ctx = null;
if (u == null)
throw new BAD_PARAM("otid_t " + jtsLogger.i18NLogger.get_orbspecific_otiderror());
else {
BasicAction act = ActionManager.manager().get(u);
if (act == null)
throw new NoTransaction();
else {
if (act.status() == ActionStatus.RUNNING) {
Object[] children = act.childTransactions();
int size = ((children == null) ? 0 : children.length);
if (size > 0) {
ctx = new org.omg.CosTransactions.otid_t[size];
for (int i = 0; i < size; i++) {
ctx[i] = Utility.uidToOtid((Uid) children[i]);
}
}
} else
throw new Inactive();
}
}
return ctx;
}
use of org.omg.CosTransactions.NoTransaction in project narayana by jbosstm.
the class GridTest method test.
@Test
public void test() {
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);
TransactionFactoryImple theOTS = new TransactionFactoryImple();
Control myControl;
grid_i localGrid = new grid_i(100, 100);
int h, w, v;
myControl = theOTS.create(0);
assertNotNull(myControl);
h = localGrid.height();
w = localGrid.width();
localGrid.set(2, 4, 123, myControl);
v = localGrid.get(2, 4, myControl);
// no problem setting and getting the elememt:
System.out.println("grid[2,4] is " + v);
assertEquals(123, v);
Terminator handle = myControl.get_terminator();
try {
if (handle != null) {
handle.commit(false);
} else
System.err.println("Error - no transaction terminator!");
} catch (Exception ex) {
System.out.println("Test error! Caught: " + ex);
}
ORBManager.getPOA().shutdownObject(theOTS);
ORBManager.getPOA().shutdownObject(localGrid);
} catch (UserException e) {
fail("Caught UserException: " + e);
e.printStackTrace();
} catch (SystemException e) {
fail("Caught SystemException: " + e);
e.printStackTrace();
}
System.out.println("\nWill now try different thread terminating transaction.\n");
try {
org.omg.CosTransactions.Current current = OTSManager.get_current();
System.out.println("Starting new transaction.");
current.begin();
Control tc = current.get_control();
if (tc != null) {
System.out.println("Creating new thread.");
TransactionalThread tranThread = new TransactionalThread(tc);
System.out.println("Waiting for thread to terminate transaction.\n");
tranThread.start();
while (!tranThread.finished()) Thread.yield();
System.out.println("\nCreator will now attempt to rollback transaction. Should fail.");
try {
current.rollback();
fail("Error - managed to rollback transaction!");
} catch (NoTransaction e1) {
System.out.println("Correct termination - caught: " + e1);
} catch (INVALID_TRANSACTION e2) {
System.out.println("Correct termination - caught: " + e2);
} catch (Exception e3) {
fail("Wrong termination - caught unexpected exception: " + e3);
e3.printStackTrace();
}
System.out.println("Test completed successfully.");
} else
System.err.println("Error - null transaction control!");
} catch (Exception e) {
System.out.println("Caught unexpected exception: " + e);
}
myOA.destroy();
myORB.shutdown();
}
Aggregations