Search in sources :

Example 6 with DistributionManager

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);
    }
}
Also used : LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) DistributionManager(org.infinispan.distribution.DistributionManager)

Aggregations

DistributionManager (org.infinispan.distribution.DistributionManager)6 Address (org.infinispan.remoting.transport.Address)3 LocalizedCacheTopology (org.infinispan.distribution.LocalizedCacheTopology)2 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 PortalContainer (org.exoplatform.container.PortalContainer)1 ConfigurationManager (org.exoplatform.container.configuration.ConfigurationManager)1 ExoCacheConfig (org.exoplatform.services.cache.ExoCacheConfig)1 ExoCacheFactoryImpl (org.exoplatform.services.cache.impl.infinispan.ExoCacheFactoryImpl)1 DistributedCacheManager (org.exoplatform.services.ispn.DistributedCacheManager)1 KeyAffinityService (org.infinispan.affinity.KeyAffinityService)1 ConsistentHash (org.infinispan.distribution.ch.ConsistentHash)1 KeyPartitioner (org.infinispan.distribution.ch.KeyPartitioner)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1 CacheTopology (org.infinispan.topology.CacheTopology)1 PersistentUUID (org.infinispan.topology.PersistentUUID)1 Test (org.junit.Test)1 Key (org.wildfly.clustering.infinispan.spi.distribution.Key)1