Search in sources :

Example 16 with DefaultChannelGroup

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();
    }
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) InetSocketAddress(java.net.InetSocketAddress) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File)

Example 17 with DefaultChannelGroup

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();
    }
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) Channel(org.jboss.netty.channel.Channel) DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) ChannelGroup(org.jboss.netty.channel.group.ChannelGroup) Test(org.junit.Test)

Example 18 with DefaultChannelGroup

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();
    }
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) Channel(org.jboss.netty.channel.Channel) DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) ChannelGroup(org.jboss.netty.channel.group.ChannelGroup) Test(org.junit.Test)

Example 19 with DefaultChannelGroup

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();
    }
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) Channel(org.jboss.netty.channel.Channel) DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) ChannelGroup(org.jboss.netty.channel.group.ChannelGroup) Test(org.junit.Test)

Example 20 with DefaultChannelGroup

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);
                }
            }
        });
    }
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) InetSocketAddress(java.net.InetSocketAddress) CountDownLatch(java.util.concurrent.CountDownLatch) Point(java.awt.Point) DataStoreException(org.apache.sis.storage.DataStoreException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) ChannelGroup(org.jboss.netty.channel.group.ChannelGroup)

Aggregations

DefaultChannelGroup (org.jboss.netty.channel.group.DefaultChannelGroup)21 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)11 Channel (org.jboss.netty.channel.Channel)10 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)9 ChannelGroup (org.jboss.netty.channel.group.ChannelGroup)8 InetSocketAddress (java.net.InetSocketAddress)7 IOException (java.io.IOException)6 Test (org.junit.Test)6 ClientBootstrap (org.jboss.netty.bootstrap.ClientBootstrap)3 SocketAddress (java.net.SocketAddress)2 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)2 Executor (java.util.concurrent.Executor)2 ExecutorService (java.util.concurrent.ExecutorService)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 SSLEngine (javax.net.ssl.SSLEngine)2 NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)2 SslHandler (org.jboss.netty.handler.ssl.SslHandler)2 Point (java.awt.Point)1 File (java.io.File)1