org.apache.camel.builder.ThreadPoolProfileBuilder Java Examples

The following examples show how to use org.apache.camel.builder.ThreadPoolProfileBuilder. 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: 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 #2
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 #3
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 #4
Source File: ThrottlerAsyncDelayedTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    ThreadPoolProfileBuilder builder = new ThreadPoolProfileBuilder("myThrottler");
    builder.maxQueueSize(5);
    context.getExecutorServiceManager().registerThreadPoolProfile(builder.build());

    return new ThrottlerAsyncDelayedRoute();
}