Search in sources :

Example 1 with ConsistentHashKeyDistribution

use of org.wildfly.clustering.infinispan.spi.distribution.ConsistentHashKeyDistribution in project wildfly by wildfly.

the class DefaultKeyAffinityService method accept.

private void accept(ConsistentHash hash) {
    KeyDistribution distribution = new ConsistentHashKeyDistribution(this.partitioner, hash);
    KeyRegistry<K> registry = new ConsistentHashKeyRegistry<>(hash, this.filter, this);
    Set<Address> addresses = registry.getAddresses();
    List<Future<?>> futures = !addresses.isEmpty() ? new ArrayList<>(addresses.size()) : Collections.emptyList();
    try {
        for (Address address : addresses) {
            BlockingQueue<K> keys = registry.getKeys(address);
            futures.add(this.executor.submit(new GenerateKeysTask<>(this.generator, distribution, address, keys)));
        }
        KeyAffinityState<K> previousState = this.currentState.getAndSet(new KeyAffinityState<K>() {

            @Override
            public KeyDistribution getDistribution() {
                return distribution;
            }

            @Override
            public KeyRegistry<K> getRegistry() {
                return registry;
            }

            @Override
            public Iterable<Future<?>> getFutures() {
                return futures;
            }
        });
        if (previousState != null) {
            for (Future<?> future : previousState.getFutures()) {
                future.cancel(true);
            }
        }
    } catch (RejectedExecutionException e) {
        // Executor was shutdown. Cancel any tasks that were already submitted
        for (Future<?> future : futures) {
            future.cancel(true);
        }
    }
}
Also used : Address(org.infinispan.remoting.transport.Address) KeyDistribution(org.wildfly.clustering.infinispan.spi.distribution.KeyDistribution) ConsistentHashKeyDistribution(org.wildfly.clustering.infinispan.spi.distribution.ConsistentHashKeyDistribution) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ConsistentHashKeyDistribution(org.wildfly.clustering.infinispan.spi.distribution.ConsistentHashKeyDistribution) Future(java.util.concurrent.Future)

Aggregations

Future (java.util.concurrent.Future)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 Address (org.infinispan.remoting.transport.Address)1 ConsistentHashKeyDistribution (org.wildfly.clustering.infinispan.spi.distribution.ConsistentHashKeyDistribution)1 KeyDistribution (org.wildfly.clustering.infinispan.spi.distribution.KeyDistribution)1