public XAService(NodeEngineImpl nodeEngine) { this.nodeEngine = nodeEngine; this.xaResource = new XAResourceImpl(nodeEngine, this); }
@Override public void rollback(Xid xid) throws XAException { List<TransactionContext> contexts = xidContextMap.remove(xid); if (contexts == null) { finalizeTransactionRemotely(xid, false); return; } for (TransactionContext context : contexts) { getTransaction(context).rollback(); } clearRemoteTransactions(xid); }
private TransactionContext createTransactionContext(Xid xid) { XAService xaService = getService(); TransactionContext context = xaService.newXATransactionContext(xid, null, timeoutInSeconds.get(), false); getTransaction(context).begin(); return context; }
@Override public void start(Xid xid, int flags) throws XAException { long threadId = currentThreadId(); TransactionContext threadContext = threadContextMap.get(currentThreadId()); switch (flags) { case TMNOFLAGS: throw new XAException("There is already TransactionContexts for the given xid: " + xid); TransactionContext context = createTransactionContext(xid); contexts.add(context); threadContextMap.put(threadId, context); threadContext = createTransactionContext(xid); threadContextMap.put(threadId, threadContext); contextList.add(threadContext);
@Override public Xid[] recover(int flag) throws XAException { NodeEngine nodeEngine = getNodeEngine(); XAService xaService = getService(); OperationService operationService = nodeEngine.getOperationService(); ClusterService clusterService = nodeEngine.getClusterService();
private void clearRemoteTransactions(Xid xid) { NodeEngine nodeEngine = getNodeEngine(); IPartitionService partitionService = nodeEngine.getPartitionService(); OperationService operationService = nodeEngine.getOperationService(); SerializableXID serializableXID = new SerializableXID(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier()); Data xidData = nodeEngine.toData(serializableXID); int partitionId = partitionService.getPartitionId(xidData); ClearRemoteTransactionOperation operation = new ClearRemoteTransactionOperation(xidData); operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId); }
@Override public void end(Xid xid, int flags) throws XAException { long threadId = currentThreadId(); TransactionContext threadContext = threadContextMap.remove(threadId); if (threadContext == null && logger.isFinestEnabled()) { logger.finest("There is no TransactionContext for the current thread: " + threadId); } List<TransactionContext> contexts = xidContextMap.get(xid); if (contexts == null && logger.isFinestEnabled()) { logger.finest("There is no TransactionContexts for the given xid: " + xid); } }
@Override public void forget(Xid xid) throws XAException { List<TransactionContext> contexts = xidContextMap.remove(xid); if (contexts == null) { throw new XAException("No context with the given xid: " + xid); } clearRemoteTransactions(xid); }
@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; }
@Override public boolean isSameRM(XAResource xaResource) throws XAException { if (this == xaResource) { return true; } String otherGroupName = null; if (xaResource instanceof XAResourceProxy) { otherGroupName = ((XAResourceProxy) xaResource).getGroupName(); } if (xaResource instanceof XAResourceImpl) { otherGroupName = ((XAResourceImpl) xaResource).getGroupName(); } return getGroupName().equals(otherGroupName); }
@Override public void start(Xid xid, int flags) throws XAException { long threadId = currentThreadId(); TransactionContext threadContext = threadContextMap.get(currentThreadId()); switch (flags) { case TMNOFLAGS: throw new XAException("There is already TransactionContexts for the given xid: " + xid); TransactionContext context = createTransactionContext(xid); contexts.add(context); threadContextMap.put(threadId, context); threadContext = createTransactionContext(xid); threadContextMap.put(threadId, threadContext); contextList.add(threadContext);
@Override public Xid[] recover(int flag) throws XAException { NodeEngine nodeEngine = getNodeEngine(); XAService xaService = getService(); OperationService operationService = nodeEngine.getOperationService(); ClusterService clusterService = nodeEngine.getClusterService();
private void clearRemoteTransactions(Xid xid) { NodeEngine nodeEngine = getNodeEngine(); IPartitionService partitionService = nodeEngine.getPartitionService(); OperationService operationService = nodeEngine.getOperationService(); SerializableXID serializableXID = new SerializableXID(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier()); Data xidData = nodeEngine.toData(serializableXID); int partitionId = partitionService.getPartitionId(xidData); ClearRemoteTransactionOperation operation = new ClearRemoteTransactionOperation(xidData); operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId); }
@Override public void end(Xid xid, int flags) throws XAException { long threadId = currentThreadId(); TransactionContext threadContext = threadContextMap.remove(threadId); if (threadContext == null && logger.isFinestEnabled()) { logger.finest("There is no TransactionContext for the current thread: " + threadId); } List<TransactionContext> contexts = xidContextMap.get(xid); if (contexts == null && logger.isFinestEnabled()) { logger.finest("There is no TransactionContexts for the given xid: " + xid); } }
@Override public void forget(Xid xid) throws XAException { List<TransactionContext> contexts = xidContextMap.remove(xid); if (contexts == null) { throw new XAException("No context with the given xid: " + xid); } clearRemoteTransactions(xid); }
@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; }
@Override public boolean isSameRM(XAResource xaResource) throws XAException { if (this == xaResource) { return true; } String otherGroupName = null; if (xaResource instanceof XAResourceProxy) { otherGroupName = ((XAResourceProxy) xaResource).getGroupName(); } if (xaResource instanceof XAResourceImpl) { otherGroupName = ((XAResourceImpl) xaResource).getGroupName(); } return getGroupName().equals(otherGroupName); }
@Override public void rollback(Xid xid) throws XAException { List<TransactionContext> contexts = xidContextMap.remove(xid); if (contexts == null) { finalizeTransactionRemotely(xid, false); return; } for (TransactionContext context : contexts) { getTransaction(context).rollback(); } clearRemoteTransactions(xid); }
private TransactionContext createTransactionContext(Xid xid) { XAService xaService = getService(); TransactionContext context = xaService.newXATransactionContext(xid, null, timeoutInSeconds.get(), false); getTransaction(context).begin(); return context; }
private void finalizeTransactionRemotely(Xid xid, boolean isCommit) throws XAException { NodeEngine nodeEngine = getNodeEngine(); IPartitionService partitionService = nodeEngine.getPartitionService(); OperationService operationService = nodeEngine.getOperationService(); SerializableXID serializableXID = new SerializableXID(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier()); Data xidData = nodeEngine.toData(serializableXID); int partitionId = partitionService.getPartitionId(xidData); FinalizeRemoteTransactionOperation operation = new FinalizeRemoteTransactionOperation(xidData, isCommit); InternalCompletableFuture<Integer> future = operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId); Integer errorCode; try { errorCode = future.get(); } catch (Exception e) { throw ExceptionUtil.rethrow(e); } if (errorCode != null) { throw new XAException(errorCode); } }