Search in sources :

Example 36 with ThreadPoolProfile

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

the class DefaultExecutorServiceManagerTest method testGetThreadPoolProfileInheritDefaultValues.

public void testGetThreadPoolProfileInheritDefaultValues() throws Exception {
    assertNull(context.getExecutorServiceManager().getThreadPoolProfile("foo"));
    ThreadPoolProfile foo = new ThreadPoolProfile("foo");
    foo.setMaxPoolSize(40);
    context.getExecutorServiceManager().registerThreadPoolProfile(foo);
    assertSame(foo, context.getExecutorServiceManager().getThreadPoolProfile("foo"));
    ExecutorService executor = context.getExecutorServiceManager().newThreadPool(this, "MyPool", "foo");
    ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
    assertEquals(40, tp.getMaximumPoolSize());
    // should inherit the default values
    assertEquals(10, tp.getCorePoolSize());
    assertEquals(60, tp.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals("CallerRuns", tp.getRejectedExecutionHandler().toString());
}
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 37 with ThreadPoolProfile

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

the class DefaultExecutorServiceManagerTest method testGetThreadPoolProfileInheritCustomDefaultValues.

public void testGetThreadPoolProfileInheritCustomDefaultValues() throws Exception {
    ThreadPoolProfile newDefault = new ThreadPoolProfile("newDefault");
    newDefault.setKeepAliveTime(30L);
    newDefault.setMaxPoolSize(50);
    newDefault.setPoolSize(5);
    newDefault.setMaxQueueSize(2000);
    newDefault.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);
    context.getExecutorServiceManager().setDefaultThreadPoolProfile(newDefault);
    assertNull(context.getExecutorServiceManager().getThreadPoolProfile("foo"));
    ThreadPoolProfile foo = new ThreadPoolProfile("foo");
    foo.setMaxPoolSize(25);
    foo.setPoolSize(1);
    context.getExecutorServiceManager().registerThreadPoolProfile(foo);
    assertSame(foo, context.getExecutorServiceManager().getThreadPoolProfile("foo"));
    ExecutorService executor = context.getExecutorServiceManager().newThreadPool(this, "MyPool", "foo");
    ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
    assertEquals(25, tp.getMaximumPoolSize());
    // should inherit the default values
    assertEquals(1, tp.getCorePoolSize());
    assertEquals(30, tp.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals("Abort", tp.getRejectedExecutionHandler().toString());
}
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 38 with ThreadPoolProfile

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

the class DefaultExecutorServiceManagerTest method testNewThreadPoolProfile.

public void testNewThreadPoolProfile() throws Exception {
    assertNull(context.getExecutorServiceManager().getThreadPoolProfile("foo"));
    ThreadPoolProfile foo = new ThreadPoolProfile("foo");
    foo.setKeepAliveTime(20L);
    foo.setMaxPoolSize(40);
    foo.setPoolSize(5);
    foo.setMaxQueueSize(2000);
    ExecutorService pool = context.getExecutorServiceManager().newThreadPool(this, "Cool", foo);
    assertNotNull(pool);
    ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, pool);
    assertEquals(20, tp.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals(40, tp.getMaximumPoolSize());
    assertEquals(5, tp.getCorePoolSize());
    assertFalse(tp.isShutdown());
    context.stop();
    assertTrue(tp.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 39 with ThreadPoolProfile

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

the class ManagedThreadPoolProfileTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            ThreadPoolProfile profile = new ThreadPoolProfile("custom");
            profile.setPoolSize(5);
            profile.setMaxPoolSize(15);
            profile.setKeepAliveTime(25L);
            profile.setMaxQueueSize(250);
            profile.setAllowCoreThreadTimeOut(true);
            profile.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);
            context.getExecutorServiceManager().registerThreadPoolProfile(profile);
            from("direct:start").threads().executorServiceRef("custom").to("mock:result");
        }
    };
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) RouteBuilder(org.apache.camel.builder.RouteBuilder)

Example 40 with ThreadPoolProfile

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

the class AbstractCamelContextFactoryBean method asThreadPoolProfile.

/**
     * Creates a {@link ThreadPoolProfile} instance based on the definition.
     *
     * @param context    the camel context
     * @return           the profile
     * @throws Exception is thrown if error creating the profile
     */
private ThreadPoolProfile asThreadPoolProfile(CamelContext context, ThreadPoolProfileDefinition definition) throws Exception {
    ThreadPoolProfile answer = new ThreadPoolProfile();
    answer.setId(definition.getId());
    answer.setDefaultProfile(definition.getDefaultProfile());
    answer.setPoolSize(CamelContextHelper.parseInteger(context, definition.getPoolSize()));
    answer.setMaxPoolSize(CamelContextHelper.parseInteger(context, definition.getMaxPoolSize()));
    answer.setKeepAliveTime(CamelContextHelper.parseLong(context, definition.getKeepAliveTime()));
    answer.setMaxQueueSize(CamelContextHelper.parseInteger(context, definition.getMaxQueueSize()));
    answer.setAllowCoreThreadTimeOut(CamelContextHelper.parseBoolean(context, definition.getAllowCoreThreadTimeOut()));
    answer.setRejectedPolicy(definition.getRejectedPolicy());
    answer.setTimeUnit(definition.getTimeUnit());
    return answer;
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile)

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