Search in sources :

Example 11 with ThreadPoolProfile

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

the class DefaultExecutorServiceManagerTest method testGetThreadPoolProfile.

public void testGetThreadPoolProfile() throws Exception {
    assertNull(context.getExecutorServiceManager().getThreadPoolProfile("foo"));
    ThreadPoolProfile foo = new ThreadPoolProfile("foo");
    foo.setKeepAliveTime(20L);
    foo.setMaxPoolSize(40);
    foo.setPoolSize(5);
    foo.setMaxQueueSize(2000);
    context.getExecutorServiceManager().registerThreadPoolProfile(foo);
    assertSame(foo, context.getExecutorServiceManager().getThreadPoolProfile("foo"));
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile)

Example 12 with ThreadPoolProfile

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

the class DefaultExecutorServiceManagerTest method testCustomDefaultThreadPool.

public void testCustomDefaultThreadPool() throws Exception {
    ThreadPoolProfile custom = new ThreadPoolProfile("custom");
    custom.setKeepAliveTime(20L);
    custom.setMaxPoolSize(40);
    custom.setPoolSize(5);
    custom.setMaxQueueSize(2000);
    context.getExecutorServiceManager().setDefaultThreadPoolProfile(custom);
    assertEquals(true, custom.isDefaultProfile().booleanValue());
    ExecutorService myPool = context.getExecutorServiceManager().newDefaultThreadPool(this, "myPool");
    assertEquals(false, myPool.isShutdown());
    // should use default settings
    ThreadPoolExecutor executor = (ThreadPoolExecutor) myPool;
    assertEquals(5, executor.getCorePoolSize());
    assertEquals(40, executor.getMaximumPoolSize());
    assertEquals(20, executor.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals(2000, executor.getQueue().remainingCapacity());
    context.stop();
    assertEquals(true, myPool.isShutdown());
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) ExecutorService(java.util.concurrent.ExecutorService) SizedScheduledExecutorService(org.apache.camel.util.concurrent.SizedScheduledExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 13 with ThreadPoolProfile

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

the class DefaultExecutorServiceManagerTest method testTwoGetThreadPoolProfile.

public void testTwoGetThreadPoolProfile() throws Exception {
    assertNull(context.getExecutorServiceManager().getThreadPoolProfile("foo"));
    ThreadPoolProfile foo = new ThreadPoolProfile("foo");
    foo.setKeepAliveTime(20L);
    foo.setMaxPoolSize(40);
    foo.setPoolSize(5);
    foo.setMaxQueueSize(2000);
    context.getExecutorServiceManager().registerThreadPoolProfile(foo);
    ThreadPoolProfile bar = new ThreadPoolProfile("bar");
    bar.setKeepAliveTime(40L);
    bar.setMaxPoolSize(5);
    bar.setPoolSize(1);
    bar.setMaxQueueSize(100);
    context.getExecutorServiceManager().registerThreadPoolProfile(bar);
    assertSame(foo, context.getExecutorServiceManager().getThreadPoolProfile("foo"));
    assertSame(bar, context.getExecutorServiceManager().getThreadPoolProfile("bar"));
    assertNotSame(foo, bar);
    assertFalse(context.getExecutorServiceManager().getThreadPoolProfile("foo").isDefaultProfile());
    assertFalse(context.getExecutorServiceManager().getThreadPoolProfile("bar").isDefaultProfile());
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile)

Example 14 with ThreadPoolProfile

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

the class CamelAutoConfiguration method initThreadPoolProfiles.

private void initThreadPoolProfiles(ApplicationContext applicationContext, CamelContext camelContext) {
    Set<String> defaultIds = new HashSet<String>();
    // lookup and use custom profiles from the registry
    Map<String, ThreadPoolProfile> profiles = applicationContext.getBeansOfType(ThreadPoolProfile.class);
    if (profiles != null && !profiles.isEmpty()) {
        for (Map.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);
                camelContext.getExecutorServiceManager().setDefaultThreadPoolProfile(profile);
                defaultIds.add(entry.getKey());
            } else {
                camelContext.getExecutorServiceManager().registerThreadPoolProfile(profile);
            }
        }
    }
    // 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) Map(java.util.Map) HashSet(java.util.HashSet)

Example 15 with ThreadPoolProfile

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

the class SpringCamelContextThreadPoolProfilesTest method testBigProfile.

public void testBigProfile() throws Exception {
    CamelContext context = getMandatoryBean(CamelContext.class, "camel-C");
    ThreadPoolProfile profile = context.getExecutorServiceManager().getThreadPoolProfile("big");
    assertEquals(50, profile.getPoolSize().intValue());
    assertEquals(100, profile.getMaxPoolSize().intValue());
    assertEquals(ThreadPoolRejectedPolicy.DiscardOldest, profile.getRejectedPolicy());
    assertEquals(null, profile.getKeepAliveTime());
    assertEquals(null, profile.getMaxQueueSize());
    // create a thread pool from big
    ExecutorService executor = context.getExecutorServiceManager().newThreadPool(this, "MyBig", "big");
    ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
    assertEquals(50, tp.getCorePoolSize());
    assertEquals(100, tp.getMaximumPoolSize());
    // should inherit default options
    assertEquals(60, tp.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals("DiscardOldest", tp.getRejectedExecutionHandler().toString());
}
Also used : CamelContext(org.apache.camel.CamelContext) ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) ExecutorService(java.util.concurrent.ExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

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