use of org.jboss.netty.channel.group.DefaultChannelGroup 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.channel.group.DefaultChannelGroup in project neo4j by neo4j.
the class NetworkSender method start.
@Override
public void start() throws Throwable {
channels = new DefaultChannelGroup();
// Start client bootstrap
clientBootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newSingleThreadExecutor(daemon("Cluster client boss", monitor)), Executors.newFixedThreadPool(2, daemon("Cluster client worker", monitor)), 2));
clientBootstrap.setOption("tcpNoDelay", true);
clientBootstrap.setPipelineFactory(new NetworkNodePipelineFactory());
msgLog.debug("Started NetworkSender for " + toString(config));
}
use of org.jboss.netty.channel.group.DefaultChannelGroup 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.channel.group.DefaultChannelGroup in project UniversalMediaServer by UniversalMediaServer.
the class HTTPServer method start.
public boolean start() throws IOException {
hostname = configuration.getServerHostname();
InetSocketAddress address;
if (StringUtils.isNotBlank(hostname)) {
LOGGER.info("Using forced address " + hostname);
InetAddress tempIA = InetAddress.getByName(hostname);
if (tempIA != null && networkInterface != null && networkInterface.equals(NetworkInterface.getByInetAddress(tempIA))) {
address = new InetSocketAddress(tempIA, port);
} else {
address = new InetSocketAddress(hostname, port);
}
} else if (isAddressFromInterfaceFound(configuration.getNetworkInterface())) {
// XXX sets iafinal and networkInterface
LOGGER.info("Using address {} found on network interface: {}", iafinal, networkInterface.toString().trim().replace('\n', ' '));
address = new InetSocketAddress(iafinal, port);
} else {
LOGGER.info("Using localhost address");
address = new InetSocketAddress(port);
}
LOGGER.info("Created socket: {}", address);
if (configuration.isHTTPEngineV2()) {
// HTTP Engine V2
ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
group = new DefaultChannelGroup("HTTPServer");
factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(new NettyBossThreadFactory()), Executors.newCachedThreadPool(new NettyWorkerThreadFactory()));
ServerBootstrap bootstrap = new ServerBootstrap(factory);
HttpServerPipelineFactory pipeline = new HttpServerPipelineFactory(group);
bootstrap.setPipelineFactory(pipeline);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("reuseAddress", true);
bootstrap.setOption("child.reuseAddress", true);
bootstrap.setOption("child.sendBufferSize", 65536);
bootstrap.setOption("child.receiveBufferSize", 65536);
try {
channel = bootstrap.bind(address);
group.add(channel);
} catch (Exception e) {
LOGGER.error("Another program is using port " + port + ", which UMS needs.");
LOGGER.error("You can change the port UMS uses on the General Configuration tab.");
LOGGER.trace("The error was: " + e);
PMS.get().getFrame().setStatusCode(0, Messages.getString("PMS.141"), "icon-status-warning.png");
}
if (hostname == null && iafinal != null) {
hostname = iafinal.getHostAddress();
} else if (hostname == null) {
hostname = InetAddress.getLocalHost().getHostAddress();
}
} else {
// HTTP Engine V1
serverSocketChannel = ServerSocketChannel.open();
serverSocket = serverSocketChannel.socket();
serverSocket.setReuseAddress(true);
serverSocket.bind(address);
if (hostname == null && iafinal != null) {
hostname = iafinal.getHostAddress();
} else if (hostname == null) {
hostname = InetAddress.getLocalHost().getHostAddress();
}
runnable = new Thread(this, "HTTPv1 Request Handler");
runnable.setDaemon(false);
runnable.start();
}
return true;
}
use of org.jboss.netty.channel.group.DefaultChannelGroup in project pinpoint by naver.
the class HealthCheckManagerTest method pingPacketTest.
@Test
public void pingPacketTest() throws Exception {
ChannelGroup channelGroup = new DefaultChannelGroup();
HealthCheckManager healthCheckManager = new HealthCheckManager(timer, 3000, channelGroup);
healthCheckManager.start(1000);
Channel mockChannel = createMockChannel(HealthCheckState.RECEIVED);
channelGroup.add(mockChannel);
try {
verify(mockChannel, timeout(3000).atLeastOnce()).write(PingSimplePacket.PING_PACKET);
} finally {
healthCheckManager.stop();
}
}
Aggregations