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