use of org.infinispan.distribution.DistributionManager 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());
Cache<?, ?> cache = findCache(containerName, cacheName);
if (cache == null) {
throw new IllegalStateException(String.format("Cache %s.%s not found", containerName, cacheName));
}
cache.addListener(this);
try {
synchronized (this) {
DistributionManager dist = cache.getAdvancedCache().getDistributionManager();
LocalizedCacheTopology topology = dist.getCacheTopology();
Set<String> members = getMembers(topology);
long start = System.currentTimeMillis();
long now = start;
long endTime = start + timeout;
while (!expectedMembers.equals(members)) {
logger.infof("%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 = dist.getCacheTopology();
members = getMembers(topology);
}
logger.infof("Cache %s/%s successfully established view %s within %d ms. Topology id = %d", containerName, cacheName, expectedMembers, now - start, topology.getTopologyId());
}
} finally {
cache.removeListener(this);
}
}
Aggregations