Search in sources :

Example 1 with NamedThreadFactory

use of com.alibaba.dubbo.common.utils.NamedThreadFactory in project dubbo by alibaba.

the class MinaServer method doOpen.

@Override
protected void doOpen() throws Throwable {
    // set thread pool.
    acceptor = new SocketAcceptor(getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS), Executors.newCachedThreadPool(new NamedThreadFactory("MinaServerWorker", true)));
    // config
    SocketAcceptorConfig cfg = (SocketAcceptorConfig) acceptor.getDefaultConfig();
    cfg.setThreadModel(ThreadModel.MANUAL);
    // set codec.
    acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecAdapter(getCodec(), getUrl(), this)));
    acceptor.bind(getBindAddress(), new MinaHandler(getUrl(), this));
}
Also used : NamedThreadFactory(com.alibaba.dubbo.common.utils.NamedThreadFactory) SocketAcceptorConfig(org.apache.mina.transport.socket.nio.SocketAcceptorConfig) SocketAcceptor(org.apache.mina.transport.socket.nio.SocketAcceptor) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter)

Example 2 with NamedThreadFactory

use of com.alibaba.dubbo.common.utils.NamedThreadFactory in project dubbo by alibaba.

the class NettyServer method doOpen.

@Override
protected void doOpen() throws Throwable {
    NettyHelper.setNettyLoggerFactory();
    ExecutorService boss = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerBoss", true));
    ExecutorService worker = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerWorker", true));
    ChannelFactory channelFactory = new NioServerSocketChannelFactory(boss, worker, getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS));
    bootstrap = new ServerBootstrap(channelFactory);
    final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
    channels = nettyHandler.getChannels();
    // https://issues.jboss.org/browse/NETTY-365
    // https://issues.jboss.org/browse/NETTY-379
    // final Timer timer = new HashedWheelTimer(new NamedThreadFactory("NettyIdleTimer", true));
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        public ChannelPipeline getPipeline() {
            NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyServer.this);
            ChannelPipeline pipeline = Channels.pipeline();
            /*int idleTimeout = getIdleTimeout();
                if (idleTimeout > 10000) {
                    pipeline.addLast("timer", new IdleStateHandler(timer, idleTimeout / 1000, 0, 0));
                }*/
            pipeline.addLast("decoder", adapter.getDecoder());
            pipeline.addLast("encoder", adapter.getEncoder());
            pipeline.addLast("handler", nettyHandler);
            return pipeline;
        }
    });
    // bind
    channel = bootstrap.bind(getBindAddress());
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) NamedThreadFactory(com.alibaba.dubbo.common.utils.NamedThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ChannelFactory(org.jboss.netty.channel.ChannelFactory) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 3 with NamedThreadFactory

use of com.alibaba.dubbo.common.utils.NamedThreadFactory in project dubbo by alibaba.

the class FixedThreadPool method getExecutor.

public Executor getExecutor(URL url) {
    String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME);
    int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
    int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES);
    return new ThreadPoolExecutor(threads, threads, 0, TimeUnit.MILLISECONDS, queues == 0 ? new SynchronousQueue<Runnable>() : (queues < 0 ? new LinkedBlockingQueue<Runnable>() : new LinkedBlockingQueue<Runnable>(queues)), new NamedThreadFactory(name, true), new AbortPolicyWithReport(name, url));
}
Also used : NamedThreadFactory(com.alibaba.dubbo.common.utils.NamedThreadFactory) SynchronousQueue(java.util.concurrent.SynchronousQueue) AbortPolicyWithReport(com.alibaba.dubbo.common.threadpool.support.AbortPolicyWithReport) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 4 with NamedThreadFactory

use of com.alibaba.dubbo.common.utils.NamedThreadFactory in project dubbo by alibaba.

the class LimitedThreadPool method getExecutor.

public Executor getExecutor(URL url) {
    String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME);
    int cores = url.getParameter(Constants.CORE_THREADS_KEY, Constants.DEFAULT_CORE_THREADS);
    int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
    int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES);
    return new ThreadPoolExecutor(cores, threads, Long.MAX_VALUE, TimeUnit.MILLISECONDS, queues == 0 ? new SynchronousQueue<Runnable>() : (queues < 0 ? new LinkedBlockingQueue<Runnable>() : new LinkedBlockingQueue<Runnable>(queues)), new NamedThreadFactory(name, true), new AbortPolicyWithReport(name, url));
}
Also used : NamedThreadFactory(com.alibaba.dubbo.common.utils.NamedThreadFactory) SynchronousQueue(java.util.concurrent.SynchronousQueue) AbortPolicyWithReport(com.alibaba.dubbo.common.threadpool.support.AbortPolicyWithReport) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 5 with NamedThreadFactory

use of com.alibaba.dubbo.common.utils.NamedThreadFactory in project dubbo by alibaba.

the class CachedThreadPool method getExecutor.

public Executor getExecutor(URL url) {
    String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME);
    int cores = url.getParameter(Constants.CORE_THREADS_KEY, Constants.DEFAULT_CORE_THREADS);
    int threads = url.getParameter(Constants.THREADS_KEY, Integer.MAX_VALUE);
    int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES);
    int alive = url.getParameter(Constants.ALIVE_KEY, Constants.DEFAULT_ALIVE);
    return new ThreadPoolExecutor(cores, threads, alive, TimeUnit.MILLISECONDS, queues == 0 ? new SynchronousQueue<Runnable>() : (queues < 0 ? new LinkedBlockingQueue<Runnable>() : new LinkedBlockingQueue<Runnable>(queues)), new NamedThreadFactory(name, true), new AbortPolicyWithReport(name, url));
}
Also used : NamedThreadFactory(com.alibaba.dubbo.common.utils.NamedThreadFactory) SynchronousQueue(java.util.concurrent.SynchronousQueue) AbortPolicyWithReport(com.alibaba.dubbo.common.threadpool.support.AbortPolicyWithReport) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Aggregations

NamedThreadFactory (com.alibaba.dubbo.common.utils.NamedThreadFactory)7 AbortPolicyWithReport (com.alibaba.dubbo.common.threadpool.support.AbortPolicyWithReport)4 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)3 SynchronousQueue (java.util.concurrent.SynchronousQueue)3 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3 ProtocolCodecFilter (org.apache.mina.filter.codec.ProtocolCodecFilter)2 URL (com.alibaba.dubbo.common.URL)1 ExecutorService (java.util.concurrent.ExecutorService)1 SocketAcceptor (org.apache.mina.transport.socket.nio.SocketAcceptor)1 SocketAcceptorConfig (org.apache.mina.transport.socket.nio.SocketAcceptorConfig)1 SocketConnector (org.apache.mina.transport.socket.nio.SocketConnector)1 SocketConnectorConfig (org.apache.mina.transport.socket.nio.SocketConnectorConfig)1 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)1 ChannelFactory (org.jboss.netty.channel.ChannelFactory)1 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)1 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)1 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)1 Test (org.junit.Test)1