Search in sources :

Example 6 with NioServerSocketChannelFactory

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

the class FlashPolicyServer method start.

public static void start() {
    // Configure the server.
    bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
    // Set up the event pipeline factory.
    bootstrap.setPipelineFactory(new FlashPolicyServerPipelineFactory());
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.keepAlive", true);
    // Bind and start to accept incoming connections.
    serverChannel = bootstrap.bind(new InetSocketAddress(843));
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Example 7 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 8 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 9 with NioServerSocketChannelFactory

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

the class JmxShutdownThread method initializeContainerNetworking.

protected void initializeContainerNetworking(ByteOrder byteOrder) throws IOException, DatabusException {
    //instruct netty not to rename our threads in the I/O and boss thread pools
    ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
    _httpBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(_bossExecutorService, _ioExecutorService));
    _httpBootstrap.setPipelineFactory(new HttpServerPipelineFactory(this));
    _httpBootstrap.setOption("bufferFactory", DirectChannelBufferFactory.getInstance(byteOrder));
    _httpBootstrap.setOption("child.bufferFactory", DirectChannelBufferFactory.getInstance(byteOrder));
    if (_containerStaticConfig.getTcp().isEnabled()) {
        _tcpBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(_bossExecutorService, _ioExecutorService));
        _tcpBootstrap.setPipelineFactory(new TcpServerPipelineFactory(this, byteOrder));
        _tcpBootstrap.setOption("bufferFactory", DirectChannelBufferFactory.getInstance(byteOrder));
        _tcpBootstrap.setOption("child.bufferFactory", DirectChannelBufferFactory.getInstance(byteOrder));
    //LOG.debug("endianness:" + ((ChannelBufferFactory)_tcpBootstrap.getOption("bufferFactory")).getDefaultOrder());
    }
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Example 10 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)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