use of org.omg.CORBA.UNKNOWN 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.CORBA.UNKNOWN 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) {
}
}
use of org.omg.CORBA.UNKNOWN in project narayana by jbosstm.
the class ContextServerRequestInterceptorImpl method suspendContext.
/*
* If there is a thread id associated with PICurrent then it will
* have been placed there by a server-side thread which executed in
* the application object and needed to associate an imported
* transaction with itself. In which case we need to do the
* equivalent of a suspend to remove the thread from Current and
* from the current transaction.
*/
private void suspendContext(ServerRequestInfo request_info) throws SystemException, InvalidSlot {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ContextServerRequestInterceptorImpl.suspendContext ( " + request_info.operation() + " )");
}
Any data = request_info.get_slot(_dataSlot);
if ((data != null) && (data.type().kind().value() != TCKind._tk_null)) {
String threadId = null;
try {
if ((threadId = data.extract_string()) != null) {
ControlWrapper ctx = OTSImpleManager.current().contextManager().popAction(threadId);
OTSImpleManager.current().contextManager().purgeActions(threadId);
if (ctx != null) {
try {
OTSManager.destroyControl(ctx.getControl());
ctx = null;
} catch (Exception e) {
jtsLogger.i18NLogger.warn_orbspecific_jacorb_interceptors_context_srie("ContextServerRequestInterceptorImpl.suspendContext", e);
throw new UNKNOWN(e.toString());
}
}
}
} catch (BAD_OPERATION be) {
// not a string, so still a pgctx
}
request_info.set_slot(_dataSlot, null);
}
}
use of org.omg.CORBA.UNKNOWN in project narayana by jbosstm.
the class ExplicitInterposition method unregisterTransaction.
/**
* We need this explicit method because we cannot rely upon the object
* "destructor" being called by the time the method which instantiated the
* interposition class ends!
*/
public synchronized void unregisterTransaction() throws SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ExplicitInterposition::unregisterTransaction ()");
}
if (!_inUse)
throw new INVALID_TRANSACTION(ExceptionCodes.INVALID_ACTION, CompletionStatus.COMPLETED_NO);
else {
try {
Control control = OTSImpleManager.current().suspend();
control = null;
if (_remember && (_oldControl != null)) {
try {
OTSImpleManager.current().resumeWrapper(_oldControl);
_oldControl = null;
} catch (Exception exp) {
throw new UNKNOWN(exp.toString());
}
}
} catch (UNKNOWN exp) {
throw exp;
} catch (SystemException ex) {
_inUse = false;
throw ex;
} catch (Exception e) {
_inUse = false;
throw new UNKNOWN(e.toString());
}
_inUse = false;
}
}
use of org.omg.CORBA.UNKNOWN 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