Search in sources :

Example 1 with DefaultThreadFactory

use of org.jboss.as.clustering.context.DefaultThreadFactory in project wildfly by wildfly.

the class ScheduledThreadPoolServiceConfigurator method configure.

@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
    int minThreads = this.definition.getMinThreads().resolveModelAttribute(context, model).asInt();
    long keepAliveTime = this.definition.getKeepAliveTime().resolveModelAttribute(context, model).asLong();
    ThreadPoolExecutorFactory<?> factory = new ThreadPoolExecutorFactory<ScheduledExecutorService>() {

        @Override
        public ScheduledExecutorService createExecutor(ThreadFactory factory) {
            // Use fixed size, based on maxThreads
            ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(minThreads, new DefaultThreadFactory(factory));
            executor.setKeepAliveTime(keepAliveTime, TimeUnit.MILLISECONDS);
            executor.setRemoveOnCancelPolicy(true);
            executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
            return executor;
        }

        @Override
        public void validate() {
        // Do nothing
        }
    };
    this.builder.threadPoolFactory(factory);
    return this;
}
Also used : DefaultThreadFactory(org.jboss.as.clustering.context.DefaultThreadFactory) DefaultThreadFactory(org.jboss.as.clustering.context.DefaultThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) ThreadPoolExecutorFactory(org.infinispan.commons.executors.ThreadPoolExecutorFactory) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor)

Example 2 with DefaultThreadFactory

use of org.jboss.as.clustering.context.DefaultThreadFactory in project wildfly by wildfly.

the class CacheContainerServiceConfigurator method get.

@Override
public EmbeddedCacheManager get() {
    GlobalConfiguration config = this.configuration.get();
    String defaultCacheName = config.defaultCacheName().orElse(null);
    ConfigurationBuilderHolder holder = new ConfigurationBuilderHolder(config.classLoader(), new GlobalConfigurationBuilder().read(config));
    // We need to create a dummy default configuration if cache has a default cache
    if (defaultCacheName != null) {
        holder.newConfigurationBuilder(defaultCacheName);
    }
    EmbeddedCacheManager manager = new DefaultCacheManager(holder, false);
    // Undefine the default cache, if we defined one
    if (defaultCacheName != null) {
        manager.undefineConfiguration(defaultCacheName);
    }
    manager.start();
    // Must create executor before registering cache listener
    this.executor = Executors.newSingleThreadExecutor(new DefaultThreadFactory(this.getClass()));
    manager.addListener(this);
    InfinispanLogger.ROOT_LOGGER.debugf("%s cache container started", this.name);
    return manager;
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) DefaultThreadFactory(org.jboss.as.clustering.context.DefaultThreadFactory) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Example 3 with DefaultThreadFactory

use of org.jboss.as.clustering.context.DefaultThreadFactory in project wildfly by wildfly.

the class ClientThreadPoolServiceConfigurator method configure.

