Search in sources :

Example 1 with WorkSynchronization

use of com.arjuna.ats.internal.jta.transaction.jts.jca.WorkSynchronization in project narayana by jbosstm.

the class WorkUnitTest method testWorkSynchronization.

@Test
public void testWorkSynchronization() throws Exception {
    Transaction tx = new TransactionImple();
    Synchronization ws = new WorkSynchronization(tx);
    DummyWork work = new DummyWork();
    TxWorkManager.addWork(work, tx);
    try {
        ws.beforeCompletion();
        fail();
    } catch (final IllegalStateException ex) {
    }
    ws.afterCompletion(Status.STATUS_COMMITTED);
}
Also used : Transaction(javax.transaction.Transaction) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) WorkSynchronization(com.arjuna.ats.internal.jta.transaction.jts.jca.WorkSynchronization) Synchronization(javax.transaction.Synchronization) WorkSynchronization(com.arjuna.ats.internal.jta.transaction.jts.jca.WorkSynchronization) Test(org.junit.Test)

Example 2 with WorkSynchronization

use of com.arjuna.ats.internal.jta.transaction.jts.jca.WorkSynchronization 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 transactin.
 */
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_jts_jca_inactive(), WorkException.TX_RECREATE_FAILED);
            case Status.STATUS_ACTIVE:
                break;
            default:
                throw new WorkCompletedException(jbossatxLogger.i18NLogger.get_jts_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_jts_jca_unknown(), WorkException.INTERNAL);
    }
}
Also used : XAException(javax.transaction.xa.XAException) Transaction(javax.transaction.Transaction) WorkSynchronization(com.arjuna.ats.internal.jta.transaction.jts.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)

Example 3 with WorkSynchronization

use of com.arjuna.ats.internal.jta.transaction.jts.jca.WorkSynchronization in project narayana by jbosstm.

the class WorkUnitTest method testWorkSynchronization.

@Test
public void testWorkSynchronization() throws Exception {
    Transaction tx = new TransactionImple();
    Synchronization ws = new WorkSynchronization(tx);
    DummyWork work = new DummyWork();
    TxWorkManager.addWork(work, tx);
    try {
        ws.beforeCompletion();
        fail();
    } catch (final IllegalStateException ex) {
    }
    ws.afterCompletion(Status.STATUS_COMMITTED);
}
Also used : Transaction(javax.transaction.Transaction) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) WorkSynchronization(com.arjuna.ats.internal.jta.transaction.jts.jca.WorkSynchronization) Synchronization(javax.transaction.Synchronization) WorkSynchronization(com.arjuna.ats.internal.jta.transaction.jts.jca.WorkSynchronization) Test(org.junit.Test)

Aggregations

WorkSynchronization (com.arjuna.ats.internal.jta.transaction.jts.jca.WorkSynchronization)3 Transaction (javax.transaction.Transaction)3 TransactionImple (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple)2 Synchronization (javax.transaction.Synchronization)2 Test (org.junit.Test)2 WorkCompletedException (javax.resource.spi.work.WorkCompletedException)1 WorkException (javax.resource.spi.work.WorkException)1 InvalidTransactionException (javax.transaction.InvalidTransactionException)1 SystemException (javax.transaction.SystemException)1 XAException (javax.transaction.xa.XAException)1