use of javax.transaction.xa.XAException in project hazelcast by hazelcast.
the class XAResourceImpl method recover.
@Override
public Xid[] recover(int flag) throws XAException {
NodeEngine nodeEngine = getNodeEngine();
XAService xaService = getService();
OperationService operationService = nodeEngine.getOperationService();
ClusterService clusterService = nodeEngine.getClusterService();
Collection<Member> memberList = clusterService.getMembers();
List<Future<SerializableList>> futureList = new ArrayList<Future<SerializableList>>();
for (Member member : memberList) {
if (member.localMember()) {
continue;
}
CollectRemoteTransactionsOperation op = new CollectRemoteTransactionsOperation();
Address address = member.getAddress();
InternalCompletableFuture<SerializableList> future = operationService.invokeOnTarget(SERVICE_NAME, op, address);
futureList.add(future);
}
HashSet<SerializableXID> xids = new HashSet<SerializableXID>();
xids.addAll(xaService.getPreparedXids());
for (Future<SerializableList> future : futureList) {
try {
SerializableList xidSet = future.get();
for (Data xidData : xidSet) {
SerializableXID xid = nodeEngine.toObject(xidData);
xids.add(xid);
}
} catch (InterruptedException e) {
throw new XAException(XAException.XAER_RMERR);
} catch (MemberLeftException e) {
logger.warning("Member left while recovering", e);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof HazelcastInstanceNotActiveException || cause instanceof TargetNotMemberException) {
logger.warning("Member left while recovering", e);
} else {
throw new XAException(XAException.XAER_RMERR);
}
}
}
return xids.toArray(new SerializableXID[xids.size()]);
}
use of javax.transaction.xa.XAException in project hazelcast by hazelcast.
the class XAResourceImpl method prepare.
@Override
public int prepare(Xid xid) throws XAException {
List<TransactionContext> contexts = xidContextMap.get(xid);
if (contexts == null) {
throw new XAException("There is no TransactionContexts for the given xid: " + xid);
}
for (TransactionContext context : contexts) {
Transaction transaction = getTransaction(context);
transaction.prepare();
}
return XA_OK;
}
use of javax.transaction.xa.XAException in project hazelcast by hazelcast.
the class ClientXACompatibilityTest 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 XAResourceProxy method prepare.
@Override
public int prepare(Xid xid) throws XAException {
List<TransactionContext> contexts = xidContextMap.get(xid);
if (contexts == null) {
throw new XAException("There is no TransactionContexts for the given xid: " + xid);
}
for (TransactionContext context : contexts) {
XATransactionProxy transaction = getTransaction(context);
transaction.prepare();
}
return XA_OK;
}
use of javax.transaction.xa.XAException in project hazelcast by hazelcast.
the class XAResourceProxy method commit.
@Override
public void commit(Xid xid, boolean onePhase) throws XAException {
List<TransactionContext> contexts = xidContextMap.remove(xid);
if (contexts == null && onePhase) {
throw new XAException("There is no TransactionContexts for the given xid: " + xid);
}
if (contexts == null) {
finalizeTransactionRemotely(xid, true);
return;
}
for (TransactionContext context : contexts) {
XATransactionProxy transaction = getTransaction(context);
transaction.commit(onePhase);
}
clearRemoteTransactions(xid);
}
Aggregations