Search in sources :

Example 1 with NioServerSocketChannelFactory

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

the class TrackerService method startUp.

@Override
protected void startUp() throws Exception {
    Executor bossThreads = Executors.newFixedThreadPool(NUM_BOSS_THREADS, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("boss-thread").build());
    Executor workerThreads = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("worker-thread#%d").build());
    ChannelFactory factory = new NioServerSocketChannelFactory(bossThreads, workerThreads);
    bootstrap = new ServerBootstrap(factory);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        public ChannelPipeline getPipeline() {
            ChannelPipeline pipeline = Channels.pipeline();
            pipeline.addLast("decoder", new HttpRequestDecoder());
            pipeline.addLast("aggregator", new HttpChunkAggregator(MAX_INPUT_SIZE));
            pipeline.addLast("encoder", new HttpResponseEncoder());
            pipeline.addLast("compressor", new HttpContentCompressor());
            pipeline.addLast("handler", new ReportHandler(resourceReport));
            return pipeline;
        }
    });
    Channel channel = bootstrap.bind(new InetSocketAddress(host, 0));
    bindAddress = (InetSocketAddress) channel.getLocalAddress();
    url = URI.create(String.format("http://%s:%d", host, bindAddress.getPort())).resolve(TrackerService.PATH).toURL();
    channelGroup.add(channel);
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) HttpContentCompressor(org.jboss.netty.handler.codec.http.HttpContentCompressor) InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.netty.channel.Channel) HttpChunkAggregator(org.jboss.netty.handler.codec.http.HttpChunkAggregator) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ChannelFactory(org.jboss.netty.channel.ChannelFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) Executor(java.util.concurrent.Executor) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory)

Example 2 with NioServerSocketChannelFactory

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

the class NetworkReceiver method start.

@Override
public void start() throws Throwable {
    channels = new DefaultChannelGroup();
    // Listen for incoming connections
    nioChannelFactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(daemon("Cluster boss", monitor)), Executors.newFixedThreadPool(2, daemon("Cluster worker", monitor)), 2);
    serverBootstrap = new ServerBootstrap(nioChannelFactory);
    serverBootstrap.setOption("child.tcpNoDelay", true);
    serverBootstrap.setPipelineFactory(new NetworkNodePipelineFactory());
    int[] ports = config.clusterServer().getPorts();
    int minPort = ports[0];
    int maxPort = ports.length == 2 ? ports[1] : minPort;
    // Try all ports in the given range
    port = listen(minPort, maxPort);
    msgLog.debug("Started NetworkReceiver at " + config.clusterServer().getHost() + ":" + port);
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Example 3 with NioServerSocketChannelFactory

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

the class Server method start.

@Override
public void start() throws Throwable {
    String className = getClass().getSimpleName();
    ExecutorService bossExecutor = newCachedThreadPool(daemon("Boss-" + className));
    ExecutorService workerExecutor = newCachedThreadPool(daemon("Worker-" + className));
    bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(bossExecutor, workerExecutor, config.getMaxConcurrentTransactions()));
    bootstrap.setPipelineFactory(this);
    PortRangeSocketBinder portRangeSocketBinder = new PortRangeSocketBinder(bootstrap);
    try {
        Connection connection = portRangeSocketBinder.bindToFirstAvailablePortInRange(config.getServerAddress());
        Channel channel = connection.getChannel();
        socketAddress = connection.getSocketAddress();
        channelGroup = new DefaultChannelGroup();
        channelGroup.add(channel);
        msgLog.info(className + " communication server started and bound to " + socketAddress);
    } catch (Exception ex) {
        msgLog.error("Failed to bind server to " + socketAddress, ex);
        bootstrap.releaseExternalResources();
        targetCallExecutor.shutdownNow();
        unfinishedTransactionExecutor.shutdownNow();
        silentChannelExecutor.shutdownNow();
        throw new IOException(ex);
    }
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) Channel(org.jboss.netty.channel.Channel) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) IOException(java.io.IOException) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException)

Example 4 with NioServerSocketChannelFactory

use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project graylog2-server by Graylog2.

the class AbstractTcpTransport method getBootstrap.

@Override
protected Bootstrap getBootstrap() {
    final ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(bossExecutor, workerExecutor));
    bootstrap.setOption("receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(8192));
    bootstrap.setOption("receiveBufferSize", getRecvBufferSize());
    bootstrap.setOption("child.receiveBufferSize", getRecvBufferSize());
    bootstrap.setOption("child.keepAlive", tcpKeepalive);
    return bootstrap;
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) FixedReceiveBufferSizePredictorFactory(org.jboss.netty.channel.FixedReceiveBufferSizePredictorFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Example 5 with NioServerSocketChannelFactory

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

the class RtspServer method run.

@Override
public void run() {
    System.out.println("Listening on Port " + port);
    ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
    bootstrap.setPipelineFactory(new RtspServerPipelineFactory());
    bootstrap.bind(new InetSocketAddress(port));
    while (!Thread.interrupted()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        // ignore
        }
    }
    System.out.println("RTSP-Server shutdown");
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) 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