Search in sources :

Example 1 with JBossThreadFactory

use of org.jboss.threads.JBossThreadFactory 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 JBossThreadFactory

use of org.jboss.threads.JBossThreadFactory in project wildfly by wildfly.

the class UndertowEventHandlerAdapter method start.

@Override
public void start(StartContext context) {
    UndertowService service = this.service.getValue();
    ContainerEventHandler eventHandler = this.eventHandler.getValue();
    this.connector = new UndertowConnector(this.listener.getValue());
    this.server = new UndertowServer(service, 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);
    // Start the periodic STATUS thread
    ThreadGroup group = new ThreadGroup(UndertowEventHandlerAdapter.class.getSimpleName());
    ThreadFactory factory = doPrivileged(new PrivilegedAction<ThreadFactory>() {

        public ThreadFactory run() {
            return new JBossThreadFactory(group, Boolean.FALSE, null, "%G - %t", null, null);
        }
    });
    this.executor = Executors.newScheduledThreadPool(1, factory);
    this.executor.scheduleWithFixedDelay(this, 0, statusInterval, TimeUnit.SECONDS);
    suspendController.getValue().registerActivity(this);
}
Also used : ContainerEventHandler(org.jboss.modcluster.container.ContainerEventHandler) ThreadFactory(java.util.concurrent.ThreadFactory) JBossThreadFactory(org.jboss.threads.JBossThreadFactory) JBossThreadFactory(org.jboss.threads.JBossThreadFactory) UndertowService(org.wildfly.extension.undertow.UndertowService)

Example 3 with JBossThreadFactory

use of org.jboss.threads.JBossThreadFactory in project wildfly by wildfly.

the class WeldExecutorServices method start.

@Override
public void start(final StartContext context) throws StartException {
    final ThreadGroup threadGroup = new ThreadGroup("Weld ThreadGroup");
    final ThreadFactory factory = new JBossThreadFactory(threadGroup, Boolean.FALSE, null, THREAD_NAME_PATTERN, null, null);
    // set TCCL to null for new threads to make sure no deployment classloader leaks through this executor's TCCL
    // Weld does not mind having null TCCL in this executor
    this.executor = new WeldExecutor(bound, runnable -> {
        Thread thread = factory.newThread(runnable);
        if (WildFlySecurityManager.isChecking()) {
            AccessController.doPrivileged(new PrivilegedAction<Void>() {

                public Void run() {
                    thread.setContextClassLoader(null);
                    return null;
                }
            });
        } else {
            thread.setContextClassLoader(null);
        }
        return thread;
    });
    if (executorServicesConsumer != null)
        executorServicesConsumer.accept(this);
}
Also used : JBossThreadFactory(org.jboss.threads.JBossThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) StopContext(org.jboss.msc.service.StopContext) StartContext(org.jboss.msc.service.StartContext) NamespaceContextSelector(org.jboss.as.naming.context.NamespaceContextSelector) Service(org.jboss.msc.Service) PrivilegedAction(java.security.PrivilegedAction) AbstractExecutorServices(org.jboss.weld.executor.AbstractExecutorServices) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Services(org.jboss.as.server.Services) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ExecutorServices(org.jboss.weld.manager.api.ExecutorServices) WildFlySecurityManager(org.wildfly.security.manager.WildFlySecurityManager) ServiceName(org.jboss.msc.service.ServiceName) ContainerState(org.jboss.weld.ContainerState) AccessController(java.security.AccessController) ThreadFactory(java.util.concurrent.ThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) Container(org.jboss.weld.Container) StartException(org.jboss.msc.service.StartException) JBossThreadFactory(org.jboss.threads.JBossThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) JBossThreadFactory(org.jboss.threads.JBossThreadFactory) PrivilegedAction(java.security.PrivilegedAction)

Example 4 with JBossThreadFactory

use of org.jboss.threads.JBossThreadFactory in project wildfly by wildfly.

the class JdrReportService method start.

public synchronized void start(StartContext context) throws StartException {
    final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<JBossThreadFactory>() {

        public JBossThreadFactory run() {
            return new JBossThreadFactory(new ThreadGroup("JdrReportCollector-threads"), Boolean.FALSE, null, "%G - %t", null, null);
        }
    });
    executorService = Executors.newCachedThreadPool(threadFactory);
    serverEnvironment = serverEnvironmentValue.getValue();
    controllerClient = modelControllerValue.getValue().createClient(executorService);
}
Also used : JBossThreadFactory(org.jboss.threads.JBossThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) JBossThreadFactory(org.jboss.threads.JBossThreadFactory)

Example 5 with JBossThreadFactory

use of org.jboss.threads.JBossThreadFactory in project wildfly by wildfly.

the class AbstractResourceAdapterDeploymentService method getLifecycleExecutorService.

protected final ExecutorService getLifecycleExecutorService() {
    ExecutorService result = executorServiceInjector.getOptionalValue();
    if (result == null) {
        // We added injection of the server executor late in WF 8, so in case some
        // add-on projects don't know to inject it....
        final ThreadGroup threadGroup = new ThreadGroup("ResourceAdapterDeploymentService ThreadGroup");
        final String namePattern = "ResourceAdapterDeploymentService Thread Pool -- %t";
        final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<JBossThreadFactory>() {

            public JBossThreadFactory run() {
                return new JBossThreadFactory(threadGroup, Boolean.FALSE, null, namePattern, null, null);
            }
        });
        result = Executors.newSingleThreadExecutor(threadFactory);
    }
    return result;
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) JBossThreadFactory(org.jboss.threads.JBossThreadFactory) JBossThreadFactory(org.jboss.threads.JBossThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) XsdString(org.jboss.jca.common.api.metadata.spec.XsdString)

Aggregations

ThreadFactory (java.util.concurrent.ThreadFactory)5 JBossThreadFactory (org.jboss.threads.JBossThreadFactory)5 ExecutorService (java.util.concurrent.ExecutorService)3 PrivilegedAction (java.security.PrivilegedAction)2 ServiceName (org.jboss.msc.service.ServiceName)2 AccessController (java.security.AccessController)1 AccessController.doPrivileged (java.security.AccessController.doPrivileged)1 Collections (java.util.Collections)1 Executors (java.util.concurrent.Executors)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 TimeUnit (java.util.concurrent.TimeUnit)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 Cache (org.infinispan.Cache)1 KeyAffinityService (org.infinispan.affinity.KeyAffinityService)1 KeyGenerator (org.infinispan.affinity.KeyGenerator)1 KeyAffinityServiceImpl (org.infinispan.affinity.impl.KeyAffinityServiceImpl)1 CacheMode (org.infinispan.configuration.cache.CacheMode)1