Search in sources :

Example 41 with EpollEventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.epoll.EpollEventLoopGroup in project turbo-rpc by hank-whu.

the class NettyRestServer method start.

public void start() throws InterruptedException {
    InetSocketAddress inet = new InetSocketAddress(hostPort.host, hostPort.port);
    ServerBootstrap bootstrap = new ServerBootstrap();
    bootstrap.group(eventLoopGroup);
    bootstrap.option(ChannelOption.SO_BACKLOG, 256);
    bootstrap.option(ChannelOption.SO_REUSEADDR, true);
    if (eventLoopGroup instanceof EpollEventLoopGroup) {
        bootstrap.option(EpollChannelOption.SO_REUSEPORT, true);
        bootstrap.channel(EpollServerSocketChannel.class);
    } else if (eventLoopGroup instanceof NioEventLoopGroup) {
        bootstrap.channel(NioServerSocketChannel.class);
    }
    bootstrap.childHandler(new NettyRestChannelInitializer(invokerFactory, jsonMapper, filters));
    bootstrap.childOption(ChannelOption.SO_REUSEADDR, true);
    bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
    channel = bootstrap.bind(inet).sync().channel();
    System.out.println("NettyRestServer started. Listening on: " + hostPort);
}
Also used : NettyRestChannelInitializer(rpc.turbo.transport.server.rest.handler.NettyRestChannelInitializer) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) InetSocketAddress(java.net.InetSocketAddress) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 42 with EpollEventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.epoll.EpollEventLoopGroup in project turbo-rpc by hank-whu.

the class NettyRpcServer method start.

public void start() throws InterruptedException {
    InetSocketAddress inet = new InetSocketAddress(hostPort.host, hostPort.port);
    ServerBootstrap bootstrap = new ServerBootstrap();
    bootstrap.group(eventLoopGroup);
    bootstrap.option(ChannelOption.SO_BACKLOG, 256);
    bootstrap.option(ChannelOption.SO_REUSEADDR, true);
    if (eventLoopGroup instanceof EpollEventLoopGroup) {
        bootstrap.option(EpollChannelOption.SO_REUSEPORT, true);
        bootstrap.channel(EpollServerSocketChannel.class);
    } else if (eventLoopGroup instanceof NioEventLoopGroup) {
        bootstrap.channel(NioServerSocketChannel.class);
    }
    bootstrap.childHandler(new NettyRpcChannelInitializer(invokerFactory, serializer, filters));
    bootstrap.childOption(ChannelOption.SO_REUSEADDR, true);
    bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
    channel = bootstrap.bind(inet).sync().channel();
    System.out.println("TurboRpcServer started. Listening on: " + hostPort);
}
Also used : NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) InetSocketAddress(java.net.InetSocketAddress) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) NettyRpcChannelInitializer(rpc.turbo.transport.server.rpc.handler.NettyRpcChannelInitializer)

Example 43 with EpollEventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.epoll.EpollEventLoopGroup in project java by wavefrontHQ.

the class TcpIngester method run.

public void run() {
    activeListeners.inc();
    ServerBootstrap b = new ServerBootstrap();
    EventLoopGroup parentGroup;
    EventLoopGroup childGroup;
    Class<? extends ServerChannel> socketChannelClass;
    if (Epoll.isAvailable()) {
        logger.fine("Using native socket transport for port " + listeningPort);
        parentGroup = new EpollEventLoopGroup(1);
        childGroup = new EpollEventLoopGroup();
        socketChannelClass = EpollServerSocketChannel.class;
    } else {
        logger.fine("Using NIO socket transport for port " + listeningPort);
        parentGroup = new NioEventLoopGroup(1);
        childGroup = new NioEventLoopGroup();
        socketChannelClass = NioServerSocketChannel.class;
    }
    try {
        b.group(parentGroup, childGroup).channel(socketChannelClass).option(ChannelOption.SO_BACKLOG, 1024).localAddress(listeningPort).childHandler(initializer);
        if (parentChannelOptions != null) {
            for (Map.Entry<ChannelOption<?>, ?> entry : parentChannelOptions.entrySet()) {
                b.option((ChannelOption<Object>) entry.getKey(), entry.getValue());
            }
        }
        if (childChannelOptions != null) {
            for (Map.Entry<ChannelOption<?>, ?> entry : childChannelOptions.entrySet()) {
                b.childOption((ChannelOption<Object>) entry.getKey(), entry.getValue());
            }
        }
        // Start the server.
        ChannelFuture f = b.bind().sync();
        // Wait until the server socket is closed.
        f.channel().closeFuture().sync();
    } catch (final InterruptedException e) {
        logger.log(Level.WARNING, "Interrupted");
        parentGroup.shutdownGracefully();
        childGroup.shutdownGracefully();
        logger.info("Listener on port " + String.valueOf(listeningPort) + " shut down");
    } catch (Exception e) {
        // ChannelFuture throws undeclared checked exceptions, so we need to handle it
        if (e instanceof BindException) {
            logger.severe("Unable to start listener - port " + String.valueOf(listeningPort) + " is already in use!");
        } else {
            logger.log(Level.SEVERE, "TcpIngester exception: ", e);
        }
    } finally {
        activeListeners.dec();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ChannelOption(io.netty.channel.ChannelOption) BindException(java.net.BindException) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) BindException(java.net.BindException) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) Map(java.util.Map) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 44 with EpollEventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.epoll.EpollEventLoopGroup in project java by wavefrontHQ.

