Search in sources :

Example 1 with SuppliedValueService

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);
}
Also used : Service(org.jboss.msc.service.Service) AccessController.doPrivileged(java.security.AccessController.doPrivileged) Cache(org.infinispan.Cache) Function(java.util.function.Function) Supplier(java.util.function.Supplier) KeyGenerator(org.infinispan.affinity.KeyGenerator) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService) KeyAffinityService(org.infinispan.affinity.KeyAffinityService) KeyAffinityServiceFactory(org.wildfly.clustering.infinispan.spi.affinity.KeyAffinityServiceFactory) ServiceTarget(org.jboss.msc.service.ServiceTarget) ThreadFactory(java.util.concurrent.ThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) Address(org.infinispan.remoting.transport.Address) JBossThreadFactory(org.jboss.threads.JBossThreadFactory) PathAddress(org.jboss.as.controller.PathAddress) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) AsynchronousServiceBuilder(org.wildfly.clustering.service.AsynchronousServiceBuilder) PrivilegedAction(java.security.PrivilegedAction) Executors(java.util.concurrent.Executors) KeyAffinityServiceImpl(org.infinispan.affinity.impl.KeyAffinityServiceImpl) ServiceController(org.jboss.msc.service.ServiceController) CacheMode(org.infinispan.configuration.cache.CacheMode) ServiceName(org.jboss.msc.service.ServiceName) Collections(java.util.Collections) Builder(org.wildfly.clustering.service.Builder) JBossThreadFactory(org.jboss.threads.JBossThreadFactory) CacheMode(org.infinispan.configuration.cache.CacheMode) KeyAffinityServiceFactory(org.wildfly.clustering.infinispan.spi.affinity.KeyAffinityServiceFactory) PrivilegedAction(java.security.PrivilegedAction) ExecutorService(java.util.concurrent.ExecutorService) KeyGenerator(org.infinispan.affinity.KeyGenerator) Cache(org.infinispan.Cache) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService)

Example 2 with SuppliedValueService

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);
}
Also used : Service(org.jboss.msc.service.Service) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) AsynchronousServiceBuilder(org.wildfly.clustering.service.AsynchronousServiceBuilder) Function(java.util.function.Function) Supplier(java.util.function.Supplier) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService) ServiceController(org.jboss.msc.service.ServiceController) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ServiceName(org.jboss.msc.service.ServiceName) ServiceTarget(org.jboss.msc.service.ServiceTarget) JBossExecutors(org.jboss.threads.JBossExecutors) ThreadFactory(java.util.concurrent.ThreadFactory) Builder(org.wildfly.clustering.service.Builder) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService)

Example 3 with SuppliedValueService

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);
}
Also used : ValueDependency(org.wildfly.clustering.service.ValueDependency) Service(org.jboss.msc.service.Service) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) DefaultCacheContainer(org.jboss.as.clustering.infinispan.DefaultCacheContainer) InfinispanBatcherFactory(org.jboss.as.clustering.infinispan.InfinispanBatcherFactory) CacheContainer(org.wildfly.clustering.infinispan.spi.CacheContainer) Function(java.util.function.Function) Supplier(java.util.function.Supplier) CacheStoppedEvent(org.infinispan.notifications.cachemanagerlistener.event.CacheStoppedEvent) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService) ALIASES(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.Attribute.ALIASES) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) OperationContext(org.jboss.as.controller.OperationContext) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) InfinispanLogger(org.jboss.as.clustering.infinispan.InfinispanLogger) InfinispanRequirement(org.wildfly.clustering.infinispan.spi.InfinispanRequirement) CacheStopped(org.infinispan.notifications.cachemanagerlistener.annotation.CacheStopped) CacheStartedEvent(org.infinispan.notifications.cachemanagerlistener.event.CacheStartedEvent) InjectedValueDependency(org.wildfly.clustering.service.InjectedValueDependency) ServiceTarget(org.jboss.msc.service.ServiceTarget) LinkedList(java.util.LinkedList) BatcherFactory(org.jboss.as.clustering.infinispan.BatcherFactory) BasicCacheContainer(org.infinispan.commons.api.BasicCacheContainer) Listener(org.infinispan.notifications.Listener) CONTAINER(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.Capability.CONTAINER) PathAddress(org.jboss.as.controller.PathAddress) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ResourceServiceBuilder(org.jboss.as.clustering.controller.ResourceServiceBuilder) Consumer(java.util.function.Consumer) ModelNodes(org.jboss.as.clustering.dmr.ModelNodes) CacheStarted(org.infinispan.notifications.cachemanagerlistener.annotation.CacheStarted) ServiceController(org.jboss.msc.service.ServiceController) List(java.util.List) DEFAULT_CACHE(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.Attribute.DEFAULT_CACHE) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceName(org.jboss.msc.service.ServiceName) ModelNode(org.jboss.dmr.ModelNode) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) DefaultCacheContainer(org.jboss.as.clustering.infinispan.DefaultCacheContainer) DefaultCacheContainer(org.jboss.as.clustering.infinispan.DefaultCacheContainer) CacheContainer(org.wildfly.clustering.infinispan.spi.CacheContainer) BasicCacheContainer(org.infinispan.commons.api.BasicCacheContainer) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService)

Aggregations

Function (java.util.function.Function)3 Supplier (java.util.function.Supplier)3 Service (org.jboss.msc.service.Service)3 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)3 ServiceController (org.jboss.msc.service.ServiceController)3 ServiceName (org.jboss.msc.service.ServiceName)3 ServiceTarget (org.jboss.msc.service.ServiceTarget)3 SuppliedValueService (org.wildfly.clustering.service.SuppliedValueService)3 ThreadFactory (java.util.concurrent.ThreadFactory)2 PathAddress (org.jboss.as.controller.PathAddress)2 AsynchronousServiceBuilder (org.wildfly.clustering.service.AsynchronousServiceBuilder)2 Builder (org.wildfly.clustering.service.Builder)2 AccessController.doPrivileged (java.security.AccessController.doPrivileged)1 PrivilegedAction (java.security.PrivilegedAction)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1