use of org.jboss.netty.channel.group.DefaultChannelGroup in project http-client by biasedbit.
the class UploadMirrorHttpServer method init.
// interface ------------------------------------------------------------------------------------------------------
public boolean init() {
Executor bossExecutor = Executors.newCachedThreadPool();
Executor workerExecutor = Executors.newCachedThreadPool();
ChannelFactory factory = new NioServerSocketChannelFactory(bossExecutor, workerExecutor);
bootstrap = new ServerBootstrap(factory);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
if (useSsl) {
SSLEngine engine = BogusSslContextFactory.getInstance().getServerContext().createSSLEngine();
engine.setUseClientMode(false);
pipeline.addLast("ssl", new SslHandler(engine));
}
pipeline.addLast("codec", new HttpServerCodec());
pipeline.addLast("handler", new RequestHandler());
return pipeline;
}
});
channelGroup = new DefaultChannelGroup("hotpotato-upload-server-" + Integer.toHexString(hashCode()));
SocketAddress bindAddress = (host != null) ? new InetSocketAddress(host, port) : new InetSocketAddress(port);
Channel serverChannel = bootstrap.bind(bindAddress);
channelGroup.add(serverChannel);
return (running = serverChannel.isBound());
}
use of org.jboss.netty.channel.group.DefaultChannelGroup in project databus by linkedin.
the class JmxShutdownThread method doStart.
protected void doStart() {
_controlLock.lock();
try {
// Bind and start to accept incoming connections.
int portNum = getContainerStaticConfig().getHttpPort();
_tcpChannelGroup = new DefaultChannelGroup();
_httpChannelGroup = new DefaultChannelGroup();
_httpServerChannel = _httpBootstrap.bind(new InetSocketAddress(portNum));
InetSocketAddress actualAddress = (InetSocketAddress) _httpServerChannel.getLocalAddress();
_containerPort = actualAddress.getPort();
// persist the port number (file name should be unique for the container)
File portNumFile = new File(getHttpPortFileName());
portNumFile.deleteOnExit();
try {
FileWriter portNumFileW = new FileWriter(portNumFile);
portNumFileW.write(Integer.toString(_containerPort));
portNumFileW.close();
LOG.info("Saving port number in " + portNumFile.getAbsolutePath());
} catch (IOException e) {
throw new RuntimeException(e);
}
_httpChannelGroup.add(_httpServerChannel);
LOG.info("Serving container " + getContainerStaticConfig().getId() + " HTTP listener on port " + _containerPort);
if (_containerStaticConfig.getTcp().isEnabled()) {
int tcpPortNum = _containerStaticConfig.getTcp().getPort();
_tcpServerChannel = _tcpBootstrap.bind(new InetSocketAddress(tcpPortNum));
_tcpChannelGroup.add(_tcpServerChannel);
LOG.info("Serving container " + getContainerStaticConfig().getId() + " TCP listener on port " + tcpPortNum);
}
_nettyShutdownThread = new NettyShutdownThread();
Runtime.getRuntime().addShutdownHook(_nettyShutdownThread);
// Start the producer thread after 5 seconds
if (null != _jmxConnServer && _containerStaticConfig.getJmx().isRmiEnabled()) {
try {
_jmxShutdownThread = new JmxShutdownThread(_jmxConnServer);
Runtime.getRuntime().addShutdownHook(_jmxShutdownThread);
_jmxConnServer.start();
LOG.info("JMX server listening on port " + _containerStaticConfig.getJmx().getJmxServicePort());
} catch (IOException ioe) {
if (ioe.getCause() != null && ioe.getCause() instanceof NameAlreadyBoundException) {
LOG.warn("Unable to bind JMX server connector. Likely cause is that the previous instance was not cleanly shutdown: killed in Eclipse?");
if (_jmxConnServer.isActive()) {
LOG.warn("JMX server connector seems to be running anyway. ");
} else {
LOG.warn("Unable to determine if JMX server connector is running");
}
} else {
LOG.error("Unable to start JMX server connector", ioe);
}
}
}
_globalStatsThread.start();
} catch (RuntimeException ex) {
LOG.error("Got runtime exception :" + ex, ex);
throw ex;
} finally {
_controlLock.unlock();
}
}
Aggregations