Search in sources :

Example 1 with ActiveMQThreadFactory

use of org.apache.activemq.artemis.utils.ActiveMQThreadFactory in project activemq-artemis by apache.

the class NettyAcceptor method start.

@Override
public synchronized void start() throws Exception {
    if (channelClazz != null) {
        // Already started
        return;
    }
    String acceptorType;
    if (useInvm) {
        acceptorType = INVM_ACCEPTOR_TYPE;
        channelClazz = LocalServerChannel.class;
        eventLoopGroup = new DefaultEventLoopGroup();
    } else {
        if (remotingThreads == -1) {
            // Default to number of cores * 3
            remotingThreads = Runtime.getRuntime().availableProcessors() * 3;
        }
        if (useEpoll && Epoll.isAvailable()) {
            channelClazz = EpollServerSocketChannel.class;
            eventLoopGroup = new EpollEventLoopGroup(remotingThreads, AccessController.doPrivileged(new PrivilegedAction<ActiveMQThreadFactory>() {

                @Override
                public ActiveMQThreadFactory run() {
                    return new ActiveMQThreadFactory("activemq-netty-threads", true, ClientSessionFactoryImpl.class.getClassLoader());
                }
            }));
            acceptorType = EPOLL_ACCEPTOR_TYPE;
            logger.debug("Acceptor using native epoll");
        } else if (useKQueue && KQueue.isAvailable()) {
            channelClazz = KQueueServerSocketChannel.class;
            eventLoopGroup = new KQueueEventLoopGroup(remotingThreads, AccessController.doPrivileged(new PrivilegedAction<ActiveMQThreadFactory>() {

                @Override
                public ActiveMQThreadFactory run() {
                    return new ActiveMQThreadFactory("activemq-netty-threads", true, ClientSessionFactoryImpl.class.getClassLoader());
                }
            }));
            acceptorType = KQUEUE_ACCEPTOR_TYPE;
            logger.debug("Acceptor using native kqueue");
        } else {
            channelClazz = NioServerSocketChannel.class;
            eventLoopGroup = new NioEventLoopGroup(remotingThreads, AccessController.doPrivileged(new PrivilegedAction<ActiveMQThreadFactory>() {

                @Override
                public ActiveMQThreadFactory run() {
                    return new ActiveMQThreadFactory("activemq-netty-threads", true, ClientSessionFactoryImpl.class.getClassLoader());
                }
            }));
            acceptorType = NIO_ACCEPTOR_TYPE;
            logger.debug("Acceptor using nio");
        }
    }
    bootstrap = new ServerBootstrap();
    bootstrap.group(eventLoopGroup);
    bootstrap.channel(channelClazz);
    ChannelInitializer<Channel> factory = new ChannelInitializer<Channel>() {

        @Override
        public void initChannel(Channel channel) throws Exception {
            ChannelPipeline pipeline = channel.pipeline();
            if (sslEnabled) {
                pipeline.addLast("ssl", getSslHandler(channel.alloc()));
                pipeline.addLast("sslHandshakeExceptionHandler", new SslHandshakeExceptionHandler());
            }
            pipeline.addLast(protocolHandler.getProtocolDecoder());
        }
    };
    bootstrap.childHandler(factory);
    // Bind
    bootstrap.childOption(ChannelOption.TCP_NODELAY, tcpNoDelay);
    if (tcpReceiveBufferSize != -1) {
        bootstrap.childOption(ChannelOption.SO_RCVBUF, tcpReceiveBufferSize);
    }
    if (tcpSendBufferSize != -1) {
        bootstrap.childOption(ChannelOption.SO_SNDBUF, tcpSendBufferSize);
    }
    final int writeBufferLowWaterMark = this.writeBufferLowWaterMark != -1 ? this.writeBufferLowWaterMark : WriteBufferWaterMark.DEFAULT.low();
    final int writeBufferHighWaterMark = this.writeBufferHighWaterMark != -1 ? this.writeBufferHighWaterMark : WriteBufferWaterMark.DEFAULT.high();
    final WriteBufferWaterMark writeBufferWaterMark = new WriteBufferWaterMark(writeBufferLowWaterMark, writeBufferHighWaterMark);
    bootstrap.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, writeBufferWaterMark);
    if (backlog != -1) {
        bootstrap.option(ChannelOption.SO_BACKLOG, backlog);
    }
    bootstrap.option(ChannelOption.SO_REUSEADDR, true);
    bootstrap.childOption(ChannelOption.SO_REUSEADDR, true);
    bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
    channelGroup = new DefaultChannelGroup("activemq-accepted-channels", GlobalEventExecutor.INSTANCE);
    serverChannelGroup = new DefaultChannelGroup("activemq-acceptor-channels", GlobalEventExecutor.INSTANCE);
    if (httpUpgradeEnabled) {
    // the channel will be bound by the Web container and hand over after the HTTP Upgrade
    // handshake is successful
    } else {
        startServerChannels();
        paused = false;
        if (notificationService != null) {
            TypedProperties props = new TypedProperties();
            props.putSimpleStringProperty(new SimpleString("factory"), new SimpleString(NettyAcceptorFactory.class.getName()));
            props.putSimpleStringProperty(new SimpleString("host"), new SimpleString(host));
            props.putIntProperty(new SimpleString("port"), port);
            Notification notification = new Notification(null, CoreNotificationType.ACCEPTOR_STARTED, props);
            notificationService.sendNotification(notification);
        }
        ActiveMQServerLogger.LOGGER.startedAcceptor(acceptorType, host, port, protocolsString);
    }
    if (batchDelay > 0) {
        flusher = new BatchFlusher();
        batchFlusherFuture = scheduledThreadPool.scheduleWithFixedDelay(flusher, batchDelay, batchDelay, TimeUnit.MILLISECONDS);
    }
}
Also used : ActiveMQThreadFactory(org.apache.activemq.artemis.utils.ActiveMQThreadFactory) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) Notification(org.apache.activemq.artemis.core.server.management.Notification) ClientSessionFactoryImpl(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl) PrivilegedAction(java.security.PrivilegedAction) WriteBufferWaterMark(io.netty.channel.WriteBufferWaterMark) ChannelInitializer(io.netty.channel.ChannelInitializer) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) KQueueServerSocketChannel(io.netty.channel.kqueue.KQueueServerSocketChannel) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) LocalServerChannel(io.netty.channel.local.LocalServerChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ServerChannel(io.netty.channel.ServerChannel) KQueueServerSocketChannel(io.netty.channel.kqueue.KQueueServerSocketChannel) EpollServerSocketChannel(io.netty.channel.epoll.EpollServerSocketChannel) Channel(io.netty.channel.Channel) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) KQueueEventLoopGroup(io.netty.channel.kqueue.KQueueEventLoopGroup)

