Search in sources :

Example 1 with ContainerScheduledExecutor

use of org.openremote.container.concurrent.ContainerScheduledExecutor in project openremote by openremote.

the class ManagerExecutorService method init.

@Override
public void init(Container container) throws Exception {
    int scheduledTasksThreadsMax = getInteger(container.getConfig(), SCHEDULED_TASKS_THREADS_MAX, SCHEDULED_TASKS_THREADS_MAX_DEFAULT);
    scheduledTasksExecutor = new ContainerScheduledExecutor("Scheduled task", scheduledTasksThreadsMax);
}
Also used : ContainerScheduledExecutor(org.openremote.container.concurrent.ContainerScheduledExecutor)

Example 2 with ContainerScheduledExecutor

use of org.openremote.container.concurrent.ContainerScheduledExecutor 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);
}
Also used : CamelThreadFactory(org.apache.camel.util.concurrent.CamelThreadFactory) CamelThreadFactory(org.apache.camel.util.concurrent.CamelThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) ContainerExecutor(org.openremote.container.concurrent.ContainerExecutor) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Processor(org.apache.camel.Processor) WebService(org.openremote.container.web.WebService) MapAccess.getString(org.openremote.container.util.MapAccess.getString) DefaultWebsocketComponent(org.openremote.container.web.DefaultWebsocketComponent) WebsocketComponent(org.openremote.container.web.socket.WebsocketComponent) DefaultWebsocketComponent(org.openremote.container.web.DefaultWebsocketComponent) IdentityService(org.openremote.container.security.IdentityService) Container(org.openremote.container.Container) ContainerScheduledExecutor(org.openremote.container.concurrent.ContainerScheduledExecutor) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) DefaultStreamCachingStrategy(org.apache.camel.impl.DefaultStreamCachingStrategy) DefaultStreamCachingStrategy(org.apache.camel.impl.DefaultStreamCachingStrategy)

Aggregations

ContainerScheduledExecutor (org.openremote.container.concurrent.ContainerScheduledExecutor)2 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 Processor (org.apache.camel.Processor)1 DefaultStreamCachingStrategy (org.apache.camel.impl.DefaultStreamCachingStrategy)1 CamelThreadFactory (org.apache.camel.util.concurrent.CamelThreadFactory)1 Container (org.openremote.container.Container)1 ContainerExecutor (org.openremote.container.concurrent.ContainerExecutor)1 IdentityService (org.openremote.container.security.IdentityService)1 MapAccess.getString (org.openremote.container.util.MapAccess.getString)1 DefaultWebsocketComponent (org.openremote.container.web.DefaultWebsocketComponent)1 WebService (org.openremote.container.web.WebService)1 WebsocketComponent (org.openremote.container.web.socket.WebsocketComponent)1