use of io.netty.util.concurrent.EventExecutor in project vert.x by eclipse.
the class VertxHttp2ConnectionHandler method writeSettings.
ChannelFuture writeSettings(Http2Settings settingsUpdate) {
ChannelPromise promise = ctx.newPromise();
EventExecutor executor = ctx.executor();
if (executor.inEventLoop()) {
_writeSettings(settingsUpdate, promise);
} else {
executor.execute(() -> {
_writeSettings(settingsUpdate, promise);
});
}
return promise;
}
use of io.netty.util.concurrent.EventExecutor in project vert.x by eclipse.
the class VertxHttp2ConnectionHandler method writePing.
ChannelFuture writePing(ByteBuf data) {
ChannelPromise promise = ctx.newPromise();
EventExecutor executor = ctx.executor();
if (executor.inEventLoop()) {
_writePing(data, promise);
} else {
executor.execute(() -> {
_writePing(data, promise);
});
}
return promise;
}
use of io.netty.util.concurrent.EventExecutor in project vert.x by eclipse.
the class VertxHttp2ConnectionHandler method writePushPromise.
void writePushPromise(int streamId, Http2Headers headers, Handler<AsyncResult<Integer>> completionHandler) {
int promisedStreamId = connection().local().incrementAndGetNextStreamId();
ChannelPromise promise = ctx.newPromise();
promise.addListener(fut -> {
if (fut.isSuccess()) {
completionHandler.handle(Future.succeededFuture(promisedStreamId));
} else {
completionHandler.handle(Future.failedFuture(fut.cause()));
}
});
EventExecutor executor = ctx.executor();
if (executor.inEventLoop()) {
_writePushPromise(streamId, promisedStreamId, headers, promise);
} else {
executor.execute(() -> {
_writePushPromise(streamId, promisedStreamId, headers, promise);
});
}
}
use of io.netty.util.concurrent.EventExecutor in project mongo-java-driver by mongodb.
the class NettyStream method adjustTimeout.
private void adjustTimeout(final boolean disable) {
ChannelHandler timeoutHandler = channel.pipeline().get(READ_HANDLER_NAME);
if (timeoutHandler != null) {
final ReadTimeoutHandler readTimeoutHandler = (ReadTimeoutHandler) timeoutHandler;
final ChannelHandlerContext handlerContext = channel.pipeline().context(timeoutHandler);
EventExecutor executor = handlerContext.executor();
if (disable) {
if (executor.inEventLoop()) {
readTimeoutHandler.removeTimeout(handlerContext);
} else {
executor.submit(new Runnable() {
@Override
public void run() {
readTimeoutHandler.removeTimeout(handlerContext);
}
});
}
} else {
if (executor.inEventLoop()) {
readTimeoutHandler.scheduleTimeout(handlerContext);
} else {
executor.submit(new Runnable() {
@Override
public void run() {
readTimeoutHandler.scheduleTimeout(handlerContext);
}
});
}
}
}
}
use of io.netty.util.concurrent.EventExecutor in project netty by netty.
the class DefaultChannelPipelineTest method testPinExecutor.
@Test
public void testPinExecutor() {
EventExecutorGroup group = new DefaultEventExecutorGroup(2);
ChannelPipeline pipeline = new LocalChannel().pipeline();
ChannelPipeline pipeline2 = new LocalChannel().pipeline();
pipeline.addLast(group, "h1", new ChannelInboundHandlerAdapter());
pipeline.addLast(group, "h2", new ChannelInboundHandlerAdapter());
pipeline2.addLast(group, "h3", new ChannelInboundHandlerAdapter());
EventExecutor executor1 = pipeline.context("h1").executor();
EventExecutor executor2 = pipeline.context("h2").executor();
assertNotNull(executor1);
assertNotNull(executor2);
assertSame(executor1, executor2);
EventExecutor executor3 = pipeline2.context("h3").executor();
assertNotNull(executor3);
assertNotSame(executor3, executor2);
group.shutdownGracefully(0, 0, TimeUnit.SECONDS);
}
Aggregations