Search in sources :

Example 1 with IterationStartOperation

use of org.infinispan.client.hotrod.impl.operations.IterationStartOperation in project keycloak by keycloak.

the class JDGPutTest method getIspnSegmentsCount.

protected static int getIspnSegmentsCount(RemoteCache remoteCache) {
    OperationsFactory operationsFactory = ((RemoteCacheImpl) remoteCache).getOperationsFactory();
    Map<SocketAddress, Set<Integer>> segmentsByAddress = operationsFactory.getPrimarySegmentsByAddress();
    for (Map.Entry<SocketAddress, Set<Integer>> entry : segmentsByAddress.entrySet()) {
        SocketAddress targetAddress = entry.getKey();
        // Same like RemoteCloseableIterator.startInternal
        IterationStartOperation iterationStartOperation = operationsFactory.newIterationStartOperation(null, null, null, 64, false, null, targetAddress);
        IterationStartResponse startResponse = await(iterationStartOperation.execute());
        try {
            // Could happen for non-clustered caches
            if (startResponse.getSegmentConsistentHash() == null) {
                return -1;
            } else {
                return startResponse.getSegmentConsistentHash().getNumSegments();
            }
        } finally {
            startResponse.getChannel().close();
        }
    }
    // Handle the case when primary segments owned by the address are not known
    return -1;
}
Also used : IterationStartResponse(org.infinispan.client.hotrod.impl.operations.IterationStartResponse) OperationsFactory(org.infinispan.client.hotrod.impl.operations.OperationsFactory) Set(java.util.Set) HashSet(java.util.HashSet) IterationStartOperation(org.infinispan.client.hotrod.impl.operations.IterationStartOperation) SocketAddress(java.net.SocketAddress) RemoteCacheImpl(org.infinispan.client.hotrod.impl.RemoteCacheImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with IterationStartOperation

use of org.infinispan.client.hotrod.impl.operations.IterationStartOperation in project keycloak by keycloak.

the class RemoteCacheSessionsLoader method getIspnSegmentsCount.

protected int getIspnSegmentsCount(RemoteCache remoteCache) {
    OperationsFactory operationsFactory = ((RemoteCacheImpl) remoteCache).getOperationsFactory();
    Map<SocketAddress, Set<Integer>> segmentsByAddress = operationsFactory.getPrimarySegmentsByAddress();
    for (Map.Entry<SocketAddress, Set<Integer>> entry : segmentsByAddress.entrySet()) {
        SocketAddress targetAddress = entry.getKey();
        // Same like RemoteCloseableIterator.startInternal
        IterationStartOperation iterationStartOperation = operationsFactory.newIterationStartOperation(null, null, null, sessionsPerSegment, false, null, targetAddress);
        IterationStartResponse startResponse = await(iterationStartOperation.execute());
        try {
            // Could happen for non-clustered caches
            if (startResponse.getSegmentConsistentHash() == null) {
                return -1;
            } else {
                return startResponse.getSegmentConsistentHash().getNumSegments();
            }
        } finally {
            startResponse.getChannel().close();
        }
    }
    // Handle the case when primary segments owned by the address are not known
    return -1;
}
Also used : IterationStartResponse(org.infinispan.client.hotrod.impl.operations.IterationStartResponse) OperationsFactory(org.infinispan.client.hotrod.impl.operations.OperationsFactory) Set(java.util.Set) HashSet(java.util.HashSet) IterationStartOperation(org.infinispan.client.hotrod.impl.operations.IterationStartOperation) SocketAddress(java.net.SocketAddress) RemoteCacheImpl(org.infinispan.client.hotrod.impl.RemoteCacheImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

SocketAddress (java.net.SocketAddress)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 RemoteCacheImpl (org.infinispan.client.hotrod.impl.RemoteCacheImpl)2 IterationStartOperation (org.infinispan.client.hotrod.impl.operations.IterationStartOperation)2 IterationStartResponse (org.infinispan.client.hotrod.impl.operations.IterationStartResponse)2 OperationsFactory (org.infinispan.client.hotrod.impl.operations.OperationsFactory)2