Search in sources :

Example 6 with NamedThreadFactory

use of org.apache.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(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.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("backlog", getUrl().getPositiveParameter(BACKLOG_KEY, Constants.DEFAULT_BACKLOG));
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        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(org.apache.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 7 with NamedThreadFactory

use of org.apache.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(IO_THREADS_KEY, DEFAULT_IO_THREADS), Executors.newCachedThreadPool(new NamedThreadFactory("MinaServerWorker", true)));
    // config
    SocketAcceptorConfig cfg = 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(org.apache.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)

Aggregations

NamedThreadFactory (org.apache.dubbo.common.utils.NamedThreadFactory)7 Test (org.junit.jupiter.api.Test)4 ProtocolCodecFilter (org.apache.mina.filter.codec.ProtocolCodecFilter)2 WeakReference (java.lang.ref.WeakReference)1 LinkedList (java.util.LinkedList)1 ExecutorService (java.util.concurrent.ExecutorService)1 AbortPolicyWithReport (org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport)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