Search in sources :

Example 16 with NioServerSocketChannelFactory

use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project http-client by biasedbit.

the class DummyHttpServer method init.

// interface ------------------------------------------------------------------------------------------------------
public boolean init() {
    Executor bossExecutor = Executors.newCachedThreadPool();
    Executor workerExecutor = Executors.newCachedThreadPool();
    ChannelFactory factory;
    if (useOldIo)
        factory = new OioServerSocketChannelFactory(bossExecutor, workerExecutor);
    else
        factory = new NioServerSocketChannelFactory(bossExecutor, workerExecutor);
    bootstrap = new ServerBootstrap(factory);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = Channels.pipeline();
            if (useSsl) {
                SSLEngine engine = BogusSslContextFactory.getInstance().getServerContext().createSSLEngine();
                engine.setUseClientMode(false);
                pipeline.addLast("ssl", new SslHandler(engine));
            }
            pipeline.addLast("encoder", new HttpResponseEncoder());
            pipeline.addLast("decoder", new HttpRequestDecoder());
            if (compressionLevel > 0)
                pipeline.addLast("compressor", new HttpContentCompressor(compressionLevel));
            // 5MB
            pipeline.addLast("aggregator", new HttpChunkAggregator(5242880));
            pipeline.addLast("handler", new RequestHandler());
            return pipeline;
        }
    });
    channelGroup = new DefaultChannelGroup("hotpotato-dummy-server-" + Integer.toHexString(hashCode()));
    SocketAddress bindAddress = (host != null) ? new InetSocketAddress(host, port) : new InetSocketAddress(port);
    Channel serverChannel = bootstrap.bind(bindAddress);
    channelGroup.add(serverChannel);
    return (running = serverChannel.isBound());
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) SSLEngine(javax.net.ssl.SSLEngine) InetSocketAddress(java.net.InetSocketAddress) OioServerSocketChannelFactory(org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) SslHandler(org.jboss.netty.handler.ssl.SslHandler) Executor(java.util.concurrent.Executor) OioServerSocketChannelFactory(org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 17 with NioServerSocketChannelFactory

use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project http-client by biasedbit.

the class UploadMirrorHttpServer method init.

// interface ------------------------------------------------------------------------------------------------------
public boolean init() {
    Executor bossExecutor = Executors.newCachedThreadPool();
    Executor workerExecutor = Executors.newCachedThreadPool();
    ChannelFactory factory = new NioServerSocketChannelFactory(bossExecutor, workerExecutor);
    bootstrap = new ServerBootstrap(factory);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = Channels.pipeline();
            if (useSsl) {
                SSLEngine engine = BogusSslContextFactory.getInstance().getServerContext().createSSLEngine();
                engine.setUseClientMode(false);
                pipeline.addLast("ssl", new SslHandler(engine));
            }
            pipeline.addLast("codec", new HttpServerCodec());
            pipeline.addLast("handler", new RequestHandler());
            return pipeline;
        }
    });
    channelGroup = new DefaultChannelGroup("hotpotato-upload-server-" + Integer.toHexString(hashCode()));
    SocketAddress bindAddress = (host != null) ? new InetSocketAddress(host, port) : new InetSocketAddress(port);
    Channel serverChannel = bootstrap.bind(bindAddress);
    channelGroup.add(serverChannel);
    return (running = serverChannel.isBound());
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) SSLEngine(javax.net.ssl.SSLEngine) InetSocketAddress(java.net.InetSocketAddress) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) SslHandler(org.jboss.netty.handler.ssl.SslHandler) Executor(java.util.concurrent.Executor) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 18 with NioServerSocketChannelFactory

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

the class PostgresNetty method doStart.

@Override
protected void doStart() {
    if (!enabled) {
        return;
    }
    bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(daemonThreadFactory(settings, "postgres-netty-boss")), Executors.newCachedThreadPool(daemonThreadFactory(settings, "postgres-netty-worker"))));
    bootstrap.setOption("child.tcpNoDelay", settings.getAsBoolean("tcp_no_delay", true));
    bootstrap.setOption("child.keepAlive", settings.getAsBoolean("tcp_keep_alive", true));
    bootstrap.setPipelineFactory(() -> {
        ChannelPipeline pipeline = Channels.pipeline();
        ConnectionContext connectionContext = new ConnectionContext(sqlOperations);
        pipeline.addLast("frame-decoder", connectionContext.decoder);
        pipeline.addLast("handler", connectionContext.handler);
        return pipeline;
    });
    boolean success = false;
    try {
        boundAddress = resolveBindAddress();
        namedLogger.info("{}", boundAddress);
        success = true;
    } finally {
        if (!success) {
            // stop boss/worker threads to avoid leaks
            doStop();
        }
    }
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 19 with NioServerSocketChannelFactory

use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project socket.io-netty by ibdknox.

the class NSIOServer method start.

public void start() {
    bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
    // Set up the event pipeline factory.
    socketHandler = new WebSocketServerHandler(handler);
    bootstrap.setPipelineFactory(new WebSocketServerPipelineFactory(socketHandler));
    // Bind and start to accept incoming connections.
    this.serverChannel = bootstrap.bind(new InetSocketAddress(port));
    this.running = true;
    try {
        FlashPolicyServer.start();
    } catch (Exception e) {
        //TODO: this should not be exception
        System.out.println("You must run as sudo for flash policy server. X-Domain flash will not currently work.");
    }
    System.out.println("Server Started at port [" + port + "]");
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Example 20 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)27 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)26 InetSocketAddress (java.net.InetSocketAddress)18 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)11 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)10 Channel (org.jboss.netty.channel.Channel)5 ChannelFactory (org.jboss.netty.channel.ChannelFactory)5 Executor (java.util.concurrent.Executor)4 ExecutorService (java.util.concurrent.ExecutorService)4 DefaultChannelGroup (org.jboss.netty.channel.group.DefaultChannelGroup)4 HttpRequestDecoder (org.jboss.netty.handler.codec.http.HttpRequestDecoder)3 HttpResponseEncoder (org.jboss.netty.handler.codec.http.HttpResponseEncoder)3 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)2 IOException (java.io.IOException)2 SocketAddress (java.net.SocketAddress)2 Map (java.util.Map)2 SSLEngine (javax.net.ssl.SSLEngine)2 NioServerBossPool (org.jboss.netty.channel.socket.nio.NioServerBossPool)2 NioWorkerPool (org.jboss.netty.channel.socket.nio.NioWorkerPool)2 OioServerSocketChannelFactory (org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory)2