the class UdpIngester method run.

@Override
public void run() {
    activeListeners.inc();
    Bootstrap bootstrap = new Bootstrap();
    EventLoopGroup group;
    Class<? extends Channel> datagramChannelClass;
    if (Epoll.isAvailable()) {
        logger.fine("Using native socket transport for port " + listeningPort);
        group = new EpollEventLoopGroup();
        datagramChannelClass = EpollDatagramChannel.class;
    } else {
        logger.fine("Using NIO socket transport for port " + listeningPort);
        group = new NioEventLoopGroup();
        datagramChannelClass = NioDatagramChannel.class;
    }
    try {
        bootstrap.group(group).channel(datagramChannelClass).localAddress(listeningPort).handler(initializer);
        // Start the server.
        bootstrap.bind().sync().channel().closeFuture().sync();
    } catch (final InterruptedException e) {
        logger.log(Level.WARNING, "Interrupted", e);
    } catch (Exception e) {
        // ChannelFuture throws undeclared checked exceptions, so we need to handle it
        if (e instanceof BindException) {
            logger.severe("Unable to start listener - port " + String.valueOf(listeningPort) + " is already in use!");
        } else {
            logger.log(Level.SEVERE, "UdpIngester exception: ", e);
        }
    } finally {
        activeListeners.dec();
        group.shutdownGracefully();
    }
}
Also used : EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) Bootstrap(io.netty.bootstrap.Bootstrap) BindException(java.net.BindException) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) BindException(java.net.BindException)

Example 45 with EpollEventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.epoll.EpollEventLoopGroup in project java by wavefrontHQ.

the class HistogramLineIngester method run.

@Override
public void run() {
    activeListeners.inc();
    ServerBootstrap bootstrap = new ServerBootstrap();
    EventLoopGroup parent;
    EventLoopGroup children;
    Class<? extends ServerChannel> socketChannelClass;
    if (Epoll.isAvailable()) {
        logger.fine("Using native socket transport for port " + port);
        parent = new EpollEventLoopGroup(1);
        children = new EpollEventLoopGroup(handlers.size());
        socketChannelClass = EpollServerSocketChannel.class;
    } else {
        logger.fine("Using NIO socket transport for port " + port);
        parent = new NioEventLoopGroup(1);
        children = new NioEventLoopGroup(handlers.size());
        socketChannelClass = NioServerSocketChannel.class;
    }
    try {
        bootstrap.group(parent, children).channel(socketChannelClass).option(ChannelOption.SO_BACKLOG, MAXIMUM_OUTSTANDING_CONNECTIONS).localAddress(port).childHandler(this);
        ChannelFuture f = bootstrap.bind().sync();
        f.channel().closeFuture().sync();
    } catch (final InterruptedException e) {
        logger.log(Level.WARNING, "Interrupted");
        parent.shutdownGracefully();
        children.shutdownGracefully();
        logger.info("Listener on port " + String.valueOf(port) + " shut down");
    } catch (Exception e) {
        // ChannelFuture throws undeclared checked exceptions, so we need to handle it
        if (e instanceof BindException) {
            logger.severe("Unable to start listener - port " + String.valueOf(port) + " is already in use!");
        } else {
            logger.log(Level.SEVERE, "HistogramLineIngester exception: ", e);
        }
    } finally {
        activeListeners.dec();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) BindException(java.net.BindException) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) BindException(java.net.BindException)

Aggregations

EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)55 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)46 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)20 EventLoopGroup (io.netty.channel.EventLoopGroup)19 EpollServerSocketChannel (io.netty.channel.epoll.EpollServerSocketChannel)14 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)14 SocketChannel (io.netty.channel.socket.SocketChannel)13 ChannelPipeline (io.netty.channel.ChannelPipeline)12 Channel (io.netty.channel.Channel)10 InetSocketAddress (java.net.InetSocketAddress)10 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)9 IOException (java.io.IOException)9 Bootstrap (io.netty.bootstrap.Bootstrap)8 ChannelFuture (io.netty.channel.ChannelFuture)8 EpollSocketChannel (io.netty.channel.epoll.EpollSocketChannel)8 SslContext (io.netty.handler.ssl.SslContext)8 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)7 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)7 LoggingHandler (io.netty.handler.logging.LoggingHandler)6 SslHandler (io.netty.handler.ssl.SslHandler)6