use of org.wildfly.clustering.service.SuppliedValueService 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);
}
use of org.wildfly.clustering.service.SuppliedValueService in project wildfly by wildfly.
the class RemoveOnCancelScheduledExecutorServiceBuilder method build.
@Override
public ServiceBuilder<ScheduledExecutorService> build(ServiceTarget target) {
Function<ScheduledExecutorService, ScheduledExecutorService> mapper = executor -> JBossExecutors.protectedScheduledExecutorService(executor);
Supplier<ScheduledExecutorService> supplier = () -> {
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(this.size, this.factory);
executor.setRemoveOnCancelPolicy(true);
executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
return executor;
};
Service<ScheduledExecutorService> service = new SuppliedValueService<>(mapper, supplier, ScheduledExecutorService::shutdown);
return new AsynchronousServiceBuilder<>(this.name, service).startSynchronously().build(target).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
use of org.wildfly.clustering.service.SuppliedValueService in project wildfly by wildfly.
the class CacheContainerBuilder method build.
@Override
public ServiceBuilder<CacheContainer> build(ServiceTarget target) {
Function<EmbeddedCacheManager, CacheContainer> mapper = manager -> new DefaultCacheContainer(this.name, manager, this.defaultCache, this.batcherFactory);
Supplier<EmbeddedCacheManager> supplier = () -> {
GlobalConfiguration config = this.configuration.getValue();
EmbeddedCacheManager manager = new DefaultCacheManager(config, null, false);
manager.addListener(this);
manager.start();
InfinispanLogger.ROOT_LOGGER.debugf("%s cache container started", this.name);
return manager;
};
Consumer<EmbeddedCacheManager> destroyer = manager -> {
manager.stop();
manager.removeListener(this);
InfinispanLogger.ROOT_LOGGER.debugf("%s cache container stopped", this.name);
};
Service<CacheContainer> service = new SuppliedValueService<>(mapper, supplier, destroyer);
ServiceBuilder<CacheContainer> builder = target.addService(this.getServiceName(), service).addAliases(this.aliases.stream().toArray(ServiceName[]::new)).setInitialMode(ServiceController.Mode.PASSIVE);
return this.configuration.register(builder);
}
Aggregations