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();
}
}
use of org.jboss.netty.channel.group.DefaultChannelGroup in project pinpoint by pinpoint-apm.
the class HealthCheckManagerTest method legacyPingPacketTest.
@Test
public void legacyPingPacketTest() throws Exception {
ChannelGroup channelGroup = new DefaultChannelGroup();
HealthCheckManager healthCheckManager = new HealthCheckManager(timer, 3000, channelGroup);
healthCheckManager.start(1000);
Channel mockChannel = createMockChannel(HealthCheckState.RECEIVED_LEGACY);
channelGroup.add(mockChannel);
try {
verify(mockChannel, timeout(3000).atLeastOnce()).write(PingPacket.PING_PACKET);
} finally {
healthCheckManager.stop();
}
}
use of org.jboss.netty.channel.group.DefaultChannelGroup in project pinpoint by pinpoint-apm.
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();
}
}
use of org.jboss.netty.channel.group.DefaultChannelGroup in project pinpoint by pinpoint-apm.
the class HealthCheckManagerTest method withoutPacketTest.
@Test
public void withoutPacketTest() throws Exception {
ChannelGroup channelGroup = new DefaultChannelGroup();
HealthCheckManager healthCheckManager = new HealthCheckManager(timer, 3000, channelGroup);
healthCheckManager.start(1000);
Channel mockChannel = createMockChannel(HealthCheckState.WAIT);
channelGroup.add(mockChannel);
try {
verify(mockChannel, timeout(5000).atLeastOnce()).close();
} finally {
healthCheckManager.stop();
}
}
use of org.jboss.netty.channel.group.DefaultChannelGroup in project geotoolkit by Geomatys.
the class CachedTileMatrixSets method queryUsingNIO.
/**
* Use Netty NIO to download tiles.
*/
private void queryUsingNIO(final URL url, final CancellableQueue queue, final List<ImagePack> downloadList) {
final String host = url.getHost();
final int port = (url.getPort() == -1) ? url.getDefaultPort() : url.getPort();
final ChannelGroup group = new DefaultChannelGroup("group");
final CountDownLatch latch = new CountDownLatch(downloadList.size()) {
@Override
public void countDown() {
super.countDown();
if (getCount() <= 0) {
try {
// put a custom object, this is used in the iterator
// to detect the end.
queue.put(TileMatrix.END_OF_QUEUE);
} catch (InterruptedException ex) {
LOGGER.log(Level.WARNING, ex.getMessage(), ex);
}
}
}
};
final Map<Integer, ImagePack> PACK_MAP = new ConcurrentHashMap<Integer, ImagePack>();
// Set up the event pipeline factory.
final ClientBootstrap boot = getBootstrap();
boot.setPipelineFactory(new TilePipelineFactory(queue, latch, PACK_MAP));
for (final ImagePack pack : downloadList) {
final ChannelFuture future = boot.connect(new InetSocketAddress(host, port));
future.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture cf) throws Exception {
final Channel channel = future.getChannel();
group.add(channel);
PACK_MAP.put(channel.getId(), pack);
final HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, pack.requestPath);
request.setHeader(HttpHeaders.Names.HOST, host);
request.setHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
request.setHeader(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.BYTES);
if (channel.isOpen() && channel.isWritable() && !queue.isCancelled()) {
channel.write(request);
}
}
});
}
}
Aggregations