Search in sources :

Example 31 with XAException

use of javax.transaction.xa.XAException in project wildfly by wildfly.

the class TransactionInflowResourceAdapter method endpointActivation.

public void endpointActivation(MessageEndpointFactory endpointFactory, ActivationSpec spec) throws ResourceException {
    Xid xid = TransactionInflowXid.getUniqueXid(42);
    TransactionInflowWork work = new TransactionInflowWork(endpointFactory, MSG);
    TransactionContext txnCtx = new TransactionContext();
    txnCtx.setXid(xid);
    TransactionInflowWorkListener workListener = new TransactionInflowWorkListener();
    try {
        bootstrapContext.getWorkManager().startWork(work, WorkManager.IMMEDIATE, txnCtx, workListener);
    } catch (WorkException e) {
        throw new IllegalStateException("Can't start work " + work + " with txn " + txnCtx);
    }
    // start Work blocks until the execution starts but not until its completion
    // timeout 10 seconds
    int timeout = TimeoutUtil.adjust(10_000);
    long start = System.currentTimeMillis();
    while (!workListener.isCompleted() && (System.currentTimeMillis() - start < timeout)) {
        // active waiting
        Thread.yield();
    }
    if (!workListener.isCompleted())
        throw new IllegalStateException("Work " + work + " of xid " + xid + " does not finish.");
    try {
        bootstrapContext.getXATerminator().prepare(xid);
        // depends on value in spec we commit or roll-back
        TransactionInflowRaSpec activationSpec = (TransactionInflowRaSpec) spec;
        if (activationSpec.getAction().equals(ACTION_COMMIT)) {
            bootstrapContext.getXATerminator().commit(xid, false);
        } else if (activationSpec.getAction().equals(ACTION_ROLLBACK)) {
            bootstrapContext.getXATerminator().rollback(xid);
        } else {
            new IllegalStateException("Spec '" + activationSpec + "' defines unknown action");
        }
    } catch (XAException xae) {
        throw new IllegalStateException("Can't process prepare/commit/rollback calls for xid: " + xid, xae);
    }
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) TransactionContext(javax.resource.spi.work.TransactionContext) WorkException(javax.resource.spi.work.WorkException)

Example 32 with XAException

use of javax.transaction.xa.XAException in project wildfly by wildfly.

the class JBossContextXATerminator method startWork.

/**
     * <p>
     * Start work gets imported transaction and assign it to current thread.
     * <p>
     * This method mimics behavior of Narayana's {@link JBossXATerminator}.
     */
@Override
public void startWork(Work work, Xid xid) throws WorkCompletedException {
    LocalTransaction transaction = null;
    try {
        ImportResult<LocalTransaction> transactionImportResult = localTransactionContext.findOrImportTransaction(xid, 0);
        transaction = transactionImportResult.getTransaction();
        ContextTransactionManager.getInstance().resume(transaction);
    } catch (XAException xae) {
        throw TransactionLogger.ROOT_LOGGER.cannotFindOrImportInflowTransaction(xid, work, xae);
    } catch (InvalidTransactionException ite) {
        throw TransactionLogger.ROOT_LOGGER.importedInflowTransactionIsInactive(xid, work, ite);
    } catch (SystemException se) {
        throw TransactionLogger.ROOT_LOGGER.cannotResumeInflowTransactionUnexpectedError(transaction, work, se);
    }
}
Also used : XAException(javax.transaction.xa.XAException) LocalTransaction(org.wildfly.transaction.client.LocalTransaction) SystemException(javax.transaction.SystemException) InvalidTransactionException(javax.transaction.InvalidTransactionException)

Example 33 with XAException

use of javax.transaction.xa.XAException in project hazelcast by hazelcast.

the class HazelcastXACompatibilityTest method testTransactionTimeout.

@Test
public void testTransactionTimeout() throws XAException {
    boolean timeoutSet = xaResource.setTransactionTimeout(2);
    assertTrue(timeoutSet);
    xaResource.start(xid, TMNOFLAGS);
    TransactionContext context = xaResource.getTransactionContext();
    TransactionalMap<Object, Object> map = context.getMap("map");
    map.put("key", "val");
    xaResource.end(xid, TMSUCCESS);
    sleepSeconds(3);
    try {
        xaResource.commit(xid, true);
        fail();
    } catch (XAException e) {
        assertEquals(XAException.XA_RBTIMEOUT, e.errorCode);
    }
}
Also used : XAException(javax.transaction.xa.XAException) TransactionContext(com.hazelcast.transaction.TransactionContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 34 with XAException

use of javax.transaction.xa.XAException in project hazelcast by hazelcast.

the class HazelcastXACompatibilityTest method testEnd_FromDifferentThread.

@Test
public void testEnd_FromDifferentThread() throws Exception {
    xaResource.start(xid, TMNOFLAGS);
    TransactionContext context = xaResource.getTransactionContext();
    TransactionalMap<Object, Object> map = context.getMap("map");
    map.put("key", "value");
    final CountDownLatch latch = new CountDownLatch(1);
    new Thread() {

        @Override
        public void run() {
            try {
                xaResource.end(xid, XAResource.TMFAIL);
                latch.countDown();
            } catch (XAException e) {
                e.printStackTrace();
            }
        }
    }.start();
    assertOpenEventually(latch, 10);
}
Also used : XAException(javax.transaction.xa.XAException) TransactionContext(com.hazelcast.transaction.TransactionContext) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 35 with XAException

use of javax.transaction.xa.XAException in project hazelcast by hazelcast.

the class HazelcastXATest method startTX.

private void startTX(final HazelcastInstance instance, final CountDownLatch nodeShutdownLatch) {
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                HazelcastXAResource xaResource = instance.getXAResource();
                Xid xid = new SerializableXID(42, "globalTransactionId".getBytes(), "branchQualifier".getBytes());
                xaResource.start(xid, XAResource.TMNOFLAGS);
                TransactionContext context = xaResource.getTransactionContext();
                final TransactionalMap<Object, Object> map = context.getMap("map");
                map.put("key", "value");
                xaResource.prepare(xid);
                instance.shutdown();
                nodeShutdownLatch.countDown();
            } catch (XAException e) {
                e.printStackTrace();
            }
        }
    }).start();
}
Also used : Xid(javax.transaction.xa.Xid) SerializableXID(com.hazelcast.transaction.impl.xa.SerializableXID) XAException(javax.transaction.xa.XAException) TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastXAResource(com.hazelcast.transaction.HazelcastXAResource)

Aggregations

XAException (javax.transaction.xa.XAException)68 IOException (java.io.IOException)20 Xid (javax.transaction.xa.Xid)19 SystemException (javax.transaction.SystemException)14 TransactionContext (com.hazelcast.transaction.TransactionContext)12 RollbackException (javax.transaction.RollbackException)8 XAResource (javax.transaction.xa.XAResource)8 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)7 HeuristicMixedException (javax.transaction.HeuristicMixedException)6 Test (org.junit.Test)6 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)6 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 HashMap (java.util.HashMap)5 XaResource (org.neo4j.kernel.impl.transaction.xaframework.XaResource)4 ArrayList (java.util.ArrayList)3 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)3 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)3 PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)3 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)3