Search in sources :

Example 21 with ThreadPoolProfile

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

the class InstrumentedThreadPoolFactoryTest method setUp.

@Before
public void setUp() throws Exception {
    profile = new ThreadPoolProfile(METRICS_NAME);
    profile.setDefaultProfile(false);
    profile.setMaxPoolSize(10);
    profile.setMaxQueueSize(1000);
    profile.setPoolSize(5);
    profile.setKeepAliveTime(5L);
    profile.setTimeUnit(TimeUnit.SECONDS);
    profile.setRejectedPolicy(ThreadPoolRejectedPolicy.CallerRuns);
    instrumentedThreadPoolFactory = new InstrumentedThreadPoolFactory(registry, threadPoolFactory);
    inOrder = Mockito.inOrder(registry);
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) Before(org.junit.Before)

Example 22 with ThreadPoolProfile

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

the class AbstractApiEndpoint method getExecutorService.

private static ExecutorService getExecutorService(Class<? extends AbstractApiEndpoint> endpointClass, CamelContext context, String threadProfileName) {
    // lookup executorService for extending class name
    final String endpointClassName = endpointClass.getName();
    ExecutorService executorService = executorServiceMap.get(endpointClassName);
    // 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(threadProfileName);
        if (poolProfile == null) {
            poolProfile = manager.getDefaultThreadPoolProfile();
        }
        // create a new pool using the custom or default profile
        executorService = manager.newScheduledThreadPool(endpointClass, threadProfileName, poolProfile);
        executorServiceMap.put(endpointClassName, executorService);
    }
    return executorService;
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) ExecutorService(java.util.concurrent.ExecutorService) ExecutorServiceManager(org.apache.camel.spi.ExecutorServiceManager)

Example 23 with ThreadPoolProfile

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

the class CamelCustomDefaultThreadPoolProfileTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    CamelContext camel = super.createCamelContext();
    ThreadPoolProfile profile = new ThreadPoolProfile("custom");
    profile.setPoolSize(5);
    profile.setMaxPoolSize(15);
    profile.setKeepAliveTime(25L);
    profile.setMaxQueueSize(250);
    profile.setAllowCoreThreadTimeOut(true);
    profile.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);
    camel.getExecutorServiceManager().setDefaultThreadPoolProfile(profile);
    return camel;
}
Also used : CamelContext(org.apache.camel.CamelContext) ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile)

Example 24 with ThreadPoolProfile

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

the class MulticastThreadPoolProfileTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // register thread pool profile
            ThreadPoolProfile profile = new ThreadPoolProfileBuilder("myProfile").poolSize(5).maxPoolSize(10).maxQueueSize(20).build();
            context.getExecutorServiceManager().registerThreadPoolProfile(profile);
            from("direct:start").multicast(new AggregationStrategy() {

                public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
                    if (oldExchange == null) {
                        return newExchange;
                    }
                    String body = oldExchange.getIn().getBody(String.class);
                    oldExchange.getIn().setBody(body + newExchange.getIn().getBody(String.class));
                    return oldExchange;
                }
            }).parallelProcessing().executorServiceRef("myProfile").to("direct:a", "direct:b").end().to("mock:result");
            from("direct:a").delay(100).setBody(constant("A"));
            from("direct:b").setBody(constant("B"));
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) RouteBuilder(org.apache.camel.builder.RouteBuilder) ThreadPoolProfileBuilder(org.apache.camel.builder.ThreadPoolProfileBuilder) AggregationStrategy(org.apache.camel.processor.aggregate.AggregationStrategy)

Example 25 with ThreadPoolProfile

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

the class AsyncDeadLetterChannelExecutorServiceRefTest method testAsyncErrorHandlerWait.

public void testAsyncErrorHandlerWait() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            ThreadPoolProfile profile = new ThreadPoolProfile("myAsyncPool");
            profile.setPoolSize(5);
            context.getExecutorServiceManager().registerThreadPoolProfile(profile);
            errorHandler(deadLetterChannel("mock:dead").maximumRedeliveries(2).redeliveryDelay(0).logStackTrace(false).executorServiceRef("myAsyncPool"));
            from("direct:in").threads(2).to("mock:foo").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    throw new Exception("Forced exception by unit test");
                }
            });
        }
    });
    context.start();
    getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:dead").expectedMessageCount(1);
    template.requestBody("direct:in", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder)

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