use of org.infinispan.affinity.KeyAffinityService in project wildfly by wildfly.
the class KeyAffinityServiceFactoryBuilder method build.
@Override
public ServiceBuilder<KeyAffinityServiceFactory> build(ServiceTarget target) {
int bufferSize = this.bufferSize;
Function<ExecutorService, KeyAffinityServiceFactory> mapper = executor -> new KeyAffinityServiceFactory() {
@Override
public <K> KeyAffinityService<K> createService(Cache<K, ?> cache, KeyGenerator<K> generator) {
CacheMode mode = cache.getCacheConfiguration().clustering().cacheMode();
return mode.isDistributed() || mode.isReplicated() ? new KeyAffinityServiceImpl<>(executor, cache, generator, bufferSize, Collections.singleton(cache.getCacheManager().getAddress()), false) : new SimpleKeyAffinityService<>(generator);
}
};
Supplier<ExecutorService> supplier = () -> {
ThreadGroup threadGroup = new ThreadGroup("KeyAffinityService ThreadGroup");
String namePattern = "KeyAffinityService Thread Pool -- %t";
PrivilegedAction<ThreadFactory> action = () -> new JBossThreadFactory(threadGroup, Boolean.FALSE, null, namePattern, null, null);
return Executors.newCachedThreadPool(doPrivileged(action));
};
Service<KeyAffinityServiceFactory> service = new SuppliedValueService<>(mapper, supplier, ExecutorService::shutdown);
return new AsynchronousServiceBuilder<>(this.getServiceName(), service).startSynchronously().build(target).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
Aggregations