org.apache.camel.spi.ThreadPoolProfile Java Examples

The following examples show how to use org.apache.camel.spi.ThreadPoolProfile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomThreadPoolProfileTest.java    From camelinaction with Apache License 2.0 7 votes vote down vote up
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // register a custom thread pool profile
            ThreadPoolProfile custom = createCustomProfile();
            context.getExecutorServiceManager().registerThreadPoolProfile(custom);

            from("direct:start")
                // use the bigPool profile for creating the thread pool to be used
                .threads().executorServiceRef("bigPool")
                .to("log:foo")
                .to("mock:result");
        }
    };
}
 
Example #2
Source File: ThreadPoolConfigurationTest.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
@Test
public void testThreadPool() throws Exception {
    ThreadPoolProfile dpp = context.getExecutorServiceManager().getDefaultThreadPoolProfile();
    Assert.assertNotNull(dpp);
    Assert.assertEquals("default", dpp.getId());
    Assert.assertEquals(5, dpp.getPoolSize().intValue());
    Assert.assertEquals(10, dpp.getMaxPoolSize().intValue());
    Assert.assertEquals(20, dpp.getMaxQueueSize().intValue());
    Assert.assertEquals(ThreadPoolRejectedPolicy.DiscardOldest, dpp.getRejectedPolicy());

    ThreadPoolProfile sp = context.getExecutorServiceManager().getThreadPoolProfile("smallPool");
    Assert.assertNotNull(sp);
    Assert.assertEquals("smallPool", sp.getId());
    Assert.assertEquals(2, sp.getPoolSize().intValue());
    Assert.assertEquals(10, sp.getMaxPoolSize().intValue());
    Assert.assertEquals(20, sp.getMaxQueueSize().intValue());
    Assert.assertEquals(ThreadPoolRejectedPolicy.Abort, sp.getRejectedPolicy());

    ThreadPoolProfile bp = context.getExecutorServiceManager().getThreadPoolProfile("bigPool");
    Assert.assertNotNull(bp);
    Assert.assertEquals("bigPool", bp.getId());
    Assert.assertEquals(20, bp.getPoolSize().intValue());
    Assert.assertEquals(50, bp.getMaxPoolSize().intValue());
    Assert.assertEquals(500, bp.getMaxQueueSize().intValue());
    Assert.assertEquals(ThreadPoolRejectedPolicy.DiscardOldest, bp.getRejectedPolicy());
}
 
Example #3
Source File: CustomThreadPoolProfileTest.java    From camelinaction2 with Apache License 2.0 6 votes vote down vote up
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // register a custom thread pool profile
            ThreadPoolProfile custom = createCustomProfile();
            context.getExecutorServiceManager().registerThreadPoolProfile(custom);

            from("direct:start")
                // use the bigPool profile for creating the thread pool to be used
                .threads().executorServiceRef("bigPool")
                .to("log:foo")
                .to("mock:result");
        }
    };
}
 
Example #4
Source File: CustomThreadPoolProfileRoute.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Override
public void configure() throws Exception {
    ThreadPoolProfile customThreadPoolProfile =
        new ThreadPoolProfileBuilder("customThreadPoolProfile").poolSize(5).maxQueueSize(100).build();
    ModelCamelContext context = getContext();
    context.getExecutorServiceManager().registerThreadPoolProfile(customThreadPoolProfile);

    from("direct:in")
        .log("Received ${body}:${threadName}")
        .threads().executorServiceRef("customThreadPoolProfile")
        .log("Processing ${body}:${threadName}")
        .transform(simple("${threadName}"))
        .to("mock:out");
}
 
