Search in sources :

Example 1 with ThreadsConfigurationBuilder

use of org.infinispan.configuration.global.ThreadsConfigurationBuilder 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 ThreadsConfigurationBuilder

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

the class Parser method parseBoundedQueueThreadPool.

public void parseBoundedQueueThreadPool(ConfigurationReader reader, ConfigurationBuilderHolder holder, String name, boolean isNonBlocking) {
    ThreadsConfigurationBuilder threadsBuilder = holder.getGlobalConfigurationBuilder().threads();
    String threadFactoryName = null;
    int maxThreads = 0;
    int coreThreads = 0;
    int queueLength = 0;
    long keepAlive = 0;
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        ParseUtils.requireNoNamespaceAttribute(reader, i);
        String value = reader.getAttributeValue(i);
        Attribute attribute = Attribute.forName(reader.getAttributeName(i));
        switch(attribute) {
            case NAME:
                {
                    // Already seen
                    break;
                }
            case THREAD_FACTORY:
                {
                    threadFactoryName = value;
                    break;
                }
            case CORE_THREADS:
                {
                    coreThreads = Integer.parseInt(value);
                    break;
                }
            case MAX_THREADS:
                {
                    maxThreads = Integer.parseInt(value);
                    break;
                }
            case QUEUE_LENGTH:
                {
                    queueLength = Integer.parseInt(value);
                    break;
                }
            case KEEP_ALIVE_TIME:
                {
                    keepAlive = Long.parseLong(value);
                    break;
                }
            default:
                {
                    throw ParseUtils.unexpectedAttribute(reader, i);
                }
        }
    }
    threadsBuilder.addBoundedThreadPool(name).threadFactory(threadFactoryName).coreThreads(coreThreads).maxThreads(maxThreads).queueLength(queueLength).keepAliveTime(keepAlive).nonBlocking(isNonBlocking);
    ParseUtils.requireNoContent(reader);
}
Also used : ParseUtils.ignoreAttribute(org.infinispan.configuration.parsing.ParseUtils.ignoreAttribute) ThreadsConfigurationBuilder(org.infinispan.configuration.global.ThreadsConfigurationBuilder)

Example 3 with ThreadsConfigurationBuilder

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

the class Parser method parseCachedThreadPool.

private void parseCachedThreadPool(ConfigurationReader reader, ConfigurationBuilderHolder holder, String name) {
    ThreadsConfigurationBuilder threadsBuilder = holder.getGlobalConfigurationBuilder().threads();
    String threadFactoryName = null;
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        ParseUtils.requireNoNamespaceAttribute(reader, i);
        String value = reader.getAttributeValue(i);
        Attribute attribute = Attribute.forName(reader.getAttributeName(i));
        switch(attribute) {
            case NAME:
                {
                    // Ignore
                    break;
                }
            case THREAD_FACTORY:
                {
                    threadFactoryName = value;
                    break;
                }
            default:
                {
                    throw ParseUtils.unexpectedAttribute(reader, i);
                }
        }
    }
    threadsBuilder.addCachedThreadPool(name).threadFactory(threadFactoryName);
    ParseUtils.requireNoContent(reader);
}
Also used : ParseUtils.ignoreAttribute(org.infinispan.configuration.parsing.ParseUtils.ignoreAttribute) ThreadsConfigurationBuilder(org.infinispan.configuration.global.ThreadsConfigurationBuilder)

Example 4 with ThreadsConfigurationBuilder

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

the class Parser method parseScheduledThreadPool.

private void parseScheduledThreadPool(ConfigurationReader reader, ConfigurationBuilderHolder holder, String name) {
    ThreadsConfigurationBuilder threadsBuilder = holder.getGlobalConfigurationBuilder().threads();
    String threadFactoryName = null;
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        ParseUtils.requireNoNamespaceAttribute(reader, i);
        String value = reader.getAttributeValue(i);
        Attribute attribute = Attribute.forName(reader.getAttributeName(i));
        switch(attribute) {
            case NAME:
                {
                    // Already seen
                    break;
                }
            case THREAD_FACTORY:
                {
                    threadFactoryName = value;
                    break;
                }
            default:
                {
                    throw ParseUtils.unexpectedAttribute(reader, i);
                }
        }
    }
    threadsBuilder.addScheduledThreadPool(name).threadFactory(threadFactoryName);
    ParseUtils.requireNoContent(reader);
}
Also used : ParseUtils.ignoreAttribute(org.infinispan.configuration.parsing.ParseUtils.ignoreAttribute) ThreadsConfigurationBuilder(org.infinispan.configuration.global.ThreadsConfigurationBuilder)

Aggregations

ThreadsConfigurationBuilder (org.infinispan.configuration.global.ThreadsConfigurationBuilder)4 ParseUtils.ignoreAttribute (org.infinispan.configuration.parsing.ParseUtils.ignoreAttribute)3 ThreadPoolBuilderAdapter (org.infinispan.configuration.global.ThreadPoolBuilderAdapter)1 ThreadPoolConfiguration (org.infinispan.configuration.global.ThreadPoolConfiguration)1 DefaultThreadFactory (org.infinispan.factories.threads.DefaultThreadFactory)1