use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class DefaultExecutorServiceManagerTest method testGetThreadPoolProfile.
public void testGetThreadPoolProfile() throws Exception {
assertNull(context.getExecutorServiceManager().getThreadPoolProfile("foo"));
ThreadPoolProfile foo = new ThreadPoolProfile("foo");
foo.setKeepAliveTime(20L);
foo.setMaxPoolSize(40);
foo.setPoolSize(5);
foo.setMaxQueueSize(2000);
context.getExecutorServiceManager().registerThreadPoolProfile(foo);
assertSame(foo, context.getExecutorServiceManager().getThreadPoolProfile("foo"));
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class DefaultExecutorServiceManagerTest method testCustomDefaultThreadPool.
public void testCustomDefaultThreadPool() throws Exception {
ThreadPoolProfile custom = new ThreadPoolProfile("custom");
custom.setKeepAliveTime(20L);
custom.setMaxPoolSize(40);
custom.setPoolSize(5);
custom.setMaxQueueSize(2000);
context.getExecutorServiceManager().setDefaultThreadPoolProfile(custom);
assertEquals(true, custom.isDefaultProfile().booleanValue());
ExecutorService myPool = context.getExecutorServiceManager().newDefaultThreadPool(this, "myPool");
assertEquals(false, myPool.isShutdown());
// should use default settings
ThreadPoolExecutor executor = (ThreadPoolExecutor) myPool;
assertEquals(5, executor.getCorePoolSize());
assertEquals(40, executor.getMaximumPoolSize());
assertEquals(20, executor.getKeepAliveTime(TimeUnit.SECONDS));
assertEquals(2000, executor.getQueue().remainingCapacity());
context.stop();
assertEquals(true, myPool.isShutdown());
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class DefaultExecutorServiceManagerTest method testTwoGetThreadPoolProfile.
public void testTwoGetThreadPoolProfile() throws Exception {
assertNull(context.getExecutorServiceManager().getThreadPoolProfile("foo"));
ThreadPoolProfile foo = new ThreadPoolProfile("foo");
foo.setKeepAliveTime(20L);
foo.setMaxPoolSize(40);
foo.setPoolSize(5);
foo.setMaxQueueSize(2000);
context.getExecutorServiceManager().registerThreadPoolProfile(foo);
ThreadPoolProfile bar = new ThreadPoolProfile("bar");
bar.setKeepAliveTime(40L);
bar.setMaxPoolSize(5);
bar.setPoolSize(1);
bar.setMaxQueueSize(100);
context.getExecutorServiceManager().registerThreadPoolProfile(bar);
assertSame(foo, context.getExecutorServiceManager().getThreadPoolProfile("foo"));
assertSame(bar, context.getExecutorServiceManager().getThreadPoolProfile("bar"));
assertNotSame(foo, bar);
assertFalse(context.getExecutorServiceManager().getThreadPoolProfile("foo").isDefaultProfile());
assertFalse(context.getExecutorServiceManager().getThreadPoolProfile("bar").isDefaultProfile());
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class CamelAutoConfiguration method initThreadPoolProfiles.
private void initThreadPoolProfiles(ApplicationContext applicationContext, CamelContext camelContext) {
Set<String> defaultIds = new HashSet<String>();
// lookup and use custom profiles from the registry
Map<String, ThreadPoolProfile> profiles = applicationContext.getBeansOfType(ThreadPoolProfile.class);
if (profiles != null && !profiles.isEmpty()) {
for (Map.Entry<String, ThreadPoolProfile> entry : profiles.entrySet()) {
ThreadPoolProfile profile = entry.getValue();
// do not add if already added, for instance a tracer that is also an InterceptStrategy class
if (profile.isDefaultProfile()) {
LOG.info("Using custom default ThreadPoolProfile with id: {} and implementation: {}", entry.getKey(), profile);
camelContext.getExecutorServiceManager().setDefaultThreadPoolProfile(profile);
defaultIds.add(entry.getKey());
} else {
camelContext.getExecutorServiceManager().registerThreadPoolProfile(profile);
}
}
}
// validate at most one is defined
if (defaultIds.size() > 1) {
throw new IllegalArgumentException("Only exactly one default ThreadPoolProfile is allowed, was " + defaultIds.size() + " ids: " + defaultIds);
}
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class SpringCamelContextThreadPoolProfilesTest method testBigProfile.
public void testBigProfile() throws Exception {
CamelContext context = getMandatoryBean(CamelContext.class, "camel-C");
ThreadPoolProfile profile = context.getExecutorServiceManager().getThreadPoolProfile("big");
assertEquals(50, profile.getPoolSize().intValue());
assertEquals(100, profile.getMaxPoolSize().intValue());
assertEquals(ThreadPoolRejectedPolicy.DiscardOldest, profile.getRejectedPolicy());
assertEquals(null, profile.getKeepAliveTime());
assertEquals(null, profile.getMaxQueueSize());
// create a thread pool from big
ExecutorService executor = context.getExecutorServiceManager().newThreadPool(this, "MyBig", "big");
ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
assertEquals(50, tp.getCorePoolSize());
assertEquals(100, tp.getMaximumPoolSize());
// should inherit default options
assertEquals(60, tp.getKeepAliveTime(TimeUnit.SECONDS));
assertEquals("DiscardOldest", tp.getRejectedExecutionHandler().toString());
}
Aggregations