use of org.omg.CosTransactions.PropagationContext in project narayana by jbosstm.
the class InterpositionClientRequestInterceptorImpl method send_request.
public void send_request(ClientRequestInfo request_info) throws SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
trace_request("send_request", request_info);
}
if (systemCall(request_info))
return;
final boolean otsAlwaysPropagate = InterceptorInfo.getAlwaysPropagate();
try {
if (!otsAlwaysPropagate) {
TransactionalObject ptr = TransactionalObjectHelper.narrow(request_info.target());
if (ptr == null)
throw new BAD_PARAM();
} else {
/**
* If the value is not null then we are currently in use *
*/
if (_inUse.get() != null) {
return;
} else {
_inUse.set(_inUse);
}
}
try {
/*
* We get back an Any, which contains a key which we must
* now use to get the actual transaction context. This saves
* use having to pack and unpack the context every time it
* changes, even if we don't then make a remote invocation.
*/
Any localData = request_info.get_slot(_localSlot);
String threadId = null;
boolean problem = false;
Any data = null;
if (localData.type().kind().value() != TCKind._tk_null) {
if ((threadId = localData.extract_string()) == null)
throw new UNKNOWN(jtsLogger.i18NLogger.get_orbspecific_javaidl_interceptors_interposition_invalidparam());
} else
threadId = ThreadUtil.getThreadId();
if (threadId != null) {
ControlWrapper theControl = OTSImpleManager.current().contextManager().current(threadId);
if (theControl != null) {
try {
Coordinator theCoordinator = theControl.get_coordinator();
PropagationContext ctx = null;
if (theCoordinator != null) {
ctx = theCoordinator.get_txcontext();
data = packPropagationContext(ctx);
theCoordinator = null;
} else
throw new Unavailable();
} catch (Unavailable ex) {
/*
* We may have to make calls during
* commit (e.g., after_completion)
* which are valid, but which will get
* Unavailable.
*/
problem = true;
}
} else
problem = true;
} else
problem = true;
if (problem) {
if (InterceptorInfo.getNeedTranContext())
throw new TRANSACTION_REQUIRED();
}
if (data != null) {
byte[] octets = _codec.encode_value(data);
ServiceContext service_context = new ServiceContext(OTSManager.serviceId, octets);
request_info.add_request_service_context(service_context, true);
}
} catch (SystemException e) {
throw e;
} catch (Exception ex) {
throw new UNKNOWN(ex.toString());
} finally {
/**
* If we are set to always propagate then ensure we clear the inuse flag *
*/
if (otsAlwaysPropagate) {
_inUse.set(null);
}
}
} catch (BAD_PARAM ex) {
// narrow failed, so not a transactional object.
}
}
use of org.omg.CosTransactions.PropagationContext 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.PropagationContext in project narayana by jbosstm.
the class StrictInterpositionUnitTest method test.
@Test
public void test() throws Exception {
StrictInterpositionCreator creator = new StrictInterpositionCreator();
OTSImpleManager.current().begin();
OTSImpleManager.current().begin();
PropagationContext ctx = OTSImpleManager.current().get_control().get_coordinator().get_txcontext();
assertTrue(creator.recreateLocal(ctx) != null);
assertTrue(creator.recreate(ctx) != null);
OTSImpleManager.current().rollback();
OTSImpleManager.current().rollback();
}
use of org.omg.CosTransactions.PropagationContext in project narayana by jbosstm.
the class ExplicitInterposition method registerTransaction.
/**
* Perform interposition with the specified transaction.
*/
public final synchronized void registerTransaction(Control action) throws InterpositionFailed, SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ExplicitInterposition::registerTransaction ( Control action )");
}
if (_inUse) {
jtsLogger.i18NLogger.warn_excalledagain("ExplicitInterposition.unregisterTransaction");
throw new InterpositionFailed();
}
boolean registerNull = false;
if (action != null) {
try {
Coordinator coord = action.get_coordinator();
if (coord != null) {
PropagationContext ctx = coord.get_txcontext();
if (ctx != null) {
try {
registerTransaction(ctx);
ctx = null;
} catch (Exception e) {
e.printStackTrace();
ctx = null;
throw new InterpositionFailed(e.toString());
}
} else
registerNull = true;
coord = null;
} else
registerNull = true;
} catch (Exception e) {
e.printStackTrace();
throw new InterpositionFailed(e.toString());
}
} else {
_inUse = true;
registerNull = true;
}
if (registerNull) {
try {
OTSImpleManager.current().resume((Control) null);
} catch (Exception e) {
e.printStackTrace();
throw new InterpositionFailed(e.toString());
}
}
}
Aggregations