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);
}
}
}
Aggregations