use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class DefaultExecutorServiceManagerTest method testGetThreadPoolProfileInheritDefaultValues.
public void testGetThreadPoolProfileInheritDefaultValues() throws Exception {
assertNull(context.getExecutorServiceManager().getThreadPoolProfile("foo"));
ThreadPoolProfile foo = new ThreadPoolProfile("foo");
foo.setMaxPoolSize(40);
context.getExecutorServiceManager().registerThreadPoolProfile(foo);
assertSame(foo, context.getExecutorServiceManager().getThreadPoolProfile("foo"));
ExecutorService executor = context.getExecutorServiceManager().newThreadPool(this, "MyPool", "foo");
ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
assertEquals(40, tp.getMaximumPoolSize());
// should inherit the default values
assertEquals(10, tp.getCorePoolSize());
assertEquals(60, tp.getKeepAliveTime(TimeUnit.SECONDS));
assertEquals("CallerRuns", tp.getRejectedExecutionHandler().toString());
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class DefaultExecutorServiceManagerTest method testGetThreadPoolProfileInheritCustomDefaultValues.
public void testGetThreadPoolProfileInheritCustomDefaultValues() throws Exception {
ThreadPoolProfile newDefault = new ThreadPoolProfile("newDefault");
newDefault.setKeepAliveTime(30L);
newDefault.setMaxPoolSize(50);
newDefault.setPoolSize(5);
newDefault.setMaxQueueSize(2000);
newDefault.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);
context.getExecutorServiceManager().setDefaultThreadPoolProfile(newDefault);
assertNull(context.getExecutorServiceManager().getThreadPoolProfile("foo"));
ThreadPoolProfile foo = new ThreadPoolProfile("foo");
foo.setMaxPoolSize(25);
foo.setPoolSize(1);
context.getExecutorServiceManager().registerThreadPoolProfile(foo);
assertSame(foo, context.getExecutorServiceManager().getThreadPoolProfile("foo"));
ExecutorService executor = context.getExecutorServiceManager().newThreadPool(this, "MyPool", "foo");
ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
assertEquals(25, tp.getMaximumPoolSize());
// should inherit the default values
assertEquals(1, tp.getCorePoolSize());
assertEquals(30, tp.getKeepAliveTime(TimeUnit.SECONDS));
assertEquals("Abort", tp.getRejectedExecutionHandler().toString());
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class DefaultExecutorServiceManagerTest method testNewThreadPoolProfile.
public void testNewThreadPoolProfile() throws Exception {
assertNull(context.getExecutorServiceManager().getThreadPoolProfile("foo"));
ThreadPoolProfile foo = new ThreadPoolProfile("foo");
foo.setKeepAliveTime(20L);
foo.setMaxPoolSize(40);
foo.setPoolSize(5);
foo.setMaxQueueSize(2000);
ExecutorService pool = context.getExecutorServiceManager().newThreadPool(this, "Cool", foo);
assertNotNull(pool);
ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, pool);
assertEquals(20, tp.getKeepAliveTime(TimeUnit.SECONDS));
assertEquals(40, tp.getMaximumPoolSize());
assertEquals(5, tp.getCorePoolSize());
assertFalse(tp.isShutdown());
context.stop();
assertTrue(tp.isShutdown());
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class ManagedThreadPoolProfileTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
ThreadPoolProfile profile = new ThreadPoolProfile("custom");
profile.setPoolSize(5);
profile.setMaxPoolSize(15);
profile.setKeepAliveTime(25L);
profile.setMaxQueueSize(250);
profile.setAllowCoreThreadTimeOut(true);
profile.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);
context.getExecutorServiceManager().registerThreadPoolProfile(profile);
from("direct:start").threads().executorServiceRef("custom").to("mock:result");
}
};
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class AbstractCamelContextFactoryBean method asThreadPoolProfile.
/**
* Creates a {@link ThreadPoolProfile} instance based on the definition.
*
* @param context the camel context
* @return the profile
* @throws Exception is thrown if error creating the profile
*/
private ThreadPoolProfile asThreadPoolProfile(CamelContext context, ThreadPoolProfileDefinition definition) throws Exception {
ThreadPoolProfile answer = new ThreadPoolProfile();
answer.setId(definition.getId());
answer.setDefaultProfile(definition.getDefaultProfile());
answer.setPoolSize(CamelContextHelper.parseInteger(context, definition.getPoolSize()));
answer.setMaxPoolSize(CamelContextHelper.parseInteger(context, definition.getMaxPoolSize()));
answer.setKeepAliveTime(CamelContextHelper.parseLong(context, definition.getKeepAliveTime()));
answer.setMaxQueueSize(CamelContextHelper.parseInteger(context, definition.getMaxQueueSize()));
answer.setAllowCoreThreadTimeOut(CamelContextHelper.parseBoolean(context, definition.getAllowCoreThreadTimeOut()));
answer.setRejectedPolicy(definition.getRejectedPolicy());
answer.setTimeUnit(definition.getTimeUnit());
return answer;
}
Aggregations