use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class AbstractCamelThreadPoolFactoryBean method getObject.
public ExecutorService getObject() throws Exception {
int size = CamelContextHelper.parseInteger(getCamelContext(), poolSize);
if (size <= 0) {
throw new IllegalArgumentException("PoolSize must be a positive number");
}
int max = size;
if (maxPoolSize != null) {
max = CamelContextHelper.parseInteger(getCamelContext(), maxPoolSize);
}
long keepAlive = 60;
if (keepAliveTime != null) {
keepAlive = CamelContextHelper.parseLong(getCamelContext(), keepAliveTime);
}
int queueSize = -1;
if (maxQueueSize != null) {
queueSize = CamelContextHelper.parseInteger(getCamelContext(), maxQueueSize);
}
boolean allow = false;
if (allowCoreThreadTimeOut != null) {
allow = CamelContextHelper.parseBoolean(getCamelContext(), allowCoreThreadTimeOut);
}
ThreadPoolProfile profile = new ThreadPoolProfileBuilder(getId()).poolSize(size).maxPoolSize(max).keepAliveTime(keepAlive, timeUnit).maxQueueSize(queueSize).allowCoreThreadTimeOut(allow).rejectedPolicy(rejectedPolicy).build();
ExecutorService answer;
if (scheduled != null && scheduled) {
answer = getCamelContext().getExecutorServiceManager().newScheduledThreadPool(getId(), getThreadName(), profile);
} else {
answer = getCamelContext().getExecutorServiceManager().newThreadPool(getId(), getThreadName(), profile);
}
return answer;
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class DefaultErrorHandlerBuilder method getExecutorService.
protected synchronized ScheduledExecutorService getExecutorService(CamelContext camelContext) {
if (executorService == null || executorService.isShutdown()) {
// camel context will shutdown the executor when it shutdown so no need to shut it down when stopping
if (executorServiceRef != null) {
executorService = camelContext.getRegistry().lookupByNameAndType(executorServiceRef, ScheduledExecutorService.class);
if (executorService == null) {
ExecutorServiceManager manager = camelContext.getExecutorServiceManager();
ThreadPoolProfile profile = manager.getThreadPoolProfile(executorServiceRef);
executorService = manager.newScheduledThreadPool(this, executorServiceRef, profile);
}
if (executorService == null) {
throw new IllegalArgumentException("ExecutorServiceRef " + executorServiceRef + " not found in registry.");
}
} else {
// no explicit configured thread pool, so leave it up to the error handler to decide if it need
// a default thread pool from CamelContext#getErrorHandlerExecutorService
executorService = null;
}
}
return executorService;
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class CamelCustomDefaultThreadPoolProfileTest method testCamelCustomDefaultThreadPoolProfile.
public void testCamelCustomDefaultThreadPoolProfile() throws Exception {
DefaultExecutorServiceManager manager = (DefaultExecutorServiceManager) context.getExecutorServiceManager();
ThreadPoolProfile profile = manager.getDefaultThreadPoolProfile();
assertEquals(5, profile.getPoolSize().intValue());
assertEquals(15, profile.getMaxPoolSize().intValue());
assertEquals(25, profile.getKeepAliveTime().longValue());
assertEquals(250, profile.getMaxQueueSize().intValue());
assertEquals(true, profile.getAllowCoreThreadTimeOut().booleanValue());
assertEquals(ThreadPoolRejectedPolicy.Abort, profile.getRejectedPolicy());
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class AggregateThreadPoolProfileTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
// create and register thread pool profile
ThreadPoolProfile profile = new ThreadPoolProfile("myProfile");
profile.setPoolSize(2);
profile.setMaxPoolSize(8);
profile.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);
context.getExecutorServiceManager().registerThreadPoolProfile(profile);
from("direct:start").aggregate(header("id"), new BodyInAggregatingStrategy()).completionSize(3).executorServiceRef("myProfile").to("log:foo").to("mock:aggregated");
}
};
}
use of org.apache.camel.spi.ThreadPoolProfile in project camel by apache.
the class DefaultExecutorServiceManager method newThreadPool.
@Override
public ExecutorService newThreadPool(Object source, String name, ThreadPoolProfile profile) {
String sanitizedName = URISupport.sanitizeUri(name);
ObjectHelper.notNull(profile, "ThreadPoolProfile");
ThreadPoolProfile defaultProfile = getDefaultThreadPoolProfile();
profile.addDefaults(defaultProfile);
ThreadFactory threadFactory = createThreadFactory(sanitizedName, true);
ExecutorService executorService = threadPoolFactory.newThreadPool(profile, threadFactory);
onThreadPoolCreated(executorService, source, profile.getId());
if (LOG.isDebugEnabled()) {
LOG.debug("Created new ThreadPool for source: {} with name: {}. -> {}", source, sanitizedName, executorService);
}
return executorService;
}
Aggregations