Search in sources :

Example 1 with DefaultChannelGroup

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);
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Example 2 with DefaultChannelGroup

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));
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap)

Example 3 with DefaultChannelGroup

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);
    }
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) Channel(org.jboss.netty.channel.Channel) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) IOException(java.io.IOException) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException)

Example 4 with DefaultChannelGroup

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;
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) IOException(java.io.IOException) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException)

Example 5 with DefaultChannelGroup

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

Aggregations

DefaultChannelGroup (org.jboss.netty.channel.group.DefaultChannelGroup)11 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)6 Channel (org.jboss.netty.channel.Channel)5 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)5 InetSocketAddress (java.net.InetSocketAddress)4 ChannelGroup (org.jboss.netty.channel.group.ChannelGroup)4 IOException (java.io.IOException)3 Test (org.junit.Test)3 SocketAddress (java.net.SocketAddress)2 Executor (java.util.concurrent.Executor)2 SSLEngine (javax.net.ssl.SSLEngine)2 SslHandler (org.jboss.netty.handler.ssl.SslHandler)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)1 ExecutorService (java.util.concurrent.ExecutorService)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1 ClientBootstrap (org.jboss.netty.bootstrap.ClientBootstrap)1