Search in sources :

Example 6 with Container

use of org.openremote.container.Container 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

Container (org.openremote.container.Container)6 Logger (java.util.logging.Logger)3 ContainerService (org.openremote.container.ContainerService)3 MessageBrokerService (org.openremote.container.message.MessageBrokerService)3 MessageBrokerSetupService (org.openremote.container.message.MessageBrokerSetupService)3 TimerService (org.openremote.container.timer.TimerService)3 ManagerExecutorService (org.openremote.manager.concurrent.ManagerExecutorService)3 java.util (java.util)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 ManagerPersistenceService (org.openremote.manager.persistence.ManagerPersistenceService)2 ManagerIdentityService (org.openremote.manager.security.ManagerIdentityService)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)1 Point (com.vividsolutions.jts.geom.Point)1 Undertow (io.undertow.Undertow)1 HttpHandler (io.undertow.server.HttpHandler)1 PathHandler (io.undertow.server.handlers.PathHandler)1 RedirectHandler (io.undertow.server.handlers.RedirectHandler)1 RequestDumpingHandler (io.undertow.server.handlers.RequestDumpingHandler)1 Servlets (io.undertow.servlet.Servlets)1