@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
    int maxThreads = this.definition.getMaxThreads().resolveModelAttribute(context, model).asInt();
    int minThreads = this.definition.getMinThreads().resolveModelAttribute(context, model).asInt();
    int queueLength = this.definition.getQueueLength().resolveModelAttribute(context, model).asInt();
    long keepAliveTime = this.definition.getKeepAliveTime().resolveModelAttribute(context, model).asLong();
    boolean nonBlocking = this.definition.isNonBlocking();
    this.factory = new ExecutorFactory() {

        @Override
        public ExecutorService getExecutor(Properties property) {
            BlockingQueue<Runnable> queue = queueLength == 0 ? new SynchronousQueue<>() : new LinkedBlockingQueue<>(queueLength);
            ThreadFactory factory = new DefaultThreadFactory(new DaemonThreadFactory(DefaultAsyncExecutorFactory.THREAD_NAME));
            if (nonBlocking) {
                factory = new DefaultNonBlockingThreadFactory(factory);
            }
            RejectedExecutionHandler handler = nonBlocking ? NonBlockingRejectedExecutionHandler.getInstance() : BlockingRejectedExecutionHandler.getInstance();
            return new ThreadPoolExecutor(minThreads, maxThreads, keepAliveTime, TimeUnit.MILLISECONDS, queue, factory, handler);
        }
    };
    return this;
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) DefaultNonBlockingThreadFactory(org.wildfly.clustering.infinispan.spi.DefaultNonBlockingThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) DefaultThreadFactory(org.jboss.as.clustering.context.DefaultThreadFactory) NonBlockingRejectedExecutionHandler(org.infinispan.commons.util.concurrent.NonBlockingRejectedExecutionHandler) BlockingRejectedExecutionHandler(org.infinispan.commons.util.concurrent.BlockingRejectedExecutionHandler) RejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler) Properties(java.util.Properties) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) DefaultThreadFactory(org.jboss.as.clustering.context.DefaultThreadFactory) ExecutorFactory(org.infinispan.commons.executors.ExecutorFactory) DefaultAsyncExecutorFactory(org.infinispan.client.hotrod.impl.async.DefaultAsyncExecutorFactory) SynchronousQueue(java.util.concurrent.SynchronousQueue) ExecutorService(java.util.concurrent.ExecutorService) DefaultNonBlockingThreadFactory(org.wildfly.clustering.infinispan.spi.DefaultNonBlockingThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 4 with DefaultThreadFactory

use of org.jboss.as.clustering.context.DefaultThreadFactory in project wildfly by wildfly.

the class UndertowEventHandlerAdapterService method start.

@Override
public void start(StartContext context) {
    UndertowService service = this.configuration.getUndertowService();
    ContainerEventHandler eventHandler = this.configuration.getContainerEventHandler();
    this.connector = new UndertowConnector(this.configuration.getListener());
    this.serverName = this.configuration.getServer().getName();
    this.server = new UndertowServer(this.serverName, service, this.connector);
    // Register ourselves as a listener to the container events
    service.registerListener(this);
    // Initialize mod_cluster and start it now
    eventHandler.init(this.server);
    eventHandler.start(this.server);
    for (Engine engine : this.server.getEngines()) {
        for (org.jboss.modcluster.container.Host host : engine.getHosts()) {
            host.getContexts().forEach(c -> contexts.add(c));
        }
    }
    // Start the periodic STATUS thread
    this.executor = Executors.newScheduledThreadPool(1, new DefaultThreadFactory(UndertowEventHandlerAdapterService.class));
    this.executor.scheduleWithFixedDelay(this, 0, this.configuration.getStatusInterval().toMillis(), TimeUnit.MILLISECONDS);
    this.configuration.getSuspendController().registerActivity(this);
}
Also used : DefaultThreadFactory(org.jboss.as.clustering.context.DefaultThreadFactory) ContainerEventHandler(org.jboss.modcluster.container.ContainerEventHandler) Engine(org.jboss.modcluster.container.Engine) UndertowService(org.wildfly.extension.undertow.UndertowService)

Aggregations

DefaultThreadFactory (org.jboss.as.clustering.context.DefaultThreadFactory)4 ThreadFactory (java.util.concurrent.ThreadFactory)2 Properties (java.util.Properties)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 ExecutorService (java.util.concurrent.ExecutorService)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 SynchronousQueue (java.util.concurrent.SynchronousQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 DefaultAsyncExecutorFactory (org.infinispan.client.hotrod.impl.async.DefaultAsyncExecutorFactory)1 ExecutorFactory (org.infinispan.commons.executors.ExecutorFactory)1 ThreadPoolExecutorFactory (org.infinispan.commons.executors.ThreadPoolExecutorFactory)1 BlockingRejectedExecutionHandler (org.infinispan.commons.util.concurrent.BlockingRejectedExecutionHandler)1 NonBlockingRejectedExecutionHandler (org.infinispan.commons.util.concurrent.NonBlockingRejectedExecutionHandler)1 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)1 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)1 ConfigurationBuilderHolder (org.infinispan.configuration.parsing.ConfigurationBuilderHolder)1 DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1