Example #5
Source File: WildFlyCamelThreadPoolFactory.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Override
public ScheduledExecutorService newScheduledThreadPool(ThreadPoolProfile profile, ThreadFactory threadFactory) {
    RejectedExecutionHandler rejectedExecutionHandler = profile.getRejectedExecutionHandler();
    if (rejectedExecutionHandler == null) {
        rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy();
    }

    ScheduledThreadPoolExecutor answer = new RejectableScheduledThreadPoolExecutor(
        profile.getPoolSize(), managedThreadFactory, rejectedExecutionHandler);

    if (profile.getMaxPoolSize() > 0) {
        return new SizedScheduledExecutorService(answer, profile.getMaxQueueSize());
    } else {
        return answer;
    }
}
 
Example #6
Source File: CamelThreadPoolAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Bean
public ThreadPoolProfile threadPool(CamelContext camelContext, CamelThreadPoolConfigurationProperties tp) {
    // okay we have all properties set so we should be able to create thread pool profiles and register them on camel
    ThreadPoolProfile defaultProfile = camelContext.getExecutorServiceManager().getDefaultThreadPoolProfile();
    final ThreadPoolProfile dp = new ThreadPoolProfileBuilder("default", defaultProfile)
            .poolSize(tp.getPoolSize())
            .maxPoolSize(tp.getMaxPoolSize())
            .keepAliveTime(tp.getKeepAliveTime(), tp.getTimeUnit())
            .maxQueueSize(tp.getMaxQueueSize())
            .allowCoreThreadTimeOut(tp.getAllowCoreThreadTimeOut())
            .rejectedPolicy(tp.getRejectedPolicy()).build();

    tp.getConfig().forEach((k, v) -> {
        ThreadPoolProfileBuilder builder = new ThreadPoolProfileBuilder(k, dp);
        final ThreadPoolProfile tpp = builder.poolSize(v.getPoolSize())
                .maxPoolSize(v.getMaxPoolSize())
                .keepAliveTime(v.getKeepAliveTime(), v.getTimeUnit())
                .maxQueueSize(v.getMaxQueueSize())
                .allowCoreThreadTimeOut(v.getAllowCoreThreadTimeOut())
                .rejectedPolicy(v.getRejectedPolicy()).build();
        if (!tpp.isEmpty()) {
            camelContext.getExecutorServiceManager().registerThreadPoolProfile(tpp);
        }
    });

    if (!dp.isEmpty()) {
        dp.setDefaultProfile(true);
        camelContext.getExecutorServiceManager().setDefaultThreadPoolProfile(dp);
    }

    // need to return something
    return dp;
}
 
Example #7
Source File: CustomThreadPoolProfileTest.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public ThreadPoolProfile createCustomProfile() {
    // create a custom thread pool profile with the name bigPool
    return new ThreadPoolProfileBuilder("bigPool")
        .maxPoolSize(200)
        .rejectedPolicy(ThreadPoolRejectedPolicy.DiscardOldest)
        .build();
}
 
Example #8
Source File: CustomThreadPoolProfileTest.java    From camelinaction with Apache License 2.0 5 votes vote down vote up
public ThreadPoolProfile createCustomProfile() {
    // create a custom thread pool profile with the name bigPool
    ThreadPoolProfile profile = new ThreadPoolProfile("bigPool");
    profile.setMaxPoolSize(200);
    profile.setRejectedPolicy(ThreadPoolRejectedPolicy.DiscardOldest);
    return profile;
}
 
Example #9
Source File: WildFlyCamelThreadPoolFactory.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Override
public ExecutorService newThreadPool(ThreadPoolProfile profile, ThreadFactory factory) {
    boolean allow = profile.getAllowCoreThreadTimeOut() != null?profile.getAllowCoreThreadTimeOut().booleanValue():false;
    return this.newThreadPool(profile.getPoolSize().intValue(),
                              profile.getMaxPoolSize().intValue(),
                              profile.getKeepAliveTime().longValue(),
                              profile.getTimeUnit(),
                              profile.getMaxQueueSize().intValue(),
                              allow,
                              profile.getRejectedExecutionHandler(),
                              managedThreadFactory);
}