use of com.arjuna.ats.internal.jts.ControlWrapper in project narayana by jbosstm.
the class TransactionImple method getTransaction.
/**
* Creates if does not exist and adds to our internal mapping table.
*/
public static final TransactionImple getTransaction() {
TransactionImple tx = null;
// try {
ControlWrapper otx = OTSImpleManager.current().getControlWrapper();
if (otx != null) {
synchronized (TransactionImple._transactions) {
try {
tx = (TransactionImple) TransactionImple._transactions.get(otx.get_uid());
if (tx == null) {
/*
* If it isn't active then don't add it to the
* hashtable.
*/
tx = new TransactionImple(new AtomicTransaction(otx));
try {
if (tx.getStatus() == javax.transaction.Status.STATUS_ACTIVE) {
putTransaction(tx);
}
} catch (Exception ex) {
// shouldn't happen!
}
}
} catch (ClassCastException ex) {
jtaxLogger.i18NLogger.warn_jtax_transaction_jts_nottximple();
}
}
}
return tx;
}
use of com.arjuna.ats.internal.jts.ControlWrapper in project narayana by jbosstm.
the class CurrentImple method commit.
/**
* It's not possible to commit/abort out of order using the current
* interface.
*
* Do we delete the control if the transaction gives an heuristic result?
* CurrentImplely we do.
*
* If another thread has already terminated the transaction then: (i) if it
* committed, 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 rolledback, we throw
* TRANSACTION_ROLLEDBACK.
*/
public void commit(boolean report_heuristics) throws NoTransaction, HeuristicMixed, HeuristicHazard, SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("CurrentImple::commit ( " + report_heuristics + " )");
}
ControlWrapper currentAction = _theManager.current();
if (currentAction != null) {
try {
ThreadAssociationControl.updateAssociation(currentAction, TX_COMMITTED);
} catch (Exception e) {
/*
* An error happened, so mark the transaction as rollback only
* (in case it hasn't already been so marked.)
*/
rollback_only();
}
try {
currentAction.commit(report_heuristics);
_theManager.popAction();
} catch (TRANSACTION_ROLLEDBACK e1) {
/*
* Is ok to destroy transaction. Different for heuristics.
*/
_theManager.popAction();
throw e1;
} catch (HeuristicMixed e2) {
_theManager.popAction();
if (report_heuristics)
throw e2;
} catch (HeuristicHazard e3) {
_theManager.popAction();
if (report_heuristics)
throw e3;
} catch (SystemException e4) {
_theManager.popAction();
throw e4;
} catch (Unavailable e5) {
/*
* If terminated by some other thread then the reference we have
* will no longer be valid.
*/
_theManager.popAction();
throw new INVALID_TRANSACTION();
}
} else
throw new NoTransaction();
}
use of com.arjuna.ats.internal.jts.ControlWrapper 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 com.arjuna.ats.internal.jts.ControlWrapper in project narayana by jbosstm.
the class CurrentImple method resume.
/**
* To support checked transactions we can only resume if the action is local
* or we received it implicitly.
*
* If the control refers to a nested transaction then we must recreate the
* entire hierarchy, i.e., the effect of a suspend/resume on the same
* control should be the same as never calling suspend in the first place.
*
* If the control is for a local transaction then it is simple to recreate
* the hierarchy. Otherwise we rely upon the PropagationContext to recreate
* it.
*
* If this control is a "proxy" then create a new proxy instance, so we can
* delete proxies whenever suspend is called.
*
* Should check if "new" transaction is not actually the current one anyway.
* If so, just return. The spec. doesn't mention what to do in this case, so
* for now we go to the overhead of the work regardless.
*/
public void resume(Control which) throws InvalidControl, SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("CurrentImple::resume ( " + which + " )");
}
/*
* We must now "forget" any current transaction information. This is
* because when we end this transaction we must be associated with no
* transaction.
*/
_theManager.purgeActions();
if (// if null then return
which == null) {
ThreadAssociationControl.updateAssociation(null, TX_RESUMED);
return;
}
/*
* Must duplicate because it is an 'in' parameter which we want to keep.
*/
org.omg.CosTransactions.Control cont = which;
boolean invalidControl = false;
try {
Coordinator coord = cont.get_coordinator();
if (!coord.is_top_level_transaction()) {
/*
* Is the Control an ActionControl? If so then it has methods to
* allow us to get the parent directly. Otherwise, rely on the
* PropagationContext.
*/
ActionControl actControl = null;
try {
actControl = com.arjuna.ArjunaOTS.ActionControlHelper.narrow(cont);
if (actControl == null)
throw new BAD_PARAM();
} catch (Exception e) {
/*
* Not an ActionControl.
*/
actControl = null;
}
if (actControl != null) {
invalidControl = _theManager.addActionControlHierarchy(actControl);
} else {
invalidControl = _theManager.addRemoteHierarchy(cont);
}
}
coord = null;
} catch (OBJECT_NOT_EXIST one) {
// throw new InvalidControl();
} catch (// JacORB 1.4.5 bug
UNKNOWN ue) {
} catch (// JacORB 2.0 beta 2 bug
org.omg.CORBA.OBJ_ADAPTER oae) {
} catch (SystemException sysEx) {
throw new InvalidControl();
} catch (UserException usrEx) {
throw new InvalidControl();
} catch (NullPointerException npx) {
throw new InvalidControl();
} catch (Exception ex) {
throw new BAD_OPERATION("CurrentImple.resume: " + ex.toString());
}
try {
if (!invalidControl) {
ControlWrapper wrap = new ControlWrapper(cont);
ThreadAssociationControl.updateAssociation(wrap, TX_RESUMED);
_theManager.pushAction(wrap);
}
} catch (NullPointerException npx) {
invalidControl = true;
}
cont = null;
if (invalidControl)
throw new InvalidControl();
}
use of com.arjuna.ats.internal.jts.ControlWrapper in project narayana by jbosstm.
the class CurrentImple method resumeImple.
public void resumeImple(ControlImple which) throws InvalidControl, SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("CurrentImple::resumeImple ( " + which + " )");
}
/*
* We must now "forget" any current transaction information. This is
* because when we end this transaction we must be associated with no
* transaction.
*/
_theManager.purgeActions();
if (// if null then return
which == null) {
ThreadAssociationControl.updateAssociation(null, TX_RESUMED);
return;
}
boolean invalidControl = _theManager.addControlImpleHierarchy(which);
try {
if (!invalidControl) {
ControlWrapper wrap = new ControlWrapper(which);
ThreadAssociationControl.updateAssociation(wrap, TX_RESUMED);
_theManager.pushAction(wrap);
}
} catch (NullPointerException npx) {
npx.printStackTrace();
invalidControl = true;
}
if (invalidControl)
throw new InvalidControl();
}
Aggregations