use of org.omg.CosTransactions.PropagationContext in project narayana by jbosstm.
the class RestrictedInterpositionUnitTest method test.
@Test
public void test() throws Exception {
RestrictedInterposition inter = new RestrictedInterposition();
OTSImpleManager.current().begin();
OTSImpleManager.current().begin();
PropagationContext ctx = OTSImpleManager.current().get_control().get_coordinator().get_txcontext();
ControlImple cont = inter.setupHierarchy(ctx);
RestrictedInterpositionCreator creator = new RestrictedInterpositionCreator();
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 ContextManager method addRemoteHierarchy.
/**
* We could maintain a list of suspended action hierarchies and resume
* the right one (and the right place!) given the control. However, this
* can lead to memory leaks, since we never know when to remove this
* hierarchy information. So, for now we simply rely on the propagation
* context.
*/
public final boolean addRemoteHierarchy(Control cont) {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ContextManager::addRemoteHierarchy ()");
}
if (false) {
pushAction(new ControlWrapper(cont));
return true;
} else {
boolean isError = false;
try {
Coordinator coord = cont.get_coordinator();
PropagationContext ctx = coord.get_txcontext();
if (ctx != null) {
/*
* Depth must be non-zero or we wouldn't be here!
*/
int depth = ctx.parents.length;
for (int i = depth - 1; i >= 0; i--) {
/*
* No memory leak as we delete either when suspend
* is called, or the transaction is terminated.
*/
Coordinator tmpCoord = ctx.parents[i].coord;
Terminator tmpTerm = ctx.parents[i].term;
Control theControl = TransactionFactoryImple.createProxy(tmpCoord, tmpTerm);
// takes care of thread/BasicAction for us.
pushAction(new ControlWrapper(theControl));
}
ctx = null;
} else {
/*
* If we can't get a propagation context then we cannot
* create the hierarchy!
*/
isError = true;
}
coord = null;
} catch (Exception e) {
isError = true;
}
return isError;
}
}
use of org.omg.CosTransactions.PropagationContext in project narayana by jbosstm.
the class ArjunaTransactionImple method propagationContext.
/*
* The caller should delete the context.
*
* The propagation context is specified on a per client thread basis.
* Therefore, at the server side we must maintain a hierarchy for each
* thread. However, the server cannot simply tear down this hierarchy
* whenever it receives a completely new one from the same thread, since the
* OTS lets a thread suspend/resume contexts at will. Potential for memory
* leaks in C++ version, but not Java!!
*
* Currently we assume that the hierarchy will be JBoss transactions so we
* can get the parents of transactions. If it is not then we could simply
* just call get_txcontext on the control!
*/
private final PropagationContext propagationContext() throws Unavailable, Inactive, SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple::propagationContext for " + get_uid());
}
String theUid = null;
Control currentControl = controlHandle.getControl();
PropagationContext context = new PropagationContext();
// most transactions will be top-level
int sequenceThreshold = 1;
int sequenceIncrement = 5;
context.parents = null;
context.current = new TransIdentity();
// uughh!!
context.implementation_specific_data = ORBManager.getORB().orb().create_any();
/*
* Some ORBs (e.g., JBroker) don't like to pass round an unused Any,
* i.e., one which has only been created and had nothing put in it! So
* we have to put something in it!!
*/
context.implementation_specific_data.insert_short((short) 0);
try {
context.current.coord = controlHandle.get_coordinator();
// will reset later!
context.timeout = 0;
if (ArjunaTransactionImple._propagateTerminator) {
context.current.term = controlHandle.get_terminator();
} else
context.current.term = null;
} catch (Exception e) {
return null;
}
/*
* We send the Uid hierarchy as the otid_t part of the TransIdentity.
*/
// the sequence should do the memory management for us.
theUid = controlHandle.get_uid().stringForm();
context.current.otid = Utility.uidToOtid(theUid);
context.current.otid.formatID = ArjunaTransactionImple._ipType;
int index = 0;
while (currentControl != null) {
try {
ActionControl control = com.arjuna.ArjunaOTS.ActionControlHelper.narrow(currentControl);
if (control != null) {
/*
* Must be an Arjuna control.
*/
currentControl = control.getParentControl();
if (currentControl != null) {
if (// first time
index == 0) {
// initial
context.parents = new TransIdentity[sequenceThreshold];
for (int ii = 0; ii < sequenceThreshold; ii++) context.parents[ii] = null;
}
context.parents[index] = new TransIdentity();
context.parents[index].coord = currentControl.get_coordinator();
if (ArjunaTransactionImple._propagateTerminator)
context.parents[index].term = currentControl.get_terminator();
else
context.parents[index].term = null;
/*
* Don't bother checking whether narrow works because we
* can't cope with mixed transaction types anyway! If we
* got here then the root transaction must be an Arjuna
* transaction, so the nested transactions *must* also
* be JBoss transactions!
*/
UidCoordinator uidCoord = Helper.getUidCoordinator(context.parents[index].coord);
theUid = uidCoord.uid();
context.parents[index].otid = Utility.uidToOtid(theUid);
context.parents[index].otid.formatID = ArjunaTransactionImple._ipType;
theUid = null;
uidCoord = null;
index++;
if (index >= sequenceThreshold) {
sequenceThreshold = index + sequenceIncrement;
context.parents = resizeHierarchy(context.parents, index + sequenceIncrement);
}
} else {
if (_propagateRemainingTimeout) {
long timeInMills = TransactionReaper.transactionReaper().getRemainingTimeoutMills(control);
context.timeout = (int) (timeInMills / 1000L);
} else {
context.timeout = TransactionReaper.transactionReaper().getTimeout(control);
}
}
control = null;
} else
throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
} catch (SystemException e) {
/*
* Not an Arjuna control!! Should not happen!!
*/
currentControl = null;
} catch (Exception e) {
e.printStackTrace();
currentControl = null;
}
}
try {
context.parents = resizeHierarchy(context.parents, index);
} catch (Exception e) {
jtsLogger.i18NLogger.warn_orbspecific_coordinator_generror("ArjunaTransactionImple.resizeHierarchy", e);
context = null;
}
return context;
}
use of org.omg.CosTransactions.PropagationContext in project narayana by jbosstm.
the class JTSInterpositionSynchronizationTest method test.
@Test
public void test() throws Exception {
InterpositionCreator creator = new InterpositionCreator();
jtaPropertyManager.getJTAEnvironmentBean().setTransactionManagerClassName(com.arjuna.ats.internal.jta.transaction.jts.TransactionManagerImple.class.getName());
jtaPropertyManager.getJTAEnvironmentBean().setUserTransactionClassName(com.arjuna.ats.internal.jta.transaction.jts.UserTransactionImple.class.getName());
jtsPropertyManager.getJTSEnvironmentBean().setSupportInterposedSynchronization(true);
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
tm.setTransactionTimeout(1000000);
tm.begin();
TransactionImple transaction = (TransactionImple) tm.getTransaction();
transaction.enlistResource(new XAResource() {
@Override
public int prepare(Xid arg0) throws XAException {
prepareCalled = true;
beforeCompletionCalledFirst = beforeCompletionCalled;
return 0;
}
@Override
public void commit(Xid arg0, boolean arg1) throws XAException {
}
@Override
public void end(Xid arg0, int arg1) throws XAException {
}
@Override
public void forget(Xid arg0) throws XAException {
}
@Override
public int getTransactionTimeout() throws XAException {
return 0;
}
@Override
public boolean isSameRM(XAResource arg0) throws XAException {
return false;
}
@Override
public Xid[] recover(int arg0) throws XAException {
return null;
}
@Override
public void rollback(Xid arg0) throws XAException {
}
@Override
public boolean setTransactionTimeout(int arg0) throws XAException {
return false;
}
@Override
public void start(Xid arg0, int arg1) throws XAException {
}
});
ControlWrapper controlWrapper = transaction.getControlWrapper();
Uid get_uid = transaction.get_uid();
ControlImple cont = controlWrapper.getImple();
ArjunaTransactionImple tx = cont.getImplHandle();
CurrentImple current = OTSImpleManager.current();
Control get_control = current.get_control();
PropagationContext ctx = cont.get_coordinator().get_txcontext();
ControlImple recreateLocal = creator.recreateLocal(ctx);
assertTrue(recreateLocal != null);
Control recreate = creator.recreate(ctx);
assertTrue(recreate != null);
Object remove = ControlImple.allControls.remove(get_uid);
ServerControl sc = new ServerControl(get_uid, get_control, null, cont.get_coordinator(), cont.get_terminator());
ControlImple.allControls.put(get_uid, remove);
ServerTopLevelAction serverTopLevelAction = new ServerTopLevelAction(sc);
sc.getImplHandle().register_synchronization(new ManagedSynchronizationImple(new Synchronization() {
@Override
public void beforeCompletion() {
beforeCompletionCalled = true;
}
@Override
public void afterCompletion(int status) {
afterCompletionCalled = true;
}
}).getSynchronization());
transaction.commit();
assertTrue(prepareCalled == true);
assertTrue(beforeCompletionCalled);
assertTrue(afterCompletionCalled);
assertTrue(beforeCompletionCalledFirst == jtsPropertyManager.getJTSEnvironmentBean().isSupportInterposedSynchronization());
}
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) {
final Coordinator finalTheCoordinator = theCoordinator;
try {
ctx = doPrivileged(new PrivilegedExceptionAction<PropagationContext>() {
@Override
public PropagationContext run() throws Unavailable {
return finalTheCoordinator.get_txcontext();
}
});
} catch (PrivilegedActionException pex) {
throw pex.getException();
}
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;
try {
final Any finalData = data;
octets = doPrivileged(new PrivilegedExceptionAction<byte[]>() {
@Override
public byte[] run() throws org.omg.CORBA.UserException {
return _codec.encode_value(finalData);
}
});
} catch (PrivilegedActionException pex) {
throw pex.getException();
}
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.
}
}
Aggregations