use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class DefaultExecutorServiceStrategy method newThreadPool.
public ExecutorService newThreadPool(Object source, String name, int corePoolSize, int maxPoolSize, int maxQueueSize) {
// use a profile with the settings
ThreadPoolProfile profile = new ThreadPoolProfile();
profile.setPoolSize(corePoolSize);
profile.setMaxPoolSize(maxPoolSize);
profile.setMaxQueueSize(maxQueueSize);
return camelContext.getExecutorServiceManager().newThreadPool(source, name, profile);
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class DefaultExecutorServiceStrategy method newThreadPool.
public ExecutorService newThreadPool(Object source, String name, int corePoolSize, int maxPoolSize, long keepAliveTime, TimeUnit timeUnit, int maxQueueSize, RejectedExecutionHandler rejectedExecutionHandler, boolean daemon) {
// use a profile with the settings
ThreadPoolProfile profile = new ThreadPoolProfile();
profile.setPoolSize(corePoolSize);
profile.setMaxPoolSize(maxPoolSize);
profile.setMaxQueueSize(maxQueueSize);
profile.setKeepAliveTime(keepAliveTime);
profile.setTimeUnit(timeUnit);
// must cast to ThreadPoolExecutor to be able to set the rejected execution handler
ThreadPoolExecutor answer = (ThreadPoolExecutor) camelContext.getExecutorServiceManager().newThreadPool(source, name, profile);
answer.setRejectedExecutionHandler(rejectedExecutionHandler);
return answer;
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class DefaultExecutorServiceStrategy method lookupScheduled.
public ScheduledExecutorService lookupScheduled(Object source, String name, String executorServiceRef) {
ScheduledExecutorService answer = camelContext.getRegistry().lookupByNameAndType(executorServiceRef, ScheduledExecutorService.class);
if (answer == null) {
ThreadPoolProfile profile = getThreadPoolProfile(executorServiceRef);
if (profile != null) {
Integer poolSize = profile.getPoolSize();
if (poolSize == null) {
poolSize = getDefaultThreadPoolProfile().getPoolSize();
}
answer = newScheduledThreadPool(source, name, poolSize);
}
}
return answer;
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class DefaultExecutorServiceManagerTest method testNewThreadPoolProfileById.
public void testNewThreadPoolProfileById() 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);
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 DefaultExecutorServiceManagerTest method testNewScheduledThreadPoolProfileById.
public void testNewScheduledThreadPoolProfileById() 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);
ExecutorService pool = context.getExecutorServiceManager().newScheduledThreadPool(this, "Cool", "foo");
assertNotNull(pool);
SizedScheduledExecutorService tp = assertIsInstanceOf(SizedScheduledExecutorService.class, pool);
// a scheduled dont use keep alive
assertEquals(0, tp.getKeepAliveTime(TimeUnit.SECONDS));
assertEquals(Integer.MAX_VALUE, tp.getMaximumPoolSize());
assertEquals(5, tp.getCorePoolSize());
assertFalse(tp.isShutdown());
context.stop();
assertTrue(tp.isShutdown());
}
Aggregations