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);
}
}
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);
}
}
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);
}
}
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);
}
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();
}
Aggregations