Search in sources :

Example 11 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project hadoop by apache.

the class ShuffleHandler method serviceStop.

@Override
protected void serviceStop() throws Exception {
    accepted.close().awaitUninterruptibly(10, TimeUnit.SECONDS);
    if (selector != null) {
        ServerBootstrap bootstrap = new ServerBootstrap(selector);
        bootstrap.releaseExternalResources();
    }
    if (pipelineFact != null) {
        pipelineFact.destroy();
    }
    if (stateDb != null) {
        stateDb.close();
    }
    super.serviceStop();
}
Also used : ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Example 12 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap 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 13 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap 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 14 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project neo4j by neo4j.

the class PortRangeSocketBinderTest method shouldReThrowExceptionIfCannotBindToPort.

@Test
public void shouldReThrowExceptionIfCannotBindToPort() {
    // given
    HostnamePort localhost = new HostnamePort("localhost", 9000);
    ServerBootstrap bootstrap = mock(ServerBootstrap.class);
    when(bootstrap.bind(new InetSocketAddress("localhost", 9000))).thenThrow(new ChannelException());
    try {
        // when
        new PortRangeSocketBinder(bootstrap).bindToFirstAvailablePortInRange(localhost);
        fail("should have thrown ChannelException");
    } catch (ChannelException ignored) {
    // expected
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) HostnamePort(org.neo4j.helpers.HostnamePort) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelException(org.jboss.netty.channel.ChannelException) Test(org.junit.Test)

Example 15 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project neo4j by neo4j.

the class PortRangeSocketBinderTest method shouldReturnChannelAndSocketIfPortIsFree.

@Test
public void shouldReturnChannelAndSocketIfPortIsFree() {
    // given
    HostnamePort localhost = new HostnamePort("localhost", 9000);
    ServerBootstrap bootstrap = mock(ServerBootstrap.class);
    Channel channel = mock(Channel.class);
    when(bootstrap.bind(new InetSocketAddress("localhost", 9000))).thenReturn(channel);
    // when
    Connection connection = new PortRangeSocketBinder(bootstrap).bindToFirstAvailablePortInRange(localhost);
    //then
    assertEquals(channel, connection.getChannel());
    assertEquals(new InetSocketAddress("localhost", 9000), connection.getSocketAddress());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) HostnamePort(org.neo4j.helpers.HostnamePort) Channel(org.jboss.netty.channel.Channel) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) Test(org.junit.Test)

Aggregations

ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)94 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)58 TrackerServer (org.traccar.TrackerServer)42 InetSocketAddress (java.net.InetSocketAddress)38 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)34 ConnectionlessBootstrap (org.jboss.netty.bootstrap.ConnectionlessBootstrap)25 StringEncoder (org.jboss.netty.handler.codec.string.StringEncoder)16 Channel (org.jboss.netty.channel.Channel)13 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)12 StringDecoder (org.jboss.netty.handler.codec.string.StringDecoder)12 LengthFieldBasedFrameDecoder (org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder)11 ChannelFactory (org.jboss.netty.channel.ChannelFactory)8 ExecutorService (java.util.concurrent.ExecutorService)5 DefaultChannelGroup (org.jboss.netty.channel.group.DefaultChannelGroup)5 Test (org.junit.Test)5 HostnamePort (org.neo4j.helpers.HostnamePort)5 CharacterDelimiterFrameDecoder (org.traccar.CharacterDelimiterFrameDecoder)5 IOException (java.io.IOException)4 ChannelException (org.jboss.netty.channel.ChannelException)4 NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)4