Example 2 with ActiveMQThreadFactory

use of org.apache.activemq.artemis.utils.ActiveMQThreadFactory in project activemq-artemis by apache.

the class DiscoveryStayAliveTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    scheduledExecutorService = new ScheduledThreadPoolExecutor(1, new ActiveMQThreadFactory("ActiveMQ-scheduled-threads", false, Thread.currentThread().getContextClassLoader()));
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ActiveMQThreadFactory(org.apache.activemq.artemis.utils.ActiveMQThreadFactory) Before(org.junit.Before)

Example 3 with ActiveMQThreadFactory

use of org.apache.activemq.artemis.utils.ActiveMQThreadFactory in project activemq-artemis by apache.

the class InVMConnector method resetThreadPool.

public static synchronized void resetThreadPool() {
    if (threadPoolExecutor != null) {
        threadPoolExecutor.shutdownNow();
        if (threadPoolExecutor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor tp = (ThreadPoolExecutor) threadPoolExecutor;
            if (tp.getThreadFactory() instanceof ActiveMQThreadFactory) {
                ActiveMQThreadFactory tf = (ActiveMQThreadFactory) tp.getThreadFactory();
                if (!tf.join(10, TimeUnit.SECONDS)) {
                    // resetThreadPool is only used on tests.
                    // no need to use a logger method, this is just fine.
                    logger.warn("Thread pool is still busy. couldn't stop on time");
                }
            }
        }
        threadPoolExecutor = null;
    }
}
Also used : ActiveMQThreadFactory(org.apache.activemq.artemis.utils.ActiveMQThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ActiveMQThreadPoolExecutor(org.apache.activemq.artemis.utils.ActiveMQThreadPoolExecutor)

Example 4 with ActiveMQThreadFactory

use of org.apache.activemq.artemis.utils.ActiveMQThreadFactory in project activemq-artemis by apache.

the class RemotingServiceImpl method start.

@Override
public synchronized void start() throws Exception {
    if (started) {
        return;
    }
    logger.tracef("Starting remoting service %s", this);
    paused = false;
    // The remoting service maintains it's own thread pool for handling remoting traffic
    // If OIO each connection will have it's own thread
    // If NIO these are capped at nio-remoting-threads which defaults to num cores * 3
    // This needs to be a different thread pool to the main thread pool especially for OIO where we may need
    // to support many hundreds of connections, but the main thread pool must be kept small for better performance
    ThreadFactory tFactory = AccessController.doPrivileged(new PrivilegedAction<ThreadFactory>() {

        @Override
        public ThreadFactory run() {
            return new ActiveMQThreadFactory("ActiveMQ-remoting-threads-" + server.toString() + "-" + System.identityHashCode(this), false, Thread.currentThread().getContextClassLoader());
        }
    });
    threadPool = Executors.newCachedThreadPool(tFactory);
    for (TransportConfiguration info : acceptorsConfig) {
        createAcceptor(info);
    }
    /**
     * Don't start the acceptors here.  Only start the acceptors at the every end of the start-up process to avoid
     * race conditions. See {@link #startAcceptors()}.
     */
    // This thread checks connections that need to be closed, and also flushes confirmations
    failureCheckAndFlushThread = new FailureCheckAndFlushThread(connectionTtlCheckInterval);
    failureCheckAndFlushThread.start();
    started = true;
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ActiveMQThreadFactory(org.apache.activemq.artemis.utils.ActiveMQThreadFactory) ActiveMQThreadFactory(org.apache.activemq.artemis.utils.ActiveMQThreadFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration)

Example 5 with ActiveMQThreadFactory

use of org.apache.activemq.artemis.utils.ActiveMQThreadFactory in project activemq-artemis by apache.

the class ActiveMQClient method getGlobalScheduledThreadPool.

public static synchronized ScheduledExecutorService getGlobalScheduledThreadPool() {
    if (globalScheduledThreadPool == null) {
        ThreadFactory factory = AccessController.doPrivileged(new PrivilegedAction<ThreadFactory>() {

            @Override
            public ThreadFactory run() {
                return new ActiveMQThreadFactory("ActiveMQ-client-global-scheduled-threads", true, ClientSessionFactoryImpl.class.getClassLoader());
            }
        });
        globalScheduledThreadPool = new ScheduledThreadPoolExecutor(ActiveMQClient.globalScheduledThreadPoolSize, factory);
    }
    return globalScheduledThreadPool;
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ActiveMQThreadFactory(org.apache.activemq.artemis.utils.ActiveMQThreadFactory) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ActiveMQThreadFactory(org.apache.activemq.artemis.utils.ActiveMQThreadFactory)

Aggregations

ActiveMQThreadFactory (org.apache.activemq.artemis.utils.ActiveMQThreadFactory)8 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)4 ThreadFactory (java.util.concurrent.ThreadFactory)4 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3 OrderedExecutorFactory (org.apache.activemq.artemis.utils.actors.OrderedExecutorFactory)3 SynchronousQueue (java.util.concurrent.SynchronousQueue)2 ActiveMQThreadPoolExecutor (org.apache.activemq.artemis.utils.ActiveMQThreadPoolExecutor)2 Before (org.junit.Before)2 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 Channel (io.netty.channel.Channel)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 DefaultEventLoopGroup (io.netty.channel.DefaultEventLoopGroup)1 ServerChannel (io.netty.channel.ServerChannel)1 WriteBufferWaterMark (io.netty.channel.WriteBufferWaterMark)1 EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)1 EpollServerSocketChannel (io.netty.channel.epoll.EpollServerSocketChannel)1 DefaultChannelGroup (io.netty.channel.group.DefaultChannelGroup)1 KQueueEventLoopGroup (io.netty.channel.kqueue.KQueueEventLoopGroup)1 KQueueServerSocketChannel (io.netty.channel.kqueue.KQueueServerSocketChannel)1