Search in sources :

Example 1 with WorkCompletedException

use of javax.resource.spi.work.WorkCompletedException in project Payara by payara.

the class TransactionManagerImpl method recreate.

/**
 * Recreate a transaction based on the Xid. This call causes the calling
 * thread to be associated with the specified transaction.
 *
 * @param xid the Xid object representing a transaction.
 * @param timeout positive, non-zero value for transaction timeout.
 */
public static void recreate(Xid xid, long timeout) throws WorkException {
    // check if xid is valid
    if (xid == null || xid.getFormatId() == 0 || xid.getBranchQualifier() == null || xid.getGlobalTransactionId() == null) {
        WorkException workExc = new WorkCompletedException("Invalid Xid");
        workExc.setErrorCode(WorkException.TX_RECREATE_FAILED);
        throw workExc;
    }
    // has TransactionService been initialized?
    if (!DefaultTransactionService.isActive()) {
        WorkException workExc = new WorkCompletedException("Transaction Manager unavailable");
        workExc.setErrorCode(WorkException.TX_RECREATE_FAILED);
        throw workExc;
    }
    // recreate the transaction
    GlobalTID tid = new GlobalTID(xid);
    try {
        CurrentTransaction.recreate(tid, (int) ((timeout <= 0) ? 0 : timeout));
    } catch (Throwable exc) {
        String errorCode = WorkException.TX_RECREATE_FAILED;
        if (exc instanceof INVALID_TRANSACTION && (((INVALID_TRANSACTION) exc).minor == MinorCode.TX_CONCURRENT_WORK_DISALLOWED)) {
            errorCode = WorkException.TX_CONCURRENT_WORK_DISALLOWED;
        }
        WorkException workExc = new WorkCompletedException(exc);
        workExc.setErrorCode(errorCode);
        throw workExc;
    }
}
Also used : WorkException(javax.resource.spi.work.WorkException) GlobalTID(com.sun.jts.CosTransactions.GlobalTID) WorkCompletedException(javax.resource.spi.work.WorkCompletedException)

Example 2 with WorkCompletedException

use of javax.resource.spi.work.WorkCompletedException in project narayana by jbosstm.

the class TxWorkManager method addWork.

/*
	 * Although we allow multiple units of work per transaction, currently
	 * JCA only allows one. Might not be worth the hassle of maintaing this
	 * support.
	 */
/**
 * Add the specified work unit to the specified transaction.
 *
 * @param work The work to associate with the transaction.
 * @param tx The transaction to have associated with the work.
 *
 * @throws WorkCompletedException thrown if there is already work
 * associated with the transaction.
 */
public static void addWork(Work work, Transaction tx) throws WorkCompletedException {
    Stack<Work> workers;
    synchronized (_transactions) {
        workers = _transactions.get(tx);
        if (workers == null) {
            workers = new Stack<Work>();
            _transactions.put(tx, workers);
        } else
            throw new WorkCompletedException(jtaLogger.i18NLogger.get_transaction_arjunacore_jca_busy(), WorkException.TX_CONCURRENT_WORK_DISALLOWED);
    }
    synchronized (workers) {
        workers.push(work);
    }
}
Also used : Work(javax.resource.spi.work.Work) WorkCompletedException(javax.resource.spi.work.WorkCompletedException)

Example 3 with WorkCompletedException

use of javax.resource.spi.work.WorkCompletedException in project narayana by jbosstm.

the class XATerminator method startWork.

/**
 * Associate the current thread with the specified transaction. In JBoss
 * 4.x, they assume that the work has already been registered, so we do
 * likewise, i.e., we don't do a register if it hasn't, but we will throw an
 * exception (which is more than JBoss does).
 *
 * @param work the Work to start
 * @param xid the transaction to associate with the current thread.
 *
 * @throws WorkCompletedException thrown if there are any errors.
 */
public void startWork(Work work, Xid xid) throws WorkCompletedException {
    try {
        Transaction tx = SubordinationManager.getTransactionImporter().importTransaction(xid);
        if (!TxWorkManager.getWork(tx).equals(work)) {
            throw new WorkCompletedException(jbossatxLogger.i18NLogger.get_jta_jca_unknownwork(), WorkException.INTERNAL);
        }
        TransactionManager.transactionManager().resume(tx);
    } catch (XAException ex) {
        throw new WorkCompletedException(ex);
    } catch (InvalidTransactionException ex) {
        throw new WorkCompletedException(jbossatxLogger.i18NLogger.get_jta_jca_inactive(), WorkException.TX_RECREATE_FAILED);
    } catch (SystemException ex) {
        throw new WorkCompletedException(jbossatxLogger.i18NLogger.get_jta_jca_unknown(), WorkException.INTERNAL);
    }
}
Also used : XAException(javax.transaction.xa.XAException) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) InvalidTransactionException(javax.transaction.InvalidTransactionException) WorkCompletedException(javax.resource.spi.work.WorkCompletedException)

