Search in sources :

Example 36 with EpollEventLoopGroup

use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup in project bgpcep by opendaylight.

the class BmpMonitorImplTest method connectTestClient.

private static Channel connectTestClient(final String routerIp, final BmpMessageRegistry msgRegistry) throws InterruptedException {
    final BmpHandlerFactory hf = new BmpHandlerFactory(msgRegistry);
    final Bootstrap b = new Bootstrap();
    final EventLoopGroup workerGroup;
    if (Epoll.isAvailable()) {
        b.channel(EpollSocketChannel.class);
        workerGroup = new EpollEventLoopGroup();
    } else {
        b.channel(NioSocketChannel.class);
        workerGroup = new NioEventLoopGroup();
    }
    b.group(workerGroup);
    b.option(ChannelOption.SO_KEEPALIVE, true);
    b.handler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(final SocketChannel ch) throws Exception {
            ch.pipeline().addLast(hf.getDecoders());
            ch.pipeline().addLast(hf.getEncoders());
        }
    });
    b.localAddress(new InetSocketAddress(routerIp, 0));
    b.option(ChannelOption.SO_REUSEADDR, true);
    final ChannelFuture future = b.connect(new InetSocketAddress(MONITOR_LOCAL_ADDRESS, MONITOR_LOCAL_PORT)).sync();
    waitFutureSuccess(future);
    return future.channel();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) SocketChannel(io.netty.channel.socket.SocketChannel) EpollSocketChannel(io.netty.channel.epoll.EpollSocketChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EventLoopGroup(io.netty.channel.EventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) InetSocketAddress(java.net.InetSocketAddress) Bootstrap(io.netty.bootstrap.Bootstrap) BmpHandlerFactory(org.opendaylight.protocol.bmp.impl.BmpHandlerFactory) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)

Example 37 with EpollEventLoopGroup

use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup in project bookkeeper by apache.

the class BookKeeper method getDefaultEventLoopGroup.

static EventLoopGroup getDefaultEventLoopGroup() {
    ThreadFactory threadFactory = new DefaultThreadFactory("bookkeeper-io");
    final int numThreads = Runtime.getRuntime().availableProcessors() * 2;
    if (SystemUtils.IS_OS_LINUX) {
        try {
            return new EpollEventLoopGroup(numThreads, threadFactory);
        } catch (Throwable t) {
            LOG.warn("Could not use Netty Epoll event loop for bookie server: {}", t.getMessage());
            return new NioEventLoopGroup(numThreads, threadFactory);
        }
    } else {
        return new NioEventLoopGroup(numThreads, threadFactory);
    }
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 38 with EpollEventLoopGroup

use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup in project duangframework by tcrct.

the class EventLoopGroupFactory method builderBossLoopGroup.

public static EventLoopGroup builderBossLoopGroup() {
    Executor executor = builderThreadPoolExecutor(ServerConfig.MAX_BOSS_EXECUTORS_NUMBER, ServerConfig.MAX_BOSS_EXECUTORS_NUMBER, ServerConfig.KEEP_ALIVETIME, TimeUnit.HOURS, new ArrayBlockingQueue<Runnable>(ServerConfig.MAX_BOSS_EXECUTORS_NUMBER), new NamedThreadFactory(ServerConfig.BOSSGROUP_POOLTHREAD_NAME));
    if (NativeSupport.isSupportNative()) {
        EpollEventLoopGroup bossLoopGroup = new EpollEventLoopGroup(ServerConfig.MAX_BOSS_EXECUTORS_NUMBER, executor);
        bossLoopGroup.setIoRatio(ServerConfig.IO_RATIO_NUMBER);
        return bossLoopGroup;
    } else {
        NioEventLoopGroup bossLoopGroup = new NioEventLoopGroup(ServerConfig.MAX_BOSS_EXECUTORS_NUMBER, executor);
        bossLoopGroup.setIoRatio(ServerConfig.IO_RATIO_NUMBER);
        return bossLoopGroup;
    }
}
Also used : NamedThreadFactory(com.duangframework.server.utils.NamedThreadFactory) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 39 with EpollEventLoopGroup

use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup in project duangframework by tcrct.

the class EventLoopGroupFactory method builderWorkerLoopGroup.

public static EventLoopGroup builderWorkerLoopGroup() {
    int workerNum = Runtime.getRuntime().availableProcessors() << 1;
    Executor executor = builderThreadPoolExecutor(workerNum, workerNum, ServerConfig.KEEP_ALIVETIME, TimeUnit.HOURS, new ArrayBlockingQueue<Runnable>(workerNum), new NamedThreadFactory(ServerConfig.WORKERGROUP_POOLTHREAD_NAME));
    if (NativeSupport.isSupportNative()) {
        EpollEventLoopGroup workerLoopGroup = new EpollEventLoopGroup(workerNum, executor);
        workerLoopGroup.setIoRatio(ServerConfig.IO_RATIO_NUMBER);
        return workerLoopGroup;
    } else {
        NioEventLoopGroup workerLoopGroup = new NioEventLoopGroup(workerNum, executor);
        workerLoopGroup.setIoRatio(ServerConfig.IO_RATIO_NUMBER);
        return workerLoopGroup;
    }
}
Also used : NamedThreadFactory(com.duangframework.server.utils.NamedThreadFactory) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 40 with EpollEventLoopGroup

use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup in project turbo-rpc by hank-whu.

the class NettyClientConnector method connect.

void connect() throws InterruptedException {
    Bootstrap bootstrap = new Bootstrap();
    bootstrap.group(eventLoopGroup);
    // bootstrap.option(ChannelOption.TCP_NODELAY, true);
    bootstrap.option(ChannelOption.SO_REUSEADDR, true);
    bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
    if (eventLoopGroup instanceof EpollEventLoopGroup) {
        bootstrap.option(EpollChannelOption.SO_REUSEPORT, true);
        bootstrap.channel(EpollSocketChannel.class);
    } else if (eventLoopGroup instanceof NioEventLoopGroup) {
        bootstrap.channel(NioSocketChannel.class);
    }
    bootstrap.handler(new TurboChannelInitializer(serializer));
    Channel[] newChannels = new Channel[connectCount];
    for (int i = 0; i < connectCount; i++) {
        newChannels[i] = bootstrap.connect(serverAddress.host, serverAddress.port).sync().channel();
        if (logger.isInfoEnabled()) {
            logger.info(serverAddress + " connect " + i + "/" + connectCount);
        }
    }
    InetSocketAddress insocket = (InetSocketAddress) newChannels[0].localAddress();
    clientAddress = new HostPort(insocket.getAddress().getHostAddress(), 0);
    Channel[] old = channels;
    channels = newChannels;
    if (old != null) {
        for (int i = 0; i < old.length; i++) {
            try {
                old[i].close();
            } catch (Exception e) {
                if (logger.isWarnEnabled()) {
                    logger.warn("关闭出错", e);
                }
            }
        }
    }
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) InetSocketAddress(java.net.InetSocketAddress) TurboChannelInitializer(rpc.turbo.transport.client.handler.TurboChannelInitializer) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) Channel(io.netty.channel.Channel) EpollSocketChannel(io.netty.channel.epoll.EpollSocketChannel) HostPort(rpc.turbo.config.HostPort) Bootstrap(io.netty.bootstrap.Bootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) IOException(java.io.IOException)

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