use of org.omg.CosTransactions.Unavailable in project narayana by jbosstm.
the class CurrentImple method begin.
public void begin() throws SubtransactionsUnavailable, SystemException {
ControlWrapper currentAction = _theManager.current();
if (// no current, so create top-level action
currentAction == null) {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("CurrentImple::begin - creating new top-level transaction.");
}
if (OTSImpleManager.localFactory())
currentAction = new ControlWrapper(OTSImpleManager.factory().createLocal(get_timeout()));
else
currentAction = new ControlWrapper(OTSImpleManager.get_factory().create(get_timeout()));
} else {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("CurrentImple::begin - creating new subtransaction.");
}
try {
currentAction = currentAction.create_subtransaction();
} catch (Unavailable ex) {
throw new INVALID_TRANSACTION(ExceptionCodes.UNAVAILABLE_COORDINATOR, CompletionStatus.COMPLETED_NO);
} catch (Inactive e) {
throw new INVALID_TRANSACTION(ExceptionCodes.INACTIVE_TRANSACTION, CompletionStatus.COMPLETED_NO);
} catch (NO_MEMORY nme) {
System.gc();
throw nme;
} catch (SystemException sysEx) {
throw new INVALID_TRANSACTION(ExceptionCodes.INACTIVE_TRANSACTION, CompletionStatus.COMPLETED_NO);
} catch (OutOfMemoryError me) {
System.gc();
throw new NO_MEMORY(0, CompletionStatus.COMPLETED_NO);
}
}
_theManager.pushAction(currentAction);
try {
ThreadAssociationControl.updateAssociation(currentAction, TX_BEGUN);
} catch (Exception e) {
try {
rollback_only();
} catch (Exception ex) {
}
}
currentAction = null;
}
use of org.omg.CosTransactions.Unavailable in project narayana by jbosstm.
the class CurrentImple method rollback.
/**
* If another thread has already terminated the transaction then: (i) if it
* rolled back, we do nothing - could throw TransactionRequired of
* INVALID_TRANSACTION, or NoTransaction. Probably not NoTransaction, since
* it would be better to distinguish between the situation where the
* transaction has already been terminated and there really is no
* transaction for this thread. (ii) if it committed, we throw
* INVALID_TRANSACTION.
*/
public void rollback() throws NoTransaction, SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("CurrentImple::rollback ()");
}
ControlWrapper currentAction = _theManager.current();
if (currentAction != null) {
ThreadAssociationControl.updateAssociation(currentAction, TX_ABORTED);
try {
currentAction.rollback();
_theManager.popAction();
} catch (INVALID_TRANSACTION e1) {
/*
* If transaction has already terminated, then throw
* INVALID_TRANSACTION. Differentiates between this stat and not
* actually having a transaction associated with the thread.
*/
_theManager.popAction();
throw e1;
} catch (SystemException e2) {
_theManager.popAction();
throw e2;
} catch (Unavailable e) {
/*
* If no terminator then not allowed!
*/
_theManager.popAction();
throw new INVALID_TRANSACTION();
}
} else
throw new NoTransaction();
}
use of org.omg.CosTransactions.Unavailable 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.
}
}
use of org.omg.CosTransactions.Unavailable 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.Unavailable 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 != null) && (localData.type().kind().value() != TCKind._tk_null)) {
if ((threadId = localData.extract_string()) == null)
throw new UNKNOWN(jtsLogger.i18NLogger.get_orbspecific_jacorb_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_jacorb_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.
} catch (OBJECT_NOT_EXIST ex) {
}
}
Aggregations