use of org.omg.CosTransactions.Coordinator in project narayana by jbosstm.
the class TerminationTest method test.
@Test
public void test() {
boolean commit = true;
Control myControl = 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);
TransactionFactoryImple theOTS = new TransactionFactoryImple();
System.out.println("Creating transaction with 2 second timeout.");
myControl = theOTS.create(2);
assertNotNull(myControl);
Terminator handle = myControl.get_terminator();
try {
System.out.println("Sleeping for 5 seconds.");
Thread.sleep(5000);
} catch (Exception e) {
}
if (handle != null) {
System.out.print("Attempting to ");
if (commit)
System.out.println("commit transaction. Should fail!");
else
System.out.println("rollback transaction. Should fail!.");
if (commit)
handle.commit(true);
else
handle.rollback();
assertFalse(commit);
System.out.println("\nNow attempting to destroy transaction. Should fail!");
OTSManager.destroyControl(myControl);
} else
System.err.println("No transaction terminator!");
} catch (UserException e) {
System.err.println("Caught UserException: " + e);
} catch (SystemException e) {
System.err.println("Caught SystemException: " + e);
try {
Coordinator coord = myControl.get_coordinator();
Status s = coord.get_status();
System.err.println("Transaction status: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
coord = null;
} catch (Exception ex) {
}
}
try {
CurrentImple current = OTSImpleManager.current();
FakeCheckedAction act = new FakeCheckedAction();
current.set_timeout(2);
current.setCheckedAction(act);
assertEquals(act, current.getCheckedAction());
System.out.println("\nNow creating current transaction with 2 second timeout.");
current.begin();
myControl = current.get_control();
try {
System.out.println("Sleeping for 5 seconds.");
Thread.sleep(5000);
} catch (Exception e) {
}
System.out.print("Attempting to ");
if (commit)
System.out.println("commit transaction. Should fail!");
else
System.out.println("rollback transaction. Should fail!.");
if (commit)
current.commit(true);
else
current.rollback();
assertFalse(commit);
assertTrue(act.called);
} catch (UserException e) {
System.err.println("Caught UserException: " + e);
System.out.println("Test did not completed successfully.");
} catch (SystemException e) {
System.err.println("Caught SystemException: " + e);
try {
Coordinator coord = myControl.get_coordinator();
Status s = coord.get_status();
System.err.println("Transaction status: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
myControl = null;
coord = null;
} catch (Exception ex) {
}
System.out.println("Test completed successfully.");
}
myOA.destroy();
myORB.shutdown();
}
use of org.omg.CosTransactions.Coordinator in project narayana by jbosstm.
the class DemoSubTranResource method registerResource.
public void registerResource(boolean registerSubtran) throws Unavailable, Inactive, NotSubtransaction, SystemException {
CurrentImple current = OTSImpleManager.current();
Control myControl = current.get_control();
Coordinator coord = myControl.get_coordinator();
if (registerSubtran)
coord.register_subtran_aware(ref);
else
coord.register_resource(ref);
System.out.println("Registered DemoSubTranResource");
}
use of org.omg.CosTransactions.Coordinator in project narayana by jbosstm.
the class setget_i method set.
public void set(short n, Control control) throws SystemException {
System.out.println("setget_i.set " + n);
try {
if (control != null) {
ExplicitInterposition manager = new ExplicitInterposition();
manager.registerTransaction(control);
System.out.println("setget_i.set - managed to set up interposition hierarchy");
CurrentImple current = OTSImpleManager.current();
Control cont = current.get_control();
if (cont == null)
System.err.println("setget_i.set error - current returned no control!");
else {
System.out.println("setget_i.set - current returned a control!");
cont = null;
}
System.out.println("setget_i.set - beginning nested action");
current.begin();
cont = current.get_control();
if (cont != null) {
Coordinator coord = cont.get_coordinator();
System.out.println("setget_i.set - registering self");
coord.register_resource(ref);
coord = null;
cont = null;
} else
System.err.println("setget_i.set - current did not return control after begin!");
value = n;
System.out.println("setget_i.set - committing nested action");
current.commit(true);
manager.unregisterTransaction();
manager = null;
} else
System.err.println("setget_i::set error - no control!");
} catch (InterpositionFailed ex) {
System.err.println("setget_i.set - error in setting up hierarchy");
throw new UNKNOWN();
} catch (Throwable e) {
System.err.println("setget_i::set - caught exception: " + e);
}
System.out.println("setget_i.set - finished");
}
use of org.omg.CosTransactions.Coordinator in project narayana by jbosstm.
the class DemoArjunaResource method registerResource.
public void registerResource(boolean registerSubtran) throws Unavailable, Inactive, NotSubtransaction, SystemException {
CurrentImple current = OTSImpleManager.current();
Control myControl = current.get_control();
Coordinator coord = myControl.get_coordinator();
if (registerSubtran)
coord.register_subtran_aware(ref);
else
coord.register_resource(ref);
System.out.println("Registered DemoArjunaResource");
}
use of org.omg.CosTransactions.Coordinator in project narayana by jbosstm.
the class DemoResource method registerResource.
public void registerResource() throws Unavailable, Inactive, SystemException {
CurrentImple current = OTSImpleManager.current();
Control myControl = current.get_control();
Coordinator coord = myControl.get_coordinator();
coord.register_resource(ref);
if (!printThread)
System.out.println("Registered DemoResource");
}
Aggregations