Search in sources :

Example 1 with NioEventLoopGroup

use of io.netty.channel.nio.NioEventLoopGroup in project camel by apache.

the class LumberjackServer method start.

/**
     * Starts the server.
     *
     * @throws InterruptedException when interrupting while connecting the socket
     */
public void start() throws InterruptedException {
    LOG.info("Starting the LUMBERJACK server (host={}, port={}).", host, port);
    // Create the group that will listen for incoming connections
    bossGroup = new NioEventLoopGroup(1);
    // Create the group that will process the connections
    workerGroup = new NioEventLoopGroup(WORKER_THREADS);
    // Create the executor service that will process the payloads without blocking netty threads
    executorService = new DefaultEventExecutorGroup(WORKER_THREADS, threadFactory);
    // Create the channel initializer
    ChannelHandler initializer = new LumberjackChannelInitializer(sslContext, executorService, messageProcessor);
    // Bootstrap the netty server
    ServerBootstrap serverBootstrap = //
    new ServerBootstrap().group(bossGroup, //
    workerGroup).channel(//
    NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, //
    100).childHandler(//
    initializer);
    // Connect the socket
    channel = serverBootstrap.bind(host, port).sync().channel();
    LOG.info("LUMBERJACK server is started (host={}, port={}).", host, port);
}
Also used : DefaultEventExecutorGroup(io.netty.util.concurrent.DefaultEventExecutorGroup) ChannelHandler(io.netty.channel.ChannelHandler) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 2 with NioEventLoopGroup

use of io.netty.channel.nio.NioEventLoopGroup in project hbase by apache.

the class TestSaslFanOutOneBlockAsyncDFSOutput method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    EVENT_LOOP_GROUP = new NioEventLoopGroup();
    TEST_UTIL.getConfiguration().setInt(DFS_CLIENT_SOCKET_TIMEOUT_KEY, READ_TIMEOUT_MS);
    KDC = TEST_UTIL.setupMiniKdc(KEYTAB_FILE);
    USERNAME = UserGroupInformation.getLoginUser().getShortUserName();
    PRINCIPAL = USERNAME + "/" + HOST;
    HTTP_PRINCIPAL = "HTTP/" + HOST;
    KDC.createPrincipal(KEYTAB_FILE, PRINCIPAL, HTTP_PRINCIPAL);
    setUpKeyProvider(TEST_UTIL.getConfiguration());
    setHdfsSecuredConfiguration(TEST_UTIL.getConfiguration());
    HBaseKerberosUtils.setPrincipalForTesting(PRINCIPAL + "@" + KDC.getRealm());
    HBaseKerberosUtils.setSecuredConfiguration(TEST_UTIL.getConfiguration());
    UserGroupInformation.setConfiguration(TEST_UTIL.getConfiguration());
}
Also used : NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) BeforeClass(org.junit.BeforeClass)

Example 3 with NioEventLoopGroup

use of io.netty.channel.nio.NioEventLoopGroup in project moco by dreamhead.

the class MocoClient method run.

public void run(final String host, final int port, final ChannelHandler pipelineFactory) {
    EventLoopGroup group = new NioEventLoopGroup();
    Bootstrap bootstrap = new Bootstrap();
    bootstrap.group(group).channel(NioSocketChannel.class).remoteAddress(host, port).option(ChannelOption.TCP_NODELAY, true).handler(pipelineFactory);
    try {
        Channel channel = bootstrap.connect().sync().channel();
        ChannelFuture future = channel.closeFuture().sync();
        future.addListener(ChannelFutureListener.CLOSE);
    } catch (InterruptedException e) {
        throw new MocoException(e);
    } finally {
        group.shutdownGracefully();
    }
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) ChannelFuture(io.netty.channel.ChannelFuture) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Channel(io.netty.channel.Channel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) Bootstrap(io.netty.bootstrap.Bootstrap) MocoException(com.github.dreamhead.moco.MocoException) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 4 with NioEventLoopGroup

use of io.netty.channel.nio.NioEventLoopGroup in project elasticsearch by elastic.

the class Netty4HttpServerTransport method doStart.

