Search in sources :

Example 41 with ThreadPoolProfile

use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.

the class AbstractCamelContextFactoryBean method initThreadPoolProfiles.

protected void initThreadPoolProfiles(T context) throws Exception {
    Set<String> defaultIds = new HashSet<String>();
    // lookup and use custom profiles from the registry
    Map<String, ThreadPoolProfile> profiles = context.getRegistry().findByTypeWithName(ThreadPoolProfile.class);
    if (profiles != null && !profiles.isEmpty()) {
        for (Entry<String, ThreadPoolProfile> entry : profiles.entrySet()) {
            ThreadPoolProfile profile = entry.getValue();
            // do not add if already added, for instance a tracer that is also an InterceptStrategy class
            if (profile.isDefaultProfile()) {
                LOG.info("Using custom default ThreadPoolProfile with id: {} and implementation: {}", entry.getKey(), profile);
                context.getExecutorServiceManager().setDefaultThreadPoolProfile(profile);
                defaultIds.add(entry.getKey());
            } else {
                context.getExecutorServiceManager().registerThreadPoolProfile(profile);
            }
        }
    }
    // use custom profiles defined in the CamelContext
    if (getThreadPoolProfiles() != null && !getThreadPoolProfiles().isEmpty()) {
        for (ThreadPoolProfileDefinition definition : getThreadPoolProfiles()) {
            if (definition.isDefaultProfile()) {
                LOG.info("Using custom default ThreadPoolProfile with id: {} and implementation: {}", definition.getId(), definition);
                context.getExecutorServiceManager().setDefaultThreadPoolProfile(asThreadPoolProfile(context, definition));
                defaultIds.add(definition.getId());
            } else {
                context.getExecutorServiceManager().registerThreadPoolProfile(asThreadPoolProfile(context, definition));
            }
        }
    }
    // validate at most one is defined
    if (defaultIds.size() > 1) {
        throw new IllegalArgumentException("Only exactly one default ThreadPoolProfile is allowed, was " + defaultIds.size() + " ids: " + defaultIds);
    }
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) ThreadPoolProfileDefinition(org.apache.camel.model.ThreadPoolProfileDefinition) HashSet(java.util.HashSet)

Aggregations

ThreadPoolProfile (org.apache.camel.spi.ThreadPoolProfile)41 ExecutorService (java.util.concurrent.ExecutorService)16 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)11 SizedScheduledExecutorService (org.apache.camel.util.concurrent.SizedScheduledExecutorService)11 CamelContext (org.apache.camel.CamelContext)5 RouteBuilder (org.apache.camel.builder.RouteBuilder)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 ExecutorServiceManager (org.apache.camel.spi.ExecutorServiceManager)4 ThreadPoolProfileBuilder (org.apache.camel.builder.ThreadPoolProfileBuilder)3 HashSet (java.util.HashSet)2 Exchange (org.apache.camel.Exchange)2 Processor (org.apache.camel.Processor)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 ThreadPoolRejectedPolicy (org.apache.camel.ThreadPoolRejectedPolicy)1 ThreadPoolProfileDefinition (org.apache.camel.model.ThreadPoolProfileDefinition)1 BodyInAggregatingStrategy (org.apache.camel.processor.BodyInAggregatingStrategy)1 Pipeline (org.apache.camel.processor.Pipeline)1