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();
}
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);
}
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);
}
}
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
}
}
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());
}
Aggregations