Example 4 with WorkCompletedException

use of javax.resource.spi.work.WorkCompletedException in project narayana by jbosstm.

the class XATerminator method startWork.

/**
 * Associate the current thread with the specified transaction. In JBoss
 * 4.x, they assume that the work has already been registered, so we do
 * likewise, i.e., we don't do a register if it hasn't, but we will throw an
 * exception (which is more than JBoss does).
 *
 * @param work the Work to start
 * @param xid the transaction to associate with the current thread.
 *
 * @throws WorkCompletedException thrown if there are any errors.
 */
public void startWork(Work work, Xid xid) throws WorkCompletedException {
    try {
        Transaction tx = SubordinationManager.getTransactionImporter().importTransaction(xid);
        if (!TxWorkManager.getWork(tx).equals(work)) {
            throw new WorkCompletedException(jbossatxLogger.i18NLogger.get_jts_jca_unknownwork(), WorkException.INTERNAL);
        }
        TransactionManager.transactionManager().resume(tx);
    } catch (XAException ex) {
        throw new WorkCompletedException(ex);
    } catch (InvalidTransactionException ex) {
        throw new WorkCompletedException(jbossatxLogger.i18NLogger.get_jts_jca_inactive(), WorkException.TX_RECREATE_FAILED);
    } catch (SystemException ex) {
        throw new WorkCompletedException(jbossatxLogger.i18NLogger.get_jts_jca_unknown(), WorkException.INTERNAL);
    }
}
Also used : XAException(javax.transaction.xa.XAException) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) InvalidTransactionException(javax.transaction.InvalidTransactionException) WorkCompletedException(javax.resource.spi.work.WorkCompletedException)

Example 5 with WorkCompletedException

use of javax.resource.spi.work.WorkCompletedException in project narayana by jbosstm.

the class XATerminator method registerWork.

/**
 * Register the unit of work with the specified transaction. The
 * thread-to-transaction association is not changed yet. Basically this
 * operation only lets the transaction system know about the work and
 * nothing else.
 *
 * @param work
 *            the work to associate with the transaction.
 * @param xid
 *            the transaction within which the work will be performed.
 * @param timeout
 *            the lifetime of the transaction.
 *
 * @throws WorkCompletedException
 *             thrown if the work cannot be associated with the transaction.
 */
public void registerWork(Work work, Xid xid, long timeout) throws WorkCompletedException {
    try {
        /*
			 * Remember to convert timeout to seconds.
			 */
        Transaction tx = SubordinationManager.getTransactionImporter().importTransaction(xid, (int) timeout / 1000);
        switch(tx.getStatus()) {
            case Status.STATUS_NO_TRANSACTION:
            case Status.STATUS_UNKNOWN:
                throw new WorkCompletedException(jbossatxLogger.i18NLogger.get_jta_jca_inactive(), WorkException.TX_RECREATE_FAILED);
            case Status.STATUS_ACTIVE:
                break;
            default:
                throw new WorkCompletedException(jbossatxLogger.i18NLogger.get_jta_jca_completing(), WorkException.TX_CONCURRENT_WORK_DISALLOWED);
        }
        TxWorkManager.addWork(work, tx);
        /*
			 * TODO currently means one synchronization per work item and that
			 * instance isn't removed when/if the work item is cancelled and
			 * another work item is later added.
			 *
			 * Synchronizations are pretty lightweight and this add/remove/add
			 * scenario will hopefully not happen that much. So, we don't
			 * optimise for it at the moment. Re-evaluate if it does become an
			 * overhead.
			 */
        tx.registerSynchronization(new WorkSynchronization(tx));
    } catch (WorkCompletedException ex) {
        throw ex;
    } catch (XAException ex) {
        throw new WorkCompletedException(ex);
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new WorkCompletedException(jbossatxLogger.i18NLogger.get_jta_jca_unknown(), WorkException.INTERNAL);
    }
}
Also used : XAException(javax.transaction.xa.XAException) Transaction(javax.transaction.Transaction) WorkSynchronization(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.WorkSynchronization) InvalidTransactionException(javax.transaction.InvalidTransactionException) WorkException(javax.resource.spi.work.WorkException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) WorkCompletedException(javax.resource.spi.work.WorkCompletedException) WorkCompletedException(javax.resource.spi.work.WorkCompletedException)

Aggregations

WorkCompletedException (javax.resource.spi.work.WorkCompletedException)7 InvalidTransactionException (javax.transaction.InvalidTransactionException)4 SystemException (javax.transaction.SystemException)4 Transaction (javax.transaction.Transaction)4 XAException (javax.transaction.xa.XAException)4 WorkException (javax.resource.spi.work.WorkException)3 Work (javax.resource.spi.work.Work)2 WorkSynchronization (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.WorkSynchronization)1 WorkSynchronization (com.arjuna.ats.internal.jta.transaction.jts.jca.WorkSynchronization)1 GlobalTID (com.sun.jts.CosTransactions.GlobalTID)1