Search in sources :

Example 1 with GetInDoubtTxInfoCommand

use of org.infinispan.commands.remote.recovery.GetInDoubtTxInfoCommand in project infinispan by infinispan.

the class RecoveryManagerImpl method getInDoubtTransactionInfoFromCluster.

@Override
public Set<InDoubtTxInfo> getInDoubtTransactionInfoFromCluster() {
    Map<XidImpl, InDoubtTxInfo> result = new HashMap<>();
    if (rpcManager != null) {
        GetInDoubtTxInfoCommand inDoubtTxInfoCommand = commandFactory.buildGetInDoubtTxInfoCommand();
        CompletionStage<Map<Address, Response>> completionStage = rpcManager.invokeCommandOnAll(inDoubtTxInfoCommand, MapResponseCollector.ignoreLeavers(), rpcManager.getSyncRpcOptions());
        Map<Address, Response> addressResponseMap = rpcManager.blocking(completionStage);
        for (Map.Entry<Address, Response> re : addressResponseMap.entrySet()) {
            Response r = re.getValue();
            if (!isSuccessful(r)) {
                throw new CacheException("Could not fetch in doubt transactions: " + r);
            }
            // noinspection unchecked
            Set<InDoubtTxInfo> infoInDoubtSet = ((SuccessfulResponse<Set<InDoubtTxInfo>>) r).getResponseValue();
            for (InDoubtTxInfo infoInDoubt : infoInDoubtSet) {
                InDoubtTxInfo inDoubtTxInfo = result.get(infoInDoubt.getXid());
                if (inDoubtTxInfo == null) {
                    inDoubtTxInfo = infoInDoubt;
                    result.put(infoInDoubt.getXid(), inDoubtTxInfo);
                } else {
                    inDoubtTxInfo.setStatus(infoInDoubt.getStatus());
                }
                inDoubtTxInfo.addOwner(re.getKey());
            }
        }
    }
    Set<InDoubtTxInfo> onThisNode = getInDoubtTransactionInfo();
    Iterator<InDoubtTxInfo> iterator = onThisNode.iterator();
    while (iterator.hasNext()) {
        InDoubtTxInfo info = iterator.next();
        InDoubtTxInfo inDoubtTxInfo = result.get(info.getXid());
        if (inDoubtTxInfo != null) {
            inDoubtTxInfo.setLocal(true);
            iterator.remove();
        } else {
            info.setLocal(true);
        }
    }
    HashSet<InDoubtTxInfo> value = new HashSet<>(result.values());
    value.addAll(onThisNode);
    return value;
}
Also used : SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) Address(org.infinispan.remoting.transport.Address) HashMap(java.util.HashMap) CacheException(org.infinispan.commons.CacheException) XidImpl(org.infinispan.commons.tx.XidImpl) Response(org.infinispan.remoting.responses.Response) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) GetInDoubtTxInfoCommand(org.infinispan.commands.remote.recovery.GetInDoubtTxInfoCommand) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 GetInDoubtTxInfoCommand (org.infinispan.commands.remote.recovery.GetInDoubtTxInfoCommand)1 CacheException (org.infinispan.commons.CacheException)1 XidImpl (org.infinispan.commons.tx.XidImpl)1 Response (org.infinispan.remoting.responses.Response)1 SuccessfulResponse (org.infinispan.remoting.responses.SuccessfulResponse)1 Address (org.infinispan.remoting.transport.Address)1