Search in sources :

Example 31 with ThreadPoolProfile

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

the class DefaultExecutorServiceStrategy method newThreadPool.

public ExecutorService newThreadPool(Object source, String name, int corePoolSize, int maxPoolSize, int maxQueueSize) {
    // use a profile with the settings
    ThreadPoolProfile profile = new ThreadPoolProfile();
    profile.setPoolSize(corePoolSize);
    profile.setMaxPoolSize(maxPoolSize);
    profile.setMaxQueueSize(maxQueueSize);
    return camelContext.getExecutorServiceManager().newThreadPool(source, name, profile);
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile)

Example 32 with ThreadPoolProfile

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

the class DefaultExecutorServiceStrategy method newThreadPool.

public ExecutorService newThreadPool(Object source, String name, int corePoolSize, int maxPoolSize, long keepAliveTime, TimeUnit timeUnit, int maxQueueSize, RejectedExecutionHandler rejectedExecutionHandler, boolean daemon) {
    // use a profile with the settings
    ThreadPoolProfile profile = new ThreadPoolProfile();
    profile.setPoolSize(corePoolSize);
    profile.setMaxPoolSize(maxPoolSize);
    profile.setMaxQueueSize(maxQueueSize);
    profile.setKeepAliveTime(keepAliveTime);
    profile.setTimeUnit(timeUnit);
    // must cast to ThreadPoolExecutor to be able to set the rejected execution handler
    ThreadPoolExecutor answer = (ThreadPoolExecutor) camelContext.getExecutorServiceManager().newThreadPool(source, name, profile);
    answer.setRejectedExecutionHandler(rejectedExecutionHandler);
    return answer;
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 33 with ThreadPoolProfile

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

the class DefaultExecutorServiceStrategy method lookupScheduled.

public ScheduledExecutorService lookupScheduled(Object source, String name, String executorServiceRef) {
    ScheduledExecutorService answer = camelContext.getRegistry().lookupByNameAndType(executorServiceRef, ScheduledExecutorService.class);
    if (answer == null) {
        ThreadPoolProfile profile = getThreadPoolProfile(executorServiceRef);
        if (profile != null) {
            Integer poolSize = profile.getPoolSize();
            if (poolSize == null) {
                poolSize = getDefaultThreadPoolProfile().getPoolSize();
            }
            answer = newScheduledThreadPool(source, name, poolSize);
        }
    }
    return answer;
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile)

Example 34 with ThreadPoolProfile

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

the class DefaultExecutorServiceManagerTest method testNewThreadPoolProfileById.

public void testNewThreadPoolProfileById() 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);
    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 35 with ThreadPoolProfile

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

the class DefaultExecutorServiceManagerTest method testNewScheduledThreadPoolProfileById.

public void testNewScheduledThreadPoolProfileById() 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);
    ExecutorService pool = context.getExecutorServiceManager().newScheduledThreadPool(this, "Cool", "foo");
    assertNotNull(pool);
    SizedScheduledExecutorService tp = assertIsInstanceOf(SizedScheduledExecutorService.class, pool);
    // a scheduled dont use keep alive
    assertEquals(0, tp.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals(Integer.MAX_VALUE, tp.getMaximumPoolSize());
    assertEquals(5, tp.getCorePoolSize());
    assertFalse(tp.isShutdown());
    context.stop();
    assertTrue(tp.isShutdown());
}
Also used : SizedScheduledExecutorService(org.apache.camel.util.concurrent.SizedScheduledExecutorService) ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) ExecutorService(java.util.concurrent.ExecutorService) SizedScheduledExecutorService(org.apache.camel.util.concurrent.SizedScheduledExecutorService)

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