@Override
protected void doStart() {
    boolean success = false;
    try {
        this.serverOpenChannels = new Netty4OpenChannelsHandler(logger);
        serverBootstrap = new ServerBootstrap();
        serverBootstrap.group(new NioEventLoopGroup(workerCount, daemonThreadFactory(settings, HTTP_SERVER_WORKER_THREAD_NAME_PREFIX)));
        serverBootstrap.channel(NioServerSocketChannel.class);
        serverBootstrap.childHandler(configureServerChannelHandler());
        serverBootstrap.childOption(ChannelOption.TCP_NODELAY, SETTING_HTTP_TCP_NO_DELAY.get(settings));
        serverBootstrap.childOption(ChannelOption.SO_KEEPALIVE, SETTING_HTTP_TCP_KEEP_ALIVE.get(settings));
        final ByteSizeValue tcpSendBufferSize = SETTING_HTTP_TCP_SEND_BUFFER_SIZE.get(settings);
        if (tcpSendBufferSize.getBytes() > 0) {
            serverBootstrap.childOption(ChannelOption.SO_SNDBUF, Math.toIntExact(tcpSendBufferSize.getBytes()));
        }
        final ByteSizeValue tcpReceiveBufferSize = SETTING_HTTP_TCP_RECEIVE_BUFFER_SIZE.get(settings);
        if (tcpReceiveBufferSize.getBytes() > 0) {
            serverBootstrap.childOption(ChannelOption.SO_RCVBUF, Math.toIntExact(tcpReceiveBufferSize.getBytes()));
        }
        serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, recvByteBufAllocator);
        serverBootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, recvByteBufAllocator);
        final boolean reuseAddress = SETTING_HTTP_TCP_REUSE_ADDRESS.get(settings);
        serverBootstrap.option(ChannelOption.SO_REUSEADDR, reuseAddress);
        serverBootstrap.childOption(ChannelOption.SO_REUSEADDR, reuseAddress);
        this.boundAddress = createBoundHttpAddress();
        if (logger.isInfoEnabled()) {
            logger.info("{}", boundAddress);
        }
        success = true;
    } finally {
        if (success == false) {
            // otherwise we leak threads since we never moved to started
            doStop();
        }
    }
}
Also used : ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) Netty4OpenChannelsHandler(org.elasticsearch.transport.netty4.Netty4OpenChannelsHandler) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 5 with NioEventLoopGroup

use of io.netty.channel.nio.NioEventLoopGroup in project jersey by jersey.

the class NettyHttpContainerProvider method createServer.

/**
     * Create and start Netty server.
     *
     * @param baseUri       base uri.
     * @param configuration Jersey configuration.
     * @param sslContext    Netty SSL context (can be null).
     * @param block         when {@code true}, this method will block until the server is stopped. When {@code false}, the
     *                      execution will
     *                      end immediately after the server is started.
     * @return Netty channel instance.
     * @throws ProcessingException when there is an issue with creating new container.
     */
public static Channel createServer(final URI baseUri, final ResourceConfig configuration, SslContext sslContext, final boolean block) throws ProcessingException {
    // Configure the server.
    final EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    final EventLoopGroup workerGroup = new NioEventLoopGroup();
    final NettyHttpContainer container = new NettyHttpContainer(configuration);
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new JerseyServerInitializer(baseUri, sslContext, container));
        int port = getPort(baseUri);
        Channel ch = b.bind(port).sync().channel();
        ch.closeFuture().addListener(new GenericFutureListener<Future<? super Void>>() {

            @Override
            public void operationComplete(Future<? super Void> future) throws Exception {
                container.getApplicationHandler().onShutdown(container);
                bossGroup.shutdownGracefully();
                workerGroup.shutdownGracefully();
            }
        });
        if (block) {
            ch.closeFuture().sync();
            return ch;
        } else {
            return ch;
        }
    } catch (InterruptedException e) {
        throw new ProcessingException(e);
    }
}
Also used : NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) Channel(io.netty.channel.Channel) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ProcessingException(javax.ws.rs.ProcessingException) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Future(io.netty.util.concurrent.Future) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ProcessingException(javax.ws.rs.ProcessingException)

Aggregations

NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)181 EventLoopGroup (io.netty.channel.EventLoopGroup)89 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)71 Bootstrap (io.netty.bootstrap.Bootstrap)65 Channel (io.netty.channel.Channel)51 ChannelFuture (io.netty.channel.ChannelFuture)50 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)48 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)46 SocketChannel (io.netty.channel.socket.SocketChannel)39 SslContext (io.netty.handler.ssl.SslContext)37 InetSocketAddress (java.net.InetSocketAddress)35 LoggingHandler (io.netty.handler.logging.LoggingHandler)33 ChannelPipeline (io.netty.channel.ChannelPipeline)30 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)26 Test (org.testng.annotations.Test)23 ByteBuf (io.netty.buffer.ByteBuf)18 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)18 NettyClientMetrics (com.linkedin.pinot.transport.metrics.NettyClientMetrics)16 HashedWheelTimer (io.netty.util.HashedWheelTimer)16 ChannelInitializer (io.netty.channel.ChannelInitializer)15