Search in sources :

Example 41 with NioServerSocketChannelFactory

use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project NabAlive by jcheype.

the class HttpServer method start.

public void start() {
    // Timer timer = new HashedWheelTimer();
    System.out.println("Runtime.getRuntime().availableProcessors(): " + Runtime.getRuntime().availableProcessors());
    // ExecutorService bossExec = new OrderedMemoryAwareThreadPoolExecutor(2, 400000000, 2000000000, 60, TimeUnit.SECONDS);
    // ExecutorService ioExec = new OrderedMemoryAwareThreadPoolExecutor(Runtime.getRuntime().availableProcessors() + 1, 400000000, 2000000000, 60, TimeUnit.SECONDS);
    // 
    // bootstrap = new ServerBootstrap(
    // new NioServerSocketChannelFactory(bossExec, ioExec, Runtime.getRuntime().availableProcessors() + 1));
    // Configure the server.
    bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.keepAlive", true);
    bootstrap.setOption("receiveBufferSize", 128 * 1024);
    bootstrap.setOption("sendBufferSize", 128 * 1024);
    bootstrap.setOption("reuseAddress", true);
    bootstrap.setOption("backlog", 16384);
    final HttpApiServerHandler httpApiServerHandler = new HttpApiServerHandler(restHandler);
    // Set up the event pipeline factory.
    bootstrap.setPipelineFactory(new HttpApiServerPipelineFactory(httpApiServerHandler));
    // Bind and start to accept incoming connections.
    Channel c = bootstrap.bind(new InetSocketAddress(port));
    cg.add(c);
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.netty.channel.Channel) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Aggregations

NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)41 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)39 InetSocketAddress (java.net.InetSocketAddress)30 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)16 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)12 ChannelFactory (org.jboss.netty.channel.ChannelFactory)9 ExecutorService (java.util.concurrent.ExecutorService)6 Channel (org.jboss.netty.channel.Channel)6 Executor (java.util.concurrent.Executor)5 DefaultChannelGroup (org.jboss.netty.channel.group.DefaultChannelGroup)5 IOException (java.io.IOException)4 NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)4 NioServerBossPool (org.jboss.netty.channel.socket.nio.NioServerBossPool)4 NioWorkerPool (org.jboss.netty.channel.socket.nio.NioWorkerPool)4 InetAddress (java.net.InetAddress)3 OioServerSocketChannelFactory (org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory)3 HttpRequestDecoder (org.jboss.netty.handler.codec.http.HttpRequestDecoder)3 HttpResponseEncoder (org.jboss.netty.handler.codec.http.HttpResponseEncoder)3 Bean (org.springframework.context.annotation.Bean)3 FixedHeaderFrameDecoder (com.alibaba.otter.canal.server.netty.handler.FixedHeaderFrameDecoder)2