Search in sources :

Example 16 with ThreadPoolProfile

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

the class SpringCamelContextThreadPoolProfilesTest method testLowProfile.

public void testLowProfile() throws Exception {
    CamelContext context = getMandatoryBean(CamelContext.class, "camel-C");
    ThreadPoolProfile profile = context.getExecutorServiceManager().getThreadPoolProfile("low");
    assertEquals(1, profile.getPoolSize().intValue());
    assertEquals(5, profile.getMaxPoolSize().intValue());
    assertEquals(null, profile.getKeepAliveTime());
    assertEquals(null, profile.getMaxQueueSize());
    assertEquals(null, profile.getRejectedPolicy());
    // create a thread pool from low
    ExecutorService executor = context.getExecutorServiceManager().newThreadPool(this, "MyLow", "low");
    ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
    assertEquals(1, tp.getCorePoolSize());
    assertEquals(5, tp.getMaximumPoolSize());
    // should inherit default options
    assertEquals(60, tp.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals("CallerRuns", 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)

Example 17 with ThreadPoolProfile

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

the class SpringCamelContextCustomDefaultThreadPoolProfileTest method testDefaultThreadPoolProfile.

public void testDefaultThreadPoolProfile() throws Exception {
    SpringCamelContext context = applicationContext.getBeansOfType(SpringCamelContext.class).values().iterator().next();
    ThreadPoolProfile profile = context.getExecutorServiceManager().getDefaultThreadPoolProfile();
    assertEquals(5, profile.getPoolSize().intValue());
    assertEquals(15, profile.getMaxPoolSize().intValue());
    assertEquals(25, profile.getKeepAliveTime().longValue());
    assertEquals(250, profile.getMaxQueueSize().intValue());
    assertEquals(true, profile.getAllowCoreThreadTimeOut().booleanValue());
    assertEquals(ThreadPoolRejectedPolicy.Abort, profile.getRejectedPolicy());
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) SpringCamelContext(org.apache.camel.spring.SpringCamelContext)

Example 18 with ThreadPoolProfile

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

the class SpringCamelContextCustomThreadPoolProfileTest method testDefaultThreadPoolProfile.

public void testDefaultThreadPoolProfile() throws Exception {
    CamelContext context = getMandatoryBean(CamelContext.class, "camel-D");
    ThreadPoolProfile profile = context.getExecutorServiceManager().getDefaultThreadPoolProfile();
    assertEquals(5, profile.getPoolSize().intValue());
    assertEquals(15, profile.getMaxPoolSize().intValue());
    assertEquals(25, profile.getKeepAliveTime().longValue());
    assertEquals(250, profile.getMaxQueueSize().intValue());
    assertEquals(ThreadPoolRejectedPolicy.Abort, profile.getRejectedPolicy());
}
Also used : CamelContext(org.apache.camel.CamelContext) ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile)

Example 19 with ThreadPoolProfile

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

the class SpringCamelContextSimpleCustomDefaultThreadPoolProfileTest method testDefaultThreadPoolProfile.

public void testDefaultThreadPoolProfile() throws Exception {
    CamelContext context = getMandatoryBean(CamelContext.class, "camel-B");
    ThreadPoolProfile profile = context.getExecutorServiceManager().getDefaultThreadPoolProfile();
    assertEquals(25, profile.getMaxPoolSize().intValue());
    // should inherit default values
    assertEquals(10, profile.getPoolSize().intValue());
    assertEquals(60, profile.getKeepAliveTime().longValue());
    assertEquals(1000, profile.getMaxQueueSize().intValue());
    assertEquals(ThreadPoolRejectedPolicy.CallerRuns, profile.getRejectedPolicy());
}
Also used : CamelContext(org.apache.camel.CamelContext) ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile)

Example 20 with ThreadPoolProfile

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

the class FacebookProducer method getExecutorService.

protected static synchronized ExecutorService getExecutorService(CamelContext context) {
    // re-create it (its a shared static instance)
    if (executorService == null || executorService.isTerminated() || executorService.isShutdown()) {
        final ExecutorServiceManager manager = context.getExecutorServiceManager();
        // try to lookup a pool first based on profile
        ThreadPoolProfile poolProfile = manager.getThreadPoolProfile(FacebookConstants.FACEBOOK_THREAD_PROFILE_NAME);
        if (poolProfile == null) {
            poolProfile = manager.getDefaultThreadPoolProfile();
        }
        // create a new pool using the custom or default profile
        executorService = manager.newScheduledThreadPool(FacebookProducer.class, FacebookConstants.FACEBOOK_THREAD_PROFILE_NAME, poolProfile);
    }
    return executorService;
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) ExecutorServiceManager(org.apache.camel.spi.ExecutorServiceManager)

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