CurrentTransactionpublic class CurrentTransaction extends Object This class manages association of transactions with threads in a process,
and associated state/operations. |
Fields Summary |
---|
private static Hashtable | threadContexts | private static Vector | suspended | static boolean | statsOn | private static Hashtable | importedTransactions | private static RegisteredStatics | statics | private static ThreadLocal | m_tid | static Logger | _logger | private static PropagationContext | emptyContext |
Methods Summary |
---|
static void | addSuspended(ControlImpl control)Adds the given Control object to the set of Control objects suspended in
the process.
if(statsOn)
suspended.addElement(control);
| static void | dump()Dumps the static state of the class.
| private static ControlImpl | endAborted()
return (ControlImpl)m_tid.get();
//return endAborted(aborted, false);
| private static ControlImpl | endAborted(boolean[] aborted, boolean endAssociation)Ensures that an association with an aborted transaction is dealt with cleanly.
TN - do not dissociate thread even if it's aborted!!
If the current Control object represents a transaction that has been
aborted, this method replaces the association by one with the first
ancestor that has not been aborted, if any, or no association, and the
method returns true as the output parameter. Otherwise the method returns
false as the output parameter.
If there is a current Control object in either case it is returned,
otherwise null is returned.
// Get the current thread identifier, and the corresponding Control object
// if there is one.
boolean completed = true;
aborted[0] = false;
ControlImpl result = (ControlImpl)m_tid.get();
// If there is a current Control object, and it represents a transaction that
// has been aborted, then we need to end its association with the current
// thread of control.
if( result != null )
try {
completed = (result.getTranState() != Status.StatusActive);
} catch( Throwable exc ) {}
if( result != null && completed ) {
if (endAssociation) {
synchronized(CurrentTransaction.class){
if(statsOn){
Thread thread = Thread.currentThread();
threadContexts.remove(thread);
}
m_tid.set(null);
// XA support: If there was a current IControl, inform all registered
// StaticResource objects of the end of the thread association.
// Allow any exception to percolate to the caller.
if( statics != null )
statics.distributeEnd(result,false);
// Discard all stacked controls that represent aborted or unrecognised
// transactions.
result = result.popAborted();
// If there is a valid ancestor, make it the current one.
if( result != null ) {
m_tid.set(result);
if(statsOn){
Thread thread = Thread.currentThread();
threadContexts.put(thread,result);
suspended.removeElement(result);
}
}
// XA support: If there is a stacked context, inform all registered
// StaticResource objects of the new thread association.
// Allow any exception to percolate to the caller.
if( statics != null )
statics.distributeStart(result,false);
}
}
aborted[0] = true;
}
if(_logger.isLoggable(Level.FINEST))
{
Thread thread = Thread.currentThread();
_logger.logp(Level.FINEST,"CurrentTransaction","endAborted()",
"threadContexts.get(thread) returned " +
result + " for current thread " + thread);
}
return result;
| static synchronized void | endAll(GlobalTID globalTID, boolean aborted)Ends all thread associations for the given transaction.
throw new NO_IMPLEMENT("not implemented");
// Modify any thread associations there may be for the transaction, to
// indicate that the transaction has ended.
/*StatusHolder outStatus = new StatusHolder();
Enumeration controls = threadContexts.elements();
int cz = threadContexts.size(); // Arun 9/27/99
while (cz-- > 0) {
ControlImpl control = (ControlImpl)controls.nextElement();
// If the Control object corresponds to the transaction being removed, then
// inform it that the transaction has completed.
try {
if( globalTID.equals(control.getGlobalTID(outStatus)) &&
outStatus.value == Status.StatusActive )
control.setTranState(aborted ? Status.StatusRolledBack : Status.StatusCommitted);
} catch( Throwable exc ) {
}
}
// Modify any suspended Control objects there may be for the transaction, to
// indicate that the transaction has ended.
controls = suspended.elements();
cz = suspended.size(); // Arun 9/27/99
while(cz-- > 0) {
try {
ControlImpl control = (ControlImpl)controls.nextElement();
// If the Control object corresponds to the transaction being removed, then
// inform it that the transaction has completed.
if( globalTID.equals(control.getGlobalTID(outStatus)) &&
outStatus.value == Status.StatusActive )
control.setTranState(aborted ? Status.StatusRolledBack : Status.StatusCommitted);
} catch( Throwable exc ) {
}
}*/
| static ControlImpl | endCurrent(boolean unstack)Removes the association for the thread under which the operation was
invoked.
The (previously) associated Control object is returned.
If there was no association, the operation returns a NULL reference.
If the stacking flag is set, and there is an associated Control, the stacked
context (if any) becomes the current context when the operation completes.
For XA support, when an association is started or ended, all
registered StaticResource objects are informed of the change.
// Ensure that the current thread association is valid.
//boolean[] outBoolean = new boolean[1];
ControlImpl result = (ControlImpl)m_tid.get();
/*if( outBoolean[0] ) {
}*/
// If there is a current Control, remove its association. If we were asked
// to unstack, get the stacked Control, if any. If there is one, set up the
// thread association.
if( result != null ){
if(statsOn){
Thread thread = Thread.currentThread();
threadContexts.remove(thread);
}
m_tid.set(null);
// Decrement the count of associations for the Control object.
result.decrementAssociation();
// Add the Control to the set of suspended Control objects, if this is
// a suspend and not an end.
if( !unstack && statsOn) suspended.addElement(result);
// XA support: If there was a current Control, inform all registered
// StaticResource objects of the end of the thread association.
// Allow any exception to percolate to the caller.
if( statics != null )
statics.distributeEnd(result,unstack);
// If we were asked to unstack, get the stacked Control, if any. If there
// is one, set up the thread association.
// Now that we have identified the first active ancestor, proceed to unstack
// its parent.
if( unstack ) {
StatusHolder outStatus = new StatusHolder();
ControlImpl stacked = result.popControl(outStatus);
if( stacked != null &&
outStatus.value == Status.StatusActive ) {
// XA support: If there is a stacked context, inform all registered
// StaticResource objects of the new thread association.
// Allow any exception to percolate to the caller.
// This is done first so that if there is an error, we don't leave the
// transaction associated.
if( statics != null )
statics.distributeStart(stacked,false);
// The stacked Control is no longer suspended so is removed from the
// set of suspended transactions.
if(statsOn){
Thread thread = Thread.currentThread();
threadContexts.put(thread,stacked);
suspended.removeElement(stacked);
}
m_tid.set(stacked);
}
}
}
// If there is no current Control, just return NULL.
else
result = null;
return result;
| static Control[] | getAllTransactions()Returns all the transactions in the system that are currently running
or suspended in the form of a sequence of Control objects.
if(!statsOn){
throw new NO_IMPLEMENT("statistics not on");
}
Control[] result = null;
int allNum = threadContexts != null ? threadContexts.size()+suspended.size() : 0;
if( allNum > 0 ) {
result = new Control[allNum];
// Copy the contents of the suspended set into the array.
Enumeration controls = suspended.elements();
int pos = 0;
while( controls.hasMoreElements() )
result[pos++] = ((ControlImpl)controls.nextElement()).object();
// Copy the Control objects which have thread associations into the result.
controls = threadContexts.elements();
while( controls.hasMoreElements() )
result[pos++] = ((ControlImpl)controls.nextElement()).object();
}
else
result = new Control[0];
return result;
| public static ControlImpl | getCurrent()Returns the current Control object.
That is, the Control object that corresponds to the thread
under which the operation was invoked. If there is no such association the
null value is returned.
//boolean[] outBoolean = new boolean[1];
ControlImpl result = (ControlImpl)m_tid.get();
return result;
| static Coordinator | getCurrentCoordinator()Returns a reference to the current Coordinator.
That is, the Coordinator object that corresponds to the
thread under which the operation was invoked.
If there is no such association the null value is returned.
Note that this operation can be optimised so that the Coordinator reference is
stored along with the Control reference when the thread association is set up.
/* This method has been rewritten (Ram J)
* in order to enable current.get_status() to be called
* on a completed transaction, and get the completed status.
* Previously, the first call to get_status() will return
* the right completion status, and the second call to get_status
* would return StatusNoTransaction, since the first call would end
* the thread - tx association.
*/
// Get the current thread identifier, and the corresponding
// Control object if there is one.
ControlImpl control = (ControlImpl)m_tid.get();
Coordinator result = null;
if (control != null) {
if( Configuration.isLocalFactory()) {
result = (Coordinator) ((ControlImpl) control).get_localCoordinator();
} else {
// this call may throw TRANSACTION_ROLLEDBACK
// or INVALID_TRANSACTION
result = control.get_coordinator();
}
}
return result;
| static Control[] | getRunningTransactions()Returns all the transactions in the system that are currently running
(i.e. not suspended) in the form of a sequence of Control objects.
if(!statsOn){
throw new NO_IMPLEMENT("statistics not on");
}
Control[] result = null;
// Copy the Control objects which have thread associations into the result.
int runNum = threadContexts != null ? threadContexts.size() : 0;
if( runNum > 0 ) {
result = new Control[runNum];
Enumeration controls = threadContexts.elements();
int pos = 0;
while( controls.hasMoreElements() )
result[pos++] = ((ControlImpl)controls.nextElement()).object();
}
else
result = new Control[0];
return result;
| static Control[] | getSuspendedTransactions()Returns all the transactions in the system that are currently suspended
in the form of a sequence of Control objects.
if(!statsOn){
throw new NO_IMPLEMENT("statistics not on");
}
Control[] result = null;
// Copy the contents of the suspended set into the array.
int suspNum = suspended != null ? suspended.size() : 0;
if( suspNum > 0 ) {
result = new Control[suspNum];
Enumeration controls = suspended.elements();
int pos = 0;
while( controls.hasMoreElements() )
result[pos++] = ((ControlImpl)controls.nextElement()).object();
}
else
result = new Control[0];
return result;
| static void | initialise()Initialises the static state of the CurrentTransaction class.
// Initialise the static state for the class.
| public static boolean | isTxAssociated()
//Thread thread = Thread.currentThread();
//ControlImpl result = (ControlImpl) threadContexts.get(thread);
//return (result != null);
return (m_tid.get()!=null);
| static int | numActive(java.lang.Long localTID, boolean[] outstanding)Returns the number of thread associations currently active for the given
transaction identifier.
A boolean value indicating whether there are outstanding requests is returned
as an output parameter.
if(!statsOn){
throw new NO_IMPLEMENT("statistics not on");
}
int result = 0;
outstanding[0] = false;
StatusHolder outStatus = new StatusHolder();
// First check whether there are any outstanding requests.
// Count all of the Control objects that have the same local TID as that given.
Enumeration controls = threadContexts.elements();
while( controls.hasMoreElements() ) {
ControlImpl current = (ControlImpl)controls.nextElement();
// If the Control object represents a transaction that has been completed,
// don't count it.
outStatus.value = Status.StatusRolledBack;
try {
Long currentLocalTID = new Long(current.getLocalTID(outStatus));
if( outStatus.value == Status.StatusActive )
if( currentLocalTID.equals(localTID) ) {
outstanding[0] |= current.isOutgoing();
result++;
}
} catch( Throwable exc ) {
}
}
return result;
| static void | receivedReply(int id, PropagationContext context, org.omg.CORBA.Environment ex)Informs the CurrentTransaction that a reply has been received.
// Look up the current Control object.
//Thread thread = Thread.currentThread();
ControlImpl current = (ControlImpl)m_tid.get();
// If there is no current transaction, or an exception was raised, then just
// return.
if( current == null ) {
return;
}
//$ If there is an active exception, report it.
// OMG OTS issue 1819, if there is a system exception mark the
// transaction for rollback
java.lang.Exception ctxExc = ex.exception();
if (ctxExc instanceof SystemException) {
Coordinator currentCoord = null;
try {
if (Configuration.isLocalFactory()) {
currentCoord = current.get_localCoordinator();
} else {
currentCoord = current.get_coordinator();
}
} catch (Unavailable exc) {}
if (currentCoord == null) {
return; // no coord, cannot mark tx for rollback
}
try {
currentCoord.rollback_only();
} catch (Inactive exc) {}
// COMMENT (Ram J) (11/24/2000) This has been commented out since
// the exception reply could have a tx context. Do further checks.
//return;
}
// Return if there is no context on the message.
if( context == null ||
context.current == null ||
context.current.coord == null ||
context.current.otid.formatID == -1 ) {
return;
}
// Get the global id from the current context. If the transaction is not
// active, then end the current association.
StatusHolder outStatus = new StatusHolder();
outStatus.value = Status.StatusRolledBack;
GlobalTID globalTID = null;
try {
globalTID = new GlobalTID(current.getGlobalTID(outStatus));
} catch( Throwable exc ) {
}
// If the global identifier is NULL, then the Control object is unable to provide
// us with checking behaviour. We do not check in this case.
if( globalTID != null ) {
if( outStatus.value != Status.StatusActive ) {
endCurrent(true);
current.destroy();
// org.omg.CORBA.WrongTransaction exc = new org.omg.CORBA.WrongTransaction(0,CompletionStatus.COMPLETED_YES);
org.omg.CORBA.WrongTransaction exc = new org.omg.CORBA.WrongTransaction();
throw exc;
}
// If the global id is different from the one in the context, then raise the
// org.omg.CORBA.WrongTransaction exception.
if( !globalTID.equals(context.current.otid) ) {
// org.omg.CORBA.WrongTransaction exc = new org.omg.CORBA.WrongTransaction(0,CompletionStatus.COMPLETED_YES);
org.omg.CORBA.WrongTransaction exc = new org.omg.CORBA.WrongTransaction();
throw exc;
}
}
// If the Control object is not a proxy, then decrement the outgoing count.
// COMMENT(Ram J) 11/25/2000 With the PI based OTS 1.2 implementation,
// exception replies | location forwarded responses may not carry back
// a tx svc context (since the server OTS interceptor send point may
// not have been called. In such a case, it is impossible to enforce
// checked behaviour. The next revision of OTS 1.2 should address this,
// and provide a solution to the checked behaviour in a PI based OTS
// implementation. Then, these checks shall be enabled.
//current.decrementOutgoing();
| static void | receivedRequest(int id, PropagationContext context)Informs the CurrentTransaction that a request has been received.
The request contains the transaction context that should be established
for the object.
// Return if there is no context on the message.
// If the transaction identifier in the context is NULL, just return.
if( context == null ||
context.current == null ||
context.current.otid.formatID == -1 ) {
return;
}
// Use a local factory to recreate the transaction locally.
//if( localFactory == null )
//localFactory = Configuration.getFactory();
//Control current = localFactory.recreate(context);
Control current = Configuration.getFactory().recreate(context);
// Record the imported transaction.
importedTransactions.put(Thread.currentThread(),new GlobalTID(context.current.otid));
// Create a new Control and associate it with the thread
try {
ControlImpl contImpl = null;
if (Configuration.isLocalFactory()) {
contImpl = (ControlImpl) current;
} else {
contImpl = ControlImpl.servant(JControlHelper.narrow(current));
}
setCurrent(contImpl,false);
}
// If any exception was thrown during that lot, then we have failed to
// create a subordinate. Do something drastic.
catch( Throwable exc ) {
_logger.log(Level.WARNING,"jts.unable_to_create_subordinate_coordinator");
String msg = LogFormatter.getLocalizedMessage(_logger,
"jts.unable_to_create_subordinate_coordinator");
throw new org.omg.CORBA.INTERNAL(msg);
}
| public static void | recreate(GlobalTID tid, int timeout)Recreates a transaction based on the information contained in the
transaction id (tid) and associates the current thread of control with
the recreated transaction.
// check if there is any concurrent activity
if (RecoveryManager.readAndUpdateTxMap(tid) == false) {
throw new INVALID_TRANSACTION(
MinorCode.TX_CONCURRENT_WORK_DISALLOWED,
CompletionStatus.COMPLETED_NO);
}
// recreate the transaction
try {
// Use a local factory to recreate the transaction locally.
TransactionFactoryImpl factory =
(TransactionFactoryImpl) Configuration.getFactory();
Control current = factory.recreate(tid, timeout);
// Record the imported transaction.
importedTransactions.put(Thread.currentThread(), tid);
// Create a new Control and associate it with the thread
ControlImpl contImpl = null;
if (Configuration.isLocalFactory()) {
contImpl = (ControlImpl) current;
} else {
contImpl = ControlImpl.servant(JControlHelper.narrow(current));
}
setCurrent(contImpl,false);
} catch (Throwable exc) {
RecoveryManager.removeFromTxMap(tid); // remove tx id from map
_logger.log(Level.WARNING,"jts.unable_to_create_subordinate_coordinator");
String msg = LogFormatter.getLocalizedMessage(_logger,
"jts.unable_to_create_subordinate_coordinator");
//ErrorLog.error(Messages.SUBORDINATE_CREATE_FAILED, null, true);
throw new INVALID_TRANSACTION(
MinorCode.TX_RECREATE_FAILED, CompletionStatus.COMPLETED_MAYBE);
}
| static synchronized void | registerStatic(StaticResource obj)Registers the given StaticResource object.
The StaticResource object will be informed whenever any association of
a transaction with a thread is started or ended.
// If the RegisteredStatics instance variable has not been created at this
// point, create it.
if( statics == null )
statics = new RegisteredStatics();
// Attempt to add the StaticResource reference to those already registered.
statics.addStatic(obj);
| public static void | release(GlobalTID tid)Disassociates the current thread of control from the specified
transaction.
Thread thread = (Thread) RecoveryManager.getThreadFromTxMap(tid);
if (thread == null || (thread != Thread.currentThread())) {
// the current thread is not in tx, so simply return.
return;
} else {
RecoveryManager.removeFromTxMap(tid);
}
// Ensure that the current Control object is valid.
boolean[] outBoolean = new boolean[1];
ControlImpl control = endAborted(outBoolean, true); // end association
if (outBoolean[0]) {
importedTransactions.remove(Thread.currentThread());
return; // thread is not associated with tx, simply return
}
// Get the global identifier of the transaction that was imported into
// this thread. If there is none, that is an error.
GlobalTID importedTID = (GlobalTID) importedTransactions.remove(thread);
// Check that the current transaction matches the one that was imported.
StatusHolder outStatus = new StatusHolder();
try {
if (importedTID == null || control == null ||
!importedTID.equals(control.getGlobalTID(outStatus)) ||
outStatus.value != Status.StatusActive) {
INVALID_TRANSACTION exc =
new INVALID_TRANSACTION(MinorCode.WrongContextOnReply,
CompletionStatus.COMPLETED_YES);
throw exc;
}
} catch (SystemException ex) {
INVALID_TRANSACTION exc =
new INVALID_TRANSACTION(MinorCode.WrongContextOnReply,
CompletionStatus.COMPLETED_YES);
throw exc;
}
// End the current thread association.
endCurrent(false);
control.destroy();
| static boolean | removeSuspended(ControlImpl control)Removes the given Control object from the set of those suspended in the
process. The operation returns FALSE if the Control object has not been
suspended.
boolean result = true;
if(statsOn)
result=suspended.removeElement(control);
return result;
| static void | sendingReply(int id, PropagationContextHolder holder)Informs the object's Coordinator that a reply is being sent to the client.
// Zero out context information.
// Ensure that the cached reference to the ORB is set up, and that the Any
// value in the context is initialised.
//$ The following is necessary for the context to be marshallable. It is a
//$ waste of time when there is no transaction, in which case we should be
//$ throwing the TRANSACTION_REQUIRED exception (?).
if( emptyContext.implementation_specific_data == null ) {
ORB orb = Configuration.getORB();
emptyContext.implementation_specific_data = orb.create_any();
emptyContext.implementation_specific_data.insert_boolean(false);
}
// COMMENT(Ram J) There is no need to send an empty context, if a tx
// is not available. The PI based OTS hooks will not send a tx context
// in the reply.
/*
holder.value = emptyContext;
*/
// Ensure that the current Control object is valid. Return immediately if not.
boolean[] outBoolean = new boolean[1];
ControlImpl current = endAborted(outBoolean, true); // end association
if( outBoolean[0] ) {
importedTransactions.remove(Thread.currentThread());
TRANSACTION_ROLLEDBACK exc = new TRANSACTION_ROLLEDBACK(0,CompletionStatus.COMPLETED_YES);
throw exc;
}
// Get the global identifier of the transaction that was imported into this
// thread. If there is none, that is an error.
Thread thread = Thread.currentThread();
GlobalTID importedTID = (GlobalTID)importedTransactions.remove(thread);
// If there is no import information, and no current transaction, then return
// the empty context.
if( importedTID == null && current == null ) {
return;
}
// Check that the current transaction matches the one that was imported.
StatusHolder outStatus = new StatusHolder();
try {
if( importedTID == null ||
current == null ||
!importedTID.equals(current.getGlobalTID(outStatus)) ||
outStatus.value != Status.StatusActive ) {
INVALID_TRANSACTION exc = new INVALID_TRANSACTION(MinorCode.WrongContextOnReply,CompletionStatus.COMPLETED_YES);
throw exc;
}
} catch( SystemException ex ) {
INVALID_TRANSACTION exc = new INVALID_TRANSACTION(MinorCode.WrongContextOnReply,CompletionStatus.COMPLETED_YES);
throw exc;
}
//$Get the Coordinator reference.
CoordinatorImpl coord = null;
Coordinator coordRef = null;
try {
if (Configuration.isLocalFactory()) {
coord = (CoordinatorImpl) current.get_localCoordinator();
} else {
coordRef = current.get_coordinator();
coord = CoordinatorImpl.servant(coordRef);
}
// _logger.log(Level.FINE,"Servant = "+coord);
} catch( Throwable exc ) {
}
// Check the Coordinator before sending the reply.
// We must do this before ending the thread association to allow the
// Coordinator to take advantage of registration on reply if available.
// Note that if the Coordinator returns forgetMe, the global identifier
// will have been destroyed at this point.
CoordinatorImpl forgetParent = null;
int[] outInt = new int[1];
//StatusHolder outStatus = new StatusHolder();
try {
forgetParent = coord.replyAction(outInt);
} catch( Throwable exc ) {
}
int replyAction = outInt[0];
if( replyAction == CoordinatorImpl.activeChildren ) {
try {
coord.rollback_only();
} catch( Throwable ex ) {}
INVALID_TRANSACTION exc = new INVALID_TRANSACTION(MinorCode.UnfinishedSubtransactions,
CompletionStatus.COMPLETED_YES);
throw exc;
}
// End the current thread association.
endCurrent(false);
// If the transaction needs to be cleaned up, do so now.
// We ignore any exception the end_current may have raised in this case.
// The Control object is destroyed before the Coordinator so that it is not
// in the suspended set when the Coordinator is rolled back.
if( replyAction == CoordinatorImpl.forgetMe ) {
current.destroy();
coord.cleanUpEmpty(forgetParent);
}
// Otherwise, we have to check this reply.
else {
if( current.isAssociated() ||
current.isOutgoing() ) {
try {
coord.rollback_only();
} catch( Throwable exc ) {}
INVALID_TRANSACTION exc = new INVALID_TRANSACTION(MinorCode.DeferredActivities,
CompletionStatus.COMPLETED_YES);
throw exc;
}
current.destroy();
}
// Create a context with the necessary information.
// All we propagate back is the transaction id and implementation specific data.
holder.value = new PropagationContext(0,new TransIdentity(null,null,importedTID.realTID),
new TransIdentity[0],emptyContext.implementation_specific_data);
| static void | sendingRequest(int id, PropagationContextHolder holder)Informs the CurrentTransaction that a request is being sent.
Returns the transaction context that should be established for the object in
the remote process.
// Empty out the context.
// Ensure that the cached reference to the ORB is set up, and that the Any
// value in the context is initialised.
//$ The following is necessary for the context to be marshallable. It is a
//$ waste of time when there is no transaction, in which case we should be
//$ throwing the TRANSACTION_REQUIRED exception.
// COMMENT(Ram J) 11/19/2000 This is taken care of by the PI OTS
// interceptors, so this has been commented out. If no current
// transaction is available simply return. The PI OTS interceptor will
// either raise a TRANSACTION_REQUIRED exception if the target policy
// requires a transaction, else it will not provide a tx context.
/*
if( emptyContext.implementation_specific_data == null ) {
if( orb == null )
orb = Configuration.getORB();
emptyContext.implementation_specific_data = orb.create_any();
emptyContext.implementation_specific_data.insert_boolean(false);
}
holder.value = emptyContext;
*/
// Ensure that the current Control object is valid. Return immediately if
// not.
boolean[] outBoolean = new boolean[1];
ControlImpl current = endAborted(outBoolean, false);
if( outBoolean[0] ) {
TRANSACTION_ROLLEDBACK exc = new TRANSACTION_ROLLEDBACK(0,CompletionStatus.COMPLETED_NO);
throw exc;
}
// Throw the TRANSACTION_REQUIRED exception if there is no current transaction.
if( current == null ) {
//$ TRANSACTION_REQUIRED exc = new TRANSACTION_REQUIRED();
//$ if( trc != null ) trc.event(EVT_THROW).data(exc).write();
//$ throw exc;
return;
}
// Get the the context from the Control object.
// If the context is not available, then indicate that there is no transaction.
try {
holder.value = current.getTXContext();
}
// If the Coordinator is inactive, throw the INVALID_TRANSACTION exception,
// as this will be because the transaction is not able to do transactional
// work.
catch (Unavailable exc) {
INVALID_TRANSACTION ex2 = new INVALID_TRANSACTION(0,CompletionStatus.COMPLETED_NO);
throw ex2;
}
// If the Coordinator has rolled back, allow the TRANSACTION_ROLLEDBACK exception,
// to pass to the caller.
catch( TRANSACTION_ROLLEDBACK exc ) {
endCurrent(true);
current.destroy();
throw (TRANSACTION_ROLLEDBACK)exc.fillInStackTrace();
}
// Any other exception is unexpected. Assume there is no transaction.
catch( Throwable exc ) {
}
// Increase the count of outgoing requests for this transaction, if the
// Control object is not a proxy.
// COMMENT(Ram J) 11/25/2000 With the PI based OTS 1.2 implementation,
// exception replies | location forwarded responses may not carry back
// a tx svc context (since the server OTS interceptor send point may
// not have been called. In such a case, it is impossible to enforce
// checked behaviour. The next revision of OTS 1.2 should address this,
// and provide a solution to the checked behaviour in a PI based OTS
// implementation. Then, these checks shall be enabled.
//current.incrementOutgoing();
| static boolean | setCurrent(ControlImpl control, boolean stack)Sets up the thread association for a Control object.
If the thread association already exists for the thread under which the
operation was invoked and the stacking flag is set, the existing Control
is stacked behind the given one, which is made the current one.
If the association already exists and the stacking flag is not set, no
association is changed and the operation returns false.
For XA support, when an association is started or ended, all
registered StaticResource objects are informed of the association change.
boolean result = false;
// Ensure that the current thread association is valid.
//boolean[] outBoolean = new boolean[1];
ControlImpl current = (ControlImpl)m_tid.get();
/*if( outBoolean[0] ) {
}*/
// If there is a current Control object, and we have not been asked to stack
// it, return FALSE to indicate that we cannot replace it.
// Otherwise stack the current Control object behind the new one, which
// becomes the current Control for the thread.
if( current != null ) {
if( stack ) {
// XA support: If the remove operation was successful, inform all registered
// StaticResource objects of the end of the thread association.
// Allow any exception to percolate to the caller.
// This is done first so that if there is an error, we don't leave the
// transaction associated.
if( statics != null )
statics.distributeEnd(current,false);
// Push the given Control object onto the current one, and remove the
// current association.
StatusHolder outStatus = new StatusHolder();
control.pushControl(current,outStatus);
if(statsOn){
Thread thread = Thread.currentThread();
result = (threadContexts.remove(thread) != null);
}
else
result=true;
m_tid.set(null);
// The parent transaction has effectively been suspended - add it to the
// set of suspended transactions.
if(statsOn)
suspended.addElement(current);
}
} else
result = true;
// If there is no current Control, then just make the new one current.
if( result ) {
// XA support: If the set_current operation was successful, inform all
// registered StaticResource objects of the new thread association.
// Allow any exception to percolate to the caller.
// This is done first so that if there is an error, we don't leave the
// transaction associated.
if( statics != null )
statics.distributeStart(control,stack);
// Update the thread to Control mapping for the new Control.
if(statsOn){
Thread thread = Thread.currentThread();
threadContexts.put(thread,control);
}
m_tid.set(control);
// Remove the Control from the set of suspended Control objects.
if(statsOn)
suspended.removeElement(control);
// Increment the association count for the control object
control.incrementAssociation();
}
return result;
| static void | shutdown(boolean immediate)Informs the CurrentTransaction that the transaction service is being shut
down.
For immediate shutdown,
For quiesce,
//$Continue with shutdown/quiesce.
|
|