use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class SynchTest method test.
@Test
public void test() {
org.omg.CosTransactions.Status status = Status.StatusUnknown;
tranobject_i localObject = null;
demosync sync = null;
ORB myORB = null;
RootOA myOA = null;
try {
ServerORB orb = new ServerORB();
myORB = orb.getORB();
myOA = orb.getOA();
Control myControl = null;
org.omg.CosTransactions.Current current = OTSManager.get_current();
Coordinator coord = null;
sync = new demosync();
localObject = new tranobject_i();
current.begin();
myControl = current.get_control();
coord = myControl.get_coordinator();
coord.register_resource(localObject.getReference());
coord.register_synchronization(sync.getReference());
try {
current.commit(true);
} catch (TRANSACTION_ROLLEDBACK e1) {
System.out.println("Transaction rolledback");
}
try {
status = coord.get_status();
} catch (SystemException ex) {
// assume reference no longer valid!
status = Status.StatusUnknown;
}
} catch (UserException e1) {
fail("Caught UserException: " + e1);
e1.printStackTrace();
} catch (SystemException e2) {
fail("Caught SystemException: " + e2);
e2.printStackTrace();
}
System.out.print("Final action status: " + com.arjuna.ats.jts.utils.Utility.stringStatus(status));
System.out.println("\nTest completed successfully.");
myOA.shutdownObject(sync);
myOA.shutdownObject(localObject);
myOA.destroy();
myORB.shutdown();
}
use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class FactoryListUnitTest method test.
@SuppressWarnings("static-access")
@Test
public void test() throws Exception {
FactoryList factory = new FactoryList();
factory.removeDefault();
try {
assertNull(factory.recreate(null, FactoryList.DEFAULT_ID));
fail();
} catch (final INVALID_TRANSACTION ex) {
} catch (final Throwable ex) {
fail();
}
FactoryList.remove(Arjuna.restrictedXID());
TransactionFactoryImple imple = new TransactionFactoryImple("test");
ControlImple tx = imple.createLocal(1000);
PropagationContext ctx = tx.get_coordinator().get_txcontext();
Control cont = FactoryList.recreate(ctx, Arjuna.XID());
assertTrue(Utility.getUid(cont).equals(tx.get_uid()));
}
use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class tx method tx_begin.
public static final synchronized int tx_begin() {
int toReturn = tx.TX_OK;
CurrentImple current = OTSImpleManager.current();
if (!__tx_allow_nesting) {
try {
Control control = current.get_control();
if (control != null) {
/*
* Have a transaction already, and not allowed to
* create nested transactions!
*/
toReturn = tx.TX_PROTOCOL_ERROR;
control = null;
}
} catch (Exception e) {
// something went wrong!
toReturn = tx.TX_FAIL;
}
}
if (toReturn == tx.TX_OK) {
try {
current.begin();
} catch (Exception e) {
toReturn = tx.TX_FAIL;
}
}
return toReturn;
}
use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class ExplicitInterposition method unregisterTransaction.
/**
* We need this explicit method because we cannot rely upon the object
* "destructor" being called by the time the method which instantiated the
* interposition class ends!
*/
public synchronized void unregisterTransaction() throws SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ExplicitInterposition::unregisterTransaction ()");
}
if (!_inUse)
throw new INVALID_TRANSACTION(ExceptionCodes.INVALID_ACTION, CompletionStatus.COMPLETED_NO);
else {
try {
Control control = OTSImpleManager.current().suspend();
control = null;
if (_remember && (_oldControl != null)) {
try {
OTSImpleManager.current().resumeWrapper(_oldControl);
_oldControl = null;
} catch (Exception exp) {
throw new UNKNOWN(exp.toString());
}
}
} catch (UNKNOWN exp) {
throw exp;
} catch (SystemException ex) {
_inUse = false;
throw ex;
} catch (Exception e) {
_inUse = false;
throw new UNKNOWN(e.toString());
}
_inUse = false;
}
}
use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class CheckedTransactions 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);
Control tx = null;
System.out.println("Thread " + Thread.currentThread() + " starting transaction.");
OTSImpleManager.current().setCheckedAction(new MyCheckedAction());
OTSImpleManager.current().begin();
tx = OTSImpleManager.current().get_control();
TXThread txThread = new TXThread(tx);
txThread.start();
txThread.join();
System.out.println("Thread " + Thread.currentThread() + " committing transaction.");
OTSImpleManager.current().commit(false);
System.out.println("Transaction committed. Checked transactions enabled.");
} catch (Exception e) {
System.out.println("Caught exception: " + e);
fail("Checked transactions disabled!");
}
myOA.destroy();
myORB.shutdown();
}
Aggregations