use of org.apache.camel.impl.DefaultStreamCachingStrategy in project openremote by openremote.
the class MessageBrokerSetupService method init.
@Override
public void init(Container container) throws Exception {
context = new MessageBrokerContext();
final ExecutorServiceManager executorServiceManager = context.getExecutorServiceManager();
executorServiceManager.setThreadNamePattern("#counter# #name#");
executorServiceManager.setThreadPoolFactory(new ThreadPoolFactory() {
@Override
public ExecutorService newCachedThreadPool(ThreadFactory threadFactory) {
// This is an unlimited pool used probably only be multicast aggregation
return new ContainerExecutor(getExecutorName("MessagingPool", threadFactory), 1, Integer.MAX_VALUE, 10, -1);
}
@Override
public ExecutorService newThreadPool(ThreadPoolProfile profile, ThreadFactory threadFactory) {
// This pool is used by SEDA consumers, so the endpoint parameters define the pool and queue sizes
return new ContainerExecutor(getExecutorName("Messaging", threadFactory), profile.getPoolSize(), profile.getMaxPoolSize(), profile.getKeepAliveTime(), profile.getMaxQueueSize());
}
@Override
public ScheduledExecutorService newScheduledThreadPool(ThreadPoolProfile profile, ThreadFactory threadFactory) {
return new ContainerScheduledExecutor(getExecutorName("MessagingTasks", threadFactory), profile.getPoolSize());
}
protected String getExecutorName(String name, ThreadFactory threadFactory) {
if (threadFactory instanceof CamelThreadFactory) {
CamelThreadFactory factory = (CamelThreadFactory) threadFactory;
String camelName = factory.getName();
camelName = camelName.contains("://") ? StringHelper.after(camelName, "://") : camelName;
camelName = camelName.contains("?") ? StringHelper.before(camelName, "?") : camelName;
name = name + "-" + camelName;
}
return name;
}
});
// TODO make configurable in environment
context.disableJMX();
// TODO might need this for errorhandler?
context.setAllowUseOriginalMessage(false);
// Don't use JMS, we do our own correlation
context.setUseBreadcrumb(false);
// Force a quick shutdown of routes with in-flight exchanges
context.getShutdownStrategy().setTimeout(1);
context.getShutdownStrategy().setSuppressLoggingOnTimeout(true);
context.setStreamCaching(true);
StreamCachingStrategy streamCachingStrategy = new DefaultStreamCachingStrategy();
// Half megabyte
streamCachingStrategy.setSpoolThreshold(524288);
context.setStreamCachingStrategy(streamCachingStrategy);
context.setErrorHandlerBuilder(new org.apache.camel.builder.LoggingErrorHandlerBuilder() {
@Override
public Processor createErrorHandler(RouteContext routeContext, Processor processor) {
// TODO: Custom error handler?
return super.createErrorHandler(routeContext, processor);
}
});
context.getRegistry().put(Container.class.getName(), container);
String allowedOrigin = getString(container.getConfig(), MESSAGE_SESSION_ALLOWED_ORIGIN, MESSAGE_SESSION_ALLOWED_ORIGIN_DEFAULT);
WebsocketComponent websocketComponent = new DefaultWebsocketComponent(container.getService(IdentityService.class), container.getService(WebService.class), allowedOrigin);
context.addComponent(WebsocketComponent.NAME, websocketComponent);
}
Aggregations