Search in sources :

Example 1 with StateTransferManager

use of org.infinispan.statetransfer.StateTransferManager in project wildfly by wildfly.

the class TopologyChangeListenerBean method establishTopology.

@Override
public void establishTopology(String containerName, String cacheName, long timeout, String... nodes) throws InterruptedException {
    Set<String> expectedMembers = Stream.of(nodes).sorted().collect(Collectors.toSet());
    ServiceRegistry registry = CurrentServiceContainer.getServiceContainer();
    ServiceName name = ServiceName.parse(InfinispanCacheRequirement.CACHE.resolve(containerName, cacheName));
    Cache<?, ?> cache = ServiceContainerHelper.findValue(registry, name);
    if (cache == null) {
        throw new IllegalStateException(String.format("Cache %s not found", name));
    }
    cache.addListener(this);
    try {
        long start = System.currentTimeMillis();
        long now = start;
        long endTime = start + timeout;
        synchronized (this) {
            StateTransferManager transfer = cache.getAdvancedCache().getComponentRegistry().getStateTransferManager();
            CacheTopology topology = transfer.getCacheTopology();
            Set<String> members = getMembers(topology);
            while (!expectedMembers.equals(members)) {
                System.out.println(String.format("%s != %s, waiting for a topology change event. Current topology id = %d", expectedMembers, members, topology.getTopologyId()));
                this.wait(endTime - now);
                now = System.currentTimeMillis();
                if (now >= endTime) {
                    throw new InterruptedException(String.format("Cache %s/%s failed to establish view %s within %d ms.  Current view is: %s", containerName, cacheName, expectedMembers, timeout, members));
                }
                topology = transfer.getCacheTopology();
                members = getMembers(topology);
            }
            System.out.println(String.format("Cache %s/%s successfully established view %s within %d ms. Topology id = %d", containerName, cacheName, expectedMembers, now - start, topology.getTopologyId()));
        }
    } finally {
        cache.removeListener(this);
    }
}
Also used : CacheTopology(org.infinispan.topology.CacheTopology) ServiceName(org.jboss.msc.service.ServiceName) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) StateTransferManager(org.infinispan.statetransfer.StateTransferManager)

Aggregations

StateTransferManager (org.infinispan.statetransfer.StateTransferManager)1 CacheTopology (org.infinispan.topology.CacheTopology)1 ServiceName (org.jboss.msc.service.ServiceName)1 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)1