Search in sources :

Example 1 with ThreadPoolProfileDefinition

use of org.apache.camel.model.ThreadPoolProfileDefinition 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

HashSet (java.util.HashSet)1 ThreadPoolProfileDefinition (org.apache.camel.model.ThreadPoolProfileDefinition)1 ThreadPoolProfile (org.apache.camel.spi.ThreadPoolProfile)1