Java Code Examples for org.apache.camel.builder.ThreadPoolProfileBuilder

The following examples show how to use org.apache.camel.builder.ThreadPoolProfileBuilder. These examples are extracted from open source projects. 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
@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 2
public ThreadPoolProfile createCustomProfile() {
    // create a custom thread pool profile with the name bigPool
    return new ThreadPoolProfileBuilder("bigPool")
        .maxPoolSize(200)
        .rejectedPolicy(ThreadPoolRejectedPolicy.DiscardOldest)
        .build();
}
 
Example 3
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    ThreadPoolProfileBuilder builder = new ThreadPoolProfileBuilder("myThrottler");
    builder.maxQueueSize(5);
    context.getExecutorServiceManager().registerThreadPoolProfile(builder.build());

    return new ThrottlerAsyncDelayedRoute();
}
 
Example 4
@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");
}