use of com.arjuna.ats.internal.jts.orbspecific.CurrentImple in project narayana by jbosstm.
the class AtomicTransaction method validTransaction.
/**
* If this transaction current? Assume we have checked that we are actually
* a transaction!
*
* If not valid then abort this transaction here. Leave current alone.
*/
protected final boolean validTransaction() {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("AtomicTransaction::validTransaction called for " + _theAction);
}
/*
* If we get here then _theAction is not null.
*/
CurrentImple current = OTSImpleManager.current();
boolean valid = false;
try {
ControlWrapper currentTransaction = current.getControlWrapper();
if (currentTransaction == null) {
jtsLogger.i18NLogger.warn_extensions_atnovalidtx("AtomicTransaction.validTransaction");
return false;
}
valid = _theAction.equals(currentTransaction);
if (!valid) {
String transactionName = get_transaction_name();
String currentTransactionName = currentTransaction.get_transaction_name();
jtsLogger.i18NLogger.warn_extensions_atoutofseq("AtomicTransaction", transactionName);
jtsLogger.i18NLogger.warn_extensions_atwillabort(currentTransactionName);
try {
_theAction.rollback();
} catch (Exception ex) {
jtsLogger.i18NLogger.warn_extensions_atcannotabort("AtomicTransaction", transactionName);
}
}
} catch (Exception e) {
jtsLogger.i18NLogger.warn_extensions_atgenerror("AtomicTransaction", e);
}
return valid;
}
use of com.arjuna.ats.internal.jts.orbspecific.CurrentImple 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 com.arjuna.ats.internal.jts.orbspecific.CurrentImple 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 com.arjuna.ats.internal.jts.orbspecific.CurrentImple in project narayana by jbosstm.
the class trangrid_i method set.
public void set(short n, short m, short value) throws SystemException {
CurrentImple current = OTSImpleManager.current();
org.omg.CosTransactions.Control control = current.get_control();
if (control != null) {
System.out.println("trangrid_i.set - found implicit transactional context!");
try {
org.omg.CosTransactions.Coordinator co = control.get_coordinator();
co.register_resource(ref);
} catch (Exception e) {
System.err.println("trangrid_i.set - caught exception: " + e);
}
} else
System.err.println("Error - set has no transaction control, therefore will ignore!");
m_a[n][m] = value;
}
use of com.arjuna.ats.internal.jts.orbspecific.CurrentImple 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");
}
Aggregations