Search in sources :

Example 1 with ThreadPoolConfiguration

use of org.infinispan.configuration.global.ThreadPoolConfiguration in project infinispan by infinispan.

the class Parser method createThreadPoolConfiguration.

private ThreadPoolConfiguration createThreadPoolConfiguration(String threadPoolName, String componentName, ConfigurationBuilderHolder holder) {
    ThreadsConfigurationBuilder threads = holder.getGlobalConfigurationBuilder().threads();
    ThreadPoolBuilderAdapter threadPool = threads.getThreadPool(threadPoolName);
    if (threadPool == null)
        throw CONFIG.undefinedThreadPoolName(threadPoolName);
    ThreadPoolConfiguration threadPoolConfiguration = threadPool.asThreadPoolConfigurationBuilder();
    boolean isNonBlocking = threadPoolConfiguration.threadPoolFactory().createsNonBlockingThreads();
    if (NON_BLOCKING_EXECUTOR.equals(componentName) && !isNonBlocking) {
        throw CONFIG.threadPoolFactoryIsBlocking(threadPoolName, componentName);
    }
    DefaultThreadFactory threadFactory = threadPoolConfiguration.threadFactory();
    if (threadFactory != null) {
        threadFactory.setComponent(shortened(componentName));
    }
    return threadPoolConfiguration;
}
Also used : DefaultThreadFactory(org.infinispan.factories.threads.DefaultThreadFactory) ThreadPoolConfiguration(org.infinispan.configuration.global.ThreadPoolConfiguration) ThreadsConfigurationBuilder(org.infinispan.configuration.global.ThreadsConfigurationBuilder) ThreadPoolBuilderAdapter(org.infinispan.configuration.global.ThreadPoolBuilderAdapter)

Example 2 with ThreadPoolConfiguration

use of org.infinispan.configuration.global.ThreadPoolConfiguration in project infinispan by infinispan.

the class CoreConfigurationSerializer method writeThreads.

private void writeThreads(ConfigurationWriter writer, GlobalConfiguration globalConfiguration) {
    ConcurrentMap<String, DefaultThreadFactory> threadFactories = new ConcurrentHashMap<>();
    for (ThreadPoolConfiguration threadPoolConfiguration : Arrays.asList(globalConfiguration.expirationThreadPool(), globalConfiguration.listenerThreadPool(), globalConfiguration.nonBlockingThreadPool(), globalConfiguration.blockingThreadPool(), globalConfiguration.transport().remoteCommandThreadPool(), globalConfiguration.transport().transportThreadPool())) {
        ThreadFactory threadFactory = threadPoolConfiguration.threadFactory();
        if (threadFactory instanceof DefaultThreadFactory) {
            DefaultThreadFactory tf = (DefaultThreadFactory) threadFactory;
            threadFactories.putIfAbsent(tf.getName(), tf);
        }
    }
    if (threadFactories.size() > 0) {
        writer.writeStartElement(Element.THREADS);
        writer.writeStartMap(Element.THREAD_FACTORIES);
        for (DefaultThreadFactory threadFactory : threadFactories.values()) {
            writeThreadFactory(writer, threadFactory);
        }
        writer.writeEndMap();
        writer.writeStartMap(Element.THREAD_POOLS);
        writeThreadPool(writer, globalConfiguration.nonBlockingThreadPoolName(), globalConfiguration.nonBlockingThreadPool());
        writeThreadPool(writer, globalConfiguration.expirationThreadPoolName(), globalConfiguration.expirationThreadPool());
        writeThreadPool(writer, globalConfiguration.listenerThreadPoolName(), globalConfiguration.listenerThreadPool());
        writeThreadPool(writer, globalConfiguration.blockingThreadPoolName(), globalConfiguration.blockingThreadPool());
        writeThreadPool(writer, globalConfiguration.transport().remoteThreadPoolName(), globalConfiguration.transport().remoteCommandThreadPool());
        writer.writeEndMap();
        writer.writeEndElement();
    }
}
Also used : DefaultThreadFactory(org.infinispan.factories.threads.DefaultThreadFactory) DefaultThreadFactory(org.infinispan.factories.threads.DefaultThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) ThreadPoolConfiguration(org.infinispan.configuration.global.ThreadPoolConfiguration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

ThreadPoolConfiguration (org.infinispan.configuration.global.ThreadPoolConfiguration)2 DefaultThreadFactory (org.infinispan.factories.threads.DefaultThreadFactory)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 ThreadPoolBuilderAdapter (org.infinispan.configuration.global.ThreadPoolBuilderAdapter)1 ThreadsConfigurationBuilder (org.infinispan.configuration.global.ThreadsConfigurationBuilder)1