use of org.apache.camel.util.concurrent.CamelThreadFactory in project camel by apache.
the class DefaultJmsMessageListenerContainer method createDefaultTaskExecutor.
/**
* Create a default TaskExecutor. Called if no explicit TaskExecutor has been specified.
* <p />
* The type of {@link TaskExecutor} will depend on the value of
* {@link JmsConfiguration#getDefaultTaskExecutorType()}. For more details, refer to the Javadoc of
* {@link DefaultTaskExecutorType}.
* <p />
* In all cases, it uses the specified bean name and Camel's {@link org.apache.camel.spi.ExecutorServiceManager}
* to resolve the thread name.
* @see JmsConfiguration#setDefaultTaskExecutorType(DefaultTaskExecutorType)
* @see ThreadPoolTaskExecutor#setBeanName(String)
*/
@Override
protected TaskExecutor createDefaultTaskExecutor() {
String pattern = endpoint.getCamelContext().getExecutorServiceManager().getThreadNamePattern();
String beanName = getBeanName() == null ? endpoint.getThreadName() : getBeanName();
TaskExecutor answer;
if (endpoint.getDefaultTaskExecutorType() == DefaultTaskExecutorType.ThreadPool) {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setBeanName(beanName);
executor.setThreadFactory(new CamelThreadFactory(pattern, beanName, true));
executor.setCorePoolSize(endpoint.getConcurrentConsumers());
// Direct hand-off mode. Do not queue up tasks: assign it to a thread immediately.
// We set no upper-bound on the thread pool (no maxPoolSize) as it's already implicitly constrained by
// maxConcurrentConsumers on the DMLC itself (i.e. DMLC will only grow up to a level of concurrency as
// defined by maxConcurrentConsumers).
executor.setQueueCapacity(0);
executor.initialize();
answer = executor;
} else {
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(beanName);
executor.setThreadFactory(new CamelThreadFactory(pattern, beanName, true));
answer = executor;
}
taskExecutor = answer;
return answer;
}
use of org.apache.camel.util.concurrent.CamelThreadFactory in project camel by apache.
the class DefaultNettySharedHttpServer method doStart.
protected void doStart() throws Exception {
ObjectHelper.notNull(configuration, "setNettyServerBootstrapConfiguration() must be called with a NettyServerBootstrapConfiguration instance", this);
// port must be set
if (configuration.getPort() <= 0) {
throw new IllegalArgumentException("Port must be configured on NettySharedHttpServerBootstrapConfiguration " + configuration);
}
// hostname must be set
if (ObjectHelper.isEmpty(configuration.getHost())) {
throw new IllegalArgumentException("Host must be configured on NettySharedHttpServerBootstrapConfiguration " + configuration);
}
LOG.debug("NettySharedHttpServer using configuration: {}", configuration);
// force using tcp as the underlying transport
configuration.setProtocol("tcp");
channelFactory = new HttpServerMultiplexChannelHandler();
channelFactory.init(configuration.getPort());
ChannelPipelineFactory pipelineFactory = new HttpServerSharedPipelineFactory(configuration, channelFactory, classResolver);
// thread factory and pattern
String port = Matcher.quoteReplacement("" + configuration.getPort());
String pattern = threadPattern;
pattern = pattern.replaceFirst("#port#", port);
ThreadFactory tf = new CamelThreadFactory(pattern, "NettySharedHttpServer", true);
// create bootstrap factory and disable compatible check as its shared among the consumers
bootstrapFactory = new HttpServerBootstrapFactory(channelFactory, false);
bootstrapFactory.init(tf, configuration, pipelineFactory);
ServiceHelper.startServices(channelFactory);
if (startServer) {
LOG.info("Starting NettySharedHttpServer on {}:{}", configuration.getHost(), configuration.getPort());
ServiceHelper.startServices(bootstrapFactory);
}
}
use of org.apache.camel.util.concurrent.CamelThreadFactory in project camel by apache.
the class DefaultNettySharedHttpServer method doStart.
protected void doStart() throws Exception {
ObjectHelper.notNull(configuration, "setNettyServerBootstrapConfiguration() must be called with a NettyServerBootstrapConfiguration instance", this);
// port must be set
if (configuration.getPort() <= 0) {
throw new IllegalArgumentException("Port must be configured on NettySharedHttpServerBootstrapConfiguration " + configuration);
}
// hostname must be set
if (ObjectHelper.isEmpty(configuration.getHost())) {
throw new IllegalArgumentException("Host must be configured on NettySharedHttpServerBootstrapConfiguration " + configuration);
}
LOG.debug("NettySharedHttpServer using configuration: {}", configuration);
// force using tcp as the underlying transport
configuration.setProtocol("tcp");
channelFactory = new HttpServerMultiplexChannelHandler();
channelFactory.init(configuration.getPort());
ChannelInitializer<Channel> pipelineFactory = new HttpServerSharedInitializerFactory(configuration, channelFactory, classResolver);
// thread factory and pattern
String port = Matcher.quoteReplacement("" + configuration.getPort());
String pattern = threadPattern;
pattern = pattern.replaceFirst("#port#", port);
ThreadFactory tf = new CamelThreadFactory(pattern, "NettySharedHttpServer", true);
// create bootstrap factory and disable compatible check as its shared among the consumers
bootstrapFactory = new HttpServerBootstrapFactory(channelFactory, false);
bootstrapFactory.init(tf, configuration, pipelineFactory);
ServiceHelper.startServices(channelFactory);
if (startServer) {
LOG.info("Starting NettySharedHttpServer on {}:{}", configuration.getHost(), configuration.getPort());
ServiceHelper.startServices(bootstrapFactory);
}
}
use of org.apache.camel.util.concurrent.CamelThreadFactory in project camel by apache.
the class NettyComponent method createExecutorService.
protected OrderedMemoryAwareThreadPoolExecutor createExecutorService() {
// use ordered thread pool, to ensure we process the events in order, and can send back
// replies in the expected order. eg this is required by TCP.
// and use a Camel thread factory so we have consistent thread namings
// we should use a shared thread pool as recommended by Netty
// NOTE: if we don't specify the MaxChannelMemorySize and MaxTotalMemorySize, the thread pool
// could eat up all the heap memory when the tasks are added very fast
String pattern = getCamelContext().getExecutorServiceManager().getThreadNamePattern();
ThreadFactory factory = new CamelThreadFactory(pattern, "NettyOrderedWorker", true);
return new OrderedMemoryAwareThreadPoolExecutor(getMaximumPoolSize(), configuration.getMaxChannelMemorySize(), configuration.getMaxTotalMemorySize(), 30, TimeUnit.SECONDS, factory);
}
use of org.apache.camel.util.concurrent.CamelThreadFactory in project camel by apache.
the class NettyComponent method createExecutorService.
protected EventExecutorGroup createExecutorService() {
// Provide the executor service for the application
// and use a Camel thread factory so we have consistent thread namings
// we should use a shared thread pool as recommended by Netty
String pattern = getCamelContext().getExecutorServiceManager().getThreadNamePattern();
ThreadFactory factory = new CamelThreadFactory(pattern, "NettyEventExecutorGroup", true);
return new DefaultEventExecutorGroup(getMaximumPoolSize(), factory);
}
Aggregations