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);
}
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;
}
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;
}
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"));
}
};
}
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();
}
Aggregations