use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup in project aerospike-client-java by aerospike.
the class SuiteAsync method init.
@BeforeClass
public static void init() {
System.out.println("Begin AerospikeClient");
Args args = Args.Instance;
EventPolicy eventPolicy = new EventPolicy();
switch(args.eventLoopType) {
default:
case DIRECT_NIO:
{
eventLoops = new NioEventLoops(eventPolicy, 1);
break;
}
case NETTY_NIO:
{
EventLoopGroup group = new NioEventLoopGroup(1);
eventLoops = new NettyEventLoops(eventPolicy, group, args.eventLoopType);
break;
}
case NETTY_EPOLL:
{
EventLoopGroup group = new EpollEventLoopGroup(1);
eventLoops = new NettyEventLoops(eventPolicy, group, args.eventLoopType);
break;
}
case NETTY_KQUEUE:
{
EventLoopGroup group = new KQueueEventLoopGroup(1);
eventLoops = new NettyEventLoops(eventPolicy, group, args.eventLoopType);
break;
}
case NETTY_IOURING:
{
EventLoopGroup group = new IOUringEventLoopGroup(1);
eventLoops = new NettyEventLoops(eventPolicy, group, args.eventLoopType);
break;
}
}
try {
ClientPolicy policy = new ClientPolicy();
policy.eventLoops = eventLoops;
policy.user = args.user;
policy.password = args.password;
policy.authMode = args.authMode;
policy.tlsPolicy = args.tlsPolicy;
Host[] hosts = Host.parseHosts(args.host, args.port);
eventLoop = eventLoops.get(0);
client = new AerospikeClient(policy, hosts);
try {
args.setServerSpecific(client);
} catch (RuntimeException re) {
client.close();
throw re;
}
} catch (Exception e) {
eventLoops.close();
throw e;
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup in project riposte by Nike-Inc.
the class StreamingAsyncHttpClient method getPoolMap.
protected ChannelPoolMap<InetSocketAddress, SimpleChannelPool> getPoolMap() {
ChannelPoolMap<InetSocketAddress, SimpleChannelPool> result = poolMap;
if (poolMap == null) {
/*
This method gets called for every downstream call, so we don't want to synchronize the whole method. But
it's easy for multiple threads to get here at the same time when the server starts up, so we need *some*
kind of protection around the creation of poolMap, hence the elaborate (but correct) double-checked
locking. Since poolMap is volatile this works, and the local variable "result" helps with speed during
the normal case where poolMap has already been initialized.
See https://en.wikipedia.org/wiki/Double-checked_locking
*/
synchronized (this) {
result = poolMap;
if (result == null) {
EventLoopGroup eventLoopGroup;
Class<? extends SocketChannel> channelClass;
if (Epoll.isAvailable()) {
logger.info("Creating channel pool. The epoll native transport is available. Using epoll instead of " + "NIO. proxy_router_using_native_epoll_transport=true");
eventLoopGroup = new EpollEventLoopGroup(0, createProxyRouterThreadFactory());
channelClass = EpollSocketChannel.class;
} else {
logger.info("Creating channel pool. The epoll native transport is NOT available or you are not running " + "on a compatible OS/architecture. Using NIO. " + "proxy_router_using_native_epoll_transport=false");
eventLoopGroup = new NioEventLoopGroup(0, createProxyRouterThreadFactory());
channelClass = NioSocketChannel.class;
}
result = new AbstractChannelPoolMap<InetSocketAddress, SimpleChannelPool>() {
@Override
protected SimpleChannelPool newPool(InetSocketAddress key) {
return new SimpleChannelPool(generateClientBootstrap(eventLoopGroup, channelClass).remoteAddress(key), new ChannelPoolHandlerImpl(), CHANNEL_HEALTH_CHECK_INSTANCE) {
@Override
public Future<Void> release(Channel channel, Promise<Void> promise) {
markChannelBrokenAndLogInfoIfHttpClientCodecStateIsNotZero(channel, "Releasing channel back to pool");
return super.release(channel, promise);
}
@Override
protected Channel pollChannel() {
Channel channel = super.pollChannel();
if (channel != null) {
markChannelBrokenAndLogInfoIfHttpClientCodecStateIsNotZero(channel, "Polling channel to be reused before healthcheck");
if (idleChannelTimeoutMillis > 0) {
/*
We have a channel that is about to be re-used, so disable the idle channel
timeout detector if it exists. By disabling it here we make sure that it is
effectively "gone" before the healthcheck happens, preventing race
conditions. Note that we can't call pipeline.remove() here because we may
not be in the pipeline's event loop, so calling pipeline.remove() could
lead to thread deadlock, but we can't call channel.eventLoop().execute()
because we need it disabled *now* before the healthcheck happens. The
pipeline preparation phase will remove it safely soon, and in the meantime
it will be disabled.
*/
ChannelPipeline pipeline = channel.pipeline();
ChannelHandler idleHandler = pipeline.get(DOWNSTREAM_IDLE_CHANNEL_TIMEOUT_HANDLER_NAME);
if (idleHandler != null) {
((DownstreamIdleChannelTimeoutHandler) idleHandler).disableTimeoutHandling();
}
}
}
return channel;
}
@Override
protected boolean offerChannel(Channel channel) {
if (idleChannelTimeoutMillis > 0) {
// Add an idle channel timeout detector. This will be removed before the
// channel's reacquisition healthcheck runs (in pollChannel()), so we won't
// have a race condition where this channel is handed over for use but gets
// squashed right before it's about to be used.
// NOTE: Due to the semantics of pool.release() we're guaranteed to be in the
// channel's event loop, so there's no chance of a thread deadlock when
// messing with the pipeline.
channel.pipeline().addFirst(DOWNSTREAM_IDLE_CHANNEL_TIMEOUT_HANDLER_NAME, new DownstreamIdleChannelTimeoutHandler(idleChannelTimeoutMillis, () -> true, false, "StreamingAsyncHttpClientChannel-idle", null, null));
}
return super.offerChannel(channel);
}
};
}
};
poolMap = result;
}
}
}
return result;
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup in project ambry by linkedin.
the class NettyServer method start.
@Override
public void start() throws InstantiationException {
long startupBeginTime = System.currentTimeMillis();
try {
logger.trace("Starting NettyServer deployment");
if (Epoll.isAvailable()) {
logger.trace("Using EpollEventLoopGroup in NettyServer.");
bossGroup = new EpollEventLoopGroup(nettyConfig.nettyServerBossThreadCount);
workerGroup = new EpollEventLoopGroup(nettyConfig.nettyServerWorkerThreadCount);
} else {
bossGroup = new NioEventLoopGroup(nettyConfig.nettyServerBossThreadCount);
workerGroup = new NioEventLoopGroup(nettyConfig.nettyServerWorkerThreadCount);
}
for (Map.Entry<Integer, ChannelInitializer<SocketChannel>> entry : channelInitializers.entrySet()) {
bindServer(entry.getKey(), entry.getValue(), bossGroup, workerGroup);
}
nettyMetrics.registerNettyPendingTasksGauge(bossGroup, "Boss");
nettyMetrics.registerNettyPendingTasksGauge(workerGroup, "Worker");
} catch (InterruptedException e) {
logger.error("NettyServer start await was interrupted", e);
nettyMetrics.nettyServerStartError.inc();
throw new InstantiationException("Netty server bind to port [" + nettyConfig.nettyServerPort + "] was interrupted");
} finally {
long startupTime = System.currentTimeMillis() - startupBeginTime;
logger.info("NettyServer start took {} ms", startupTime);
nettyMetrics.nettyServerStartTimeInMs.update(startupTime);
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup in project lispflowmapping by opendaylight.
the class LispSouthboundPlugin method init.
public void init() {
LOG.info("LISP (RFC6830) Southbound Plugin is initializing...");
synchronized (startLock) {
this.akdb = new AuthKeyDb(new HashMapDb());
this.authenticationKeyDataListener = new AuthenticationKeyDataListener(dataBroker, akdb);
this.dsbe = new DataStoreBackEnd(dataBroker);
restoreDaoFromDatastore();
LispSouthboundHandler lsbh = new LispSouthboundHandler(this);
this.lispSouthboundHandler = lsbh;
LispXtrSouthboundHandler lxsbh = new LispXtrSouthboundHandler(this);
this.lispXtrSouthboundHandler = lxsbh;
if (Epoll.isAvailable()) {
eventLoopGroup = new EpollEventLoopGroup(numChannels, threadFactory);
channelType = EpollDatagramChannel.class;
bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
bootstrap.option(EpollChannelOption.SO_REUSEPORT, true);
LOG.debug("Using Netty Epoll for UDP sockets");
} else {
eventLoopGroup = new NioEventLoopGroup(0, threadFactory);
channelType = NioDatagramChannel.class;
LOG.debug("Using Netty I/O (non-Epoll) for UDP sockets");
}
bootstrap.group(eventLoopGroup);
bootstrap.channel(channelType);
bootstrap.handler(lsbh);
xtrBootstrap.group(eventLoopGroup);
xtrBootstrap.channel(channelType);
xtrBootstrap.handler(lxsbh);
start();
startXtr();
clusterSingletonService.registerClusterSingletonService(this);
LOG.info("LISP (RFC6830) Southbound Plugin is up!");
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup in project netty by netty.
the class EpollSocketChannelBenchmark method setup.
@Setup
public void setup() throws Exception {
group = new EpollEventLoopGroup(1);
// add an arbitrary timeout to make the timer reschedule
future = group.schedule(new Runnable() {
@Override
public void run() {
throw new AssertionError();
}
}, 5, TimeUnit.MINUTES);
serverChan = new ServerBootstrap().channel(EpollServerSocketChannel.class).group(group).childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) {
ch.pipeline().addLast(new ChannelDuplexHandler() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
if (msg instanceof ByteBuf) {
ctx.writeAndFlush(msg, ctx.voidPromise());
} else {
throw new AssertionError();
}
}
});
}
}).bind(0).sync().channel();
chan = new Bootstrap().channel(EpollSocketChannel.class).handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) {
ch.pipeline().addLast(new ChannelDuplexHandler() {
private ChannelPromise lastWritePromise;
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
if (msg instanceof ByteBuf) {
ByteBuf buf = (ByteBuf) msg;
try {
if (buf.readableBytes() == 1) {
lastWritePromise.trySuccess();
lastWritePromise = null;
} else {
throw new AssertionError();
}
} finally {
buf.release();
}
} else {
throw new AssertionError();
}
}
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (lastWritePromise != null) {
throw new IllegalStateException();
}
lastWritePromise = promise;
super.write(ctx, msg, ctx.voidPromise());
}
});
}
}).group(group).connect(serverChan.localAddress()).sync().channel();
abyte = chan.alloc().directBuffer(1);
abyte.writeByte('a');
}
Aggregations