use of com.arjuna.ats.internal.jts.ControlWrapper in project narayana by jbosstm.
the class ArjunaTransactionImple method doBeforeCompletion.
protected void doBeforeCompletion() throws SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple::doBeforeCompletion for " + get_uid());
}
boolean problem = false;
SystemException exp = null;
/*
* If we have a synchronization list then we must be top-level.
*/
if (_synchs != null) {
boolean doSuspend = false;
ControlWrapper cw = null;
try {
try {
// cw = OTSImpleManager.systemCurrent().getControlWrapper();
cw = OTSImpleManager.current().getControlWrapper();
if ((cw == null) || (!controlHandle.equals(cw.getImple()))) {
// OTSImpleManager.systemCurrent().resumeImple(controlHandle);
OTSImpleManager.current().resumeImple(controlHandle);
doSuspend = true;
}
} catch (Exception ex) {
/*
* It should be OK to continue with the invocations even if
* we couldn't resume, because a Synchronization is only
* supposed to be associated with a single transaction. So,
* it should be able to infer the transaction.
*/
}
/*
* Since Synchronizations may add register other Synchronizations, we can't simply
* iterate the collection. Instead we work from an ordered copy, which we periodically
* check for freshness. The addSynchronization method uses _currentRecord to disallow
* adding records in the part of the array we have already traversed, thus all
* Synchronization will be called and the (jta only) rules on ordering of interposed
* Synchronization will be respected.
*/
int lastIndexProcessed = -1;
SynchronizationRecord[] copiedSynchs = (SynchronizationRecord[]) _synchs.toArray(new SynchronizationRecord[] {});
while ((lastIndexProcessed < _synchs.size() - 1) && !problem) {
// if new Synchronization have been registered, refresh our copy of the collection:
if (copiedSynchs.length != _synchs.size()) {
copiedSynchs = (SynchronizationRecord[]) _synchs.toArray(new SynchronizationRecord[] {});
}
lastIndexProcessed = lastIndexProcessed + 1;
_currentRecord = copiedSynchs[lastIndexProcessed];
Synchronization c = _currentRecord.contents();
c.before_completion();
}
} catch (SystemException e) {
jtsLogger.i18NLogger.warn_orbspecific_coordinator_generror("ArjunaTransactionImple.doBeforeCompletion", e);
if (!problem) {
exp = e;
problem = true;
try {
rollback_only();
} catch (Inactive ex) {
/*
* This should not happen. If it does, continue with
* commit to tidy-up.
*/
jtsLogger.i18NLogger.warn_orbspecific_coordinator_rbofail("ArjunaTransactionImple.doBeforeCompletion", get_uid(), ex);
}
}
} finally {
if (doSuspend) {
try {
if (cw != null)
OTSImpleManager.current().resumeWrapper(cw);
else
OTSImpleManager.current().suspend();
} catch (Exception ex) {
}
// OTSImpleManager.systemCurrent().suspend();
}
}
}
if (!problem)
problem = !super.beforeCompletion();
if (problem) {
if (exp != null)
throw exp;
else
throw new UNKNOWN(ExceptionCodes.SYNCHRONIZATION_EXCEPTION, CompletionStatus.COMPLETED_NO);
}
}
use of com.arjuna.ats.internal.jts.ControlWrapper in project narayana by jbosstm.
the class TransactionFactoryImple method createLocal.
/**
* This creates a local instance of a transaction control, but does not
* register it with the ORB. Either call its getControl method directly, or
* use the create method of the factory.
*/
public ControlImple createLocal(int time_out) throws SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("TransactionFactoryImple::createLocal ( " + time_out + " )");
}
try {
ControlImple tranControl = new ControlImple((Control) null, (ArjunaTransactionImple) null);
int theTimeout = time_out;
if (theTimeout == 0)
theTimeout = TxControl.getDefaultTimeout();
if (theTimeout > 0) {
/*
* Currently we do not remove controls from the list once they
* have terminated. We should to save time and space!
*/
TransactionReaper reaper = TransactionReaper.transactionReaper();
reaper.insert(new ControlWrapper((ControlImple) tranControl), theTimeout);
}
return tranControl;
} catch (OutOfMemoryError e) {
/*
* Rather than try again after running gc simply return and let the
* user deal with it. May help with memory!
*/
System.gc();
throw new NO_MEMORY(0, CompletionStatus.COMPLETED_NO);
}
}
use of com.arjuna.ats.internal.jts.ControlWrapper in project narayana by jbosstm.
the class TransactionManagerImple method resume.
/**
* Unlike the OTS, if we are already associated with a transaction then we
* cannot call resume.
*/
public void resume(Transaction which) throws InvalidTransactionException, java.lang.IllegalStateException, javax.transaction.SystemException {
if (jtaxLogger.logger.isTraceEnabled()) {
jtaxLogger.logger.trace("TransactionManagerImple.resume");
}
super.checkTransactionState();
if ((which == null) || (which instanceof TransactionImple)) {
TransactionImple theTransaction = (TransactionImple) which;
try {
ControlWrapper cont = ((theTransaction == null) ? null : theTransaction.getControlWrapper());
OTSImpleManager.current().resumeWrapper(cont);
cont = null;
theTransaction = null;
} catch (org.omg.CosTransactions.InvalidControl e1) {
InvalidTransactionException invalidTransactionException = new InvalidTransactionException();
invalidTransactionException.initCause(e1);
throw invalidTransactionException;
} catch (org.omg.CORBA.SystemException e2) {
javax.transaction.SystemException systemException = new javax.transaction.SystemException(e2.toString());
systemException.initCause(e2);
throw systemException;
}
} else {
throw new InvalidTransactionException();
}
}
use of com.arjuna.ats.internal.jts.ControlWrapper 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 {
/**
* Set the flag *
*/
_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 != null && (localData.type().kind().value() != TCKind._tk_null)) {
if ((threadId = localData.extract_string()) == null)
throw new UNKNOWN(jtsLogger.i18NLogger.get_orbspecific_jacorb_interceptors_interposition_invalidparam());
} else
threadId = ThreadUtil.getThreadId();
if (threadId != null) {
ControlWrapper theControl = OTSImpleManager.systemCurrent().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) {
ex.printStackTrace();
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.
} catch (OBJECT_NOT_EXIST ex) {
}
}
use of com.arjuna.ats.internal.jts.ControlWrapper in project narayana by jbosstm.
the class ContextClientRequestInterceptorImpl method send_request.
public void send_request(ClientRequestInfo request_info) throws SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ContextClientRequestInterceptorImpl::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;
String stringRef = null;
if (localData.type().kind().value() != TCKind._tk_null) {
if ((threadId = localData.extract_string()) == null)
throw new UNKNOWN(jtsLogger.i18NLogger.get_orbspecific_javaidl_interceptors_context_invalidparam());
} else
threadId = ThreadUtil.getThreadId();
if (threadId != null) {
ControlWrapper theControl = OTSImpleManager.current().contextManager().current(threadId);
if (theControl != null) {
try {
Coordinator theCoordinator = theControl.get_coordinator();
if (theCoordinator != null) {
stringRef = ORBManager.getORB().orb().object_to_string(theCoordinator);
} else {
problem = true;
}
} catch (Unavailable e) {
problem = true;
}
theControl = null;
} else
problem = true;
} else
problem = true;
if (problem) {
if (InterceptorInfo.getNeedTranContext())
throw new TRANSACTION_REQUIRED();
else
stringRef = null;
}
if (stringRef != null) {
Any data = ORBManager.getORB().orb().create_any();
data.insert_string(stringRef);
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) {
jtsLogger.i18NLogger.warn_orbspecific_javaidl_interceptors_context_error(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