Search in sources :

Example 1 with EventExecutor

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;
}
Also used : EventExecutor(io.netty.util.concurrent.EventExecutor) ChannelPromise(io.netty.channel.ChannelPromise)

Example 2 with EventExecutor

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;
}
Also used : EventExecutor(io.netty.util.concurrent.EventExecutor) ChannelPromise(io.netty.channel.ChannelPromise)

Example 3 with EventExecutor

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);
        });
    }
}
Also used : EventExecutor(io.netty.util.concurrent.EventExecutor) ChannelPromise(io.netty.channel.ChannelPromise)

Example 4 with EventExecutor

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);
                    }
                });
            }
        }
    }
}
Also used : EventExecutor(io.netty.util.concurrent.EventExecutor) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelHandler(io.netty.channel.ChannelHandler)

Example 5 with EventExecutor

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);
}
Also used : DefaultEventExecutorGroup(io.netty.util.concurrent.DefaultEventExecutorGroup) EventExecutorGroup(io.netty.util.concurrent.EventExecutorGroup) EventExecutor(io.netty.util.concurrent.EventExecutor) AbstractEventExecutor(io.netty.util.concurrent.AbstractEventExecutor) ImmediateEventExecutor(io.netty.util.concurrent.ImmediateEventExecutor) UnorderedThreadPoolEventExecutor(io.netty.util.concurrent.UnorderedThreadPoolEventExecutor) DefaultEventExecutorGroup(io.netty.util.concurrent.DefaultEventExecutorGroup) LocalChannel(io.netty.channel.local.LocalChannel) Test(org.junit.Test)

Aggregations

EventExecutor (io.netty.util.concurrent.EventExecutor)37 OrderedEventExecutor (io.netty.util.concurrent.OrderedEventExecutor)13 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)6 ChannelPromise (io.netty.channel.ChannelPromise)5 ChannelFuture (io.netty.channel.ChannelFuture)4 ChannelPromiseNotifier (io.netty.channel.ChannelPromiseNotifier)4 EventExecutorGroup (io.netty.util.concurrent.EventExecutorGroup)4 DefaultEventExecutorGroup (io.netty.util.concurrent.DefaultEventExecutorGroup)3 Test (org.junit.Test)3 LocalChannel (io.netty.channel.local.LocalChannel)2 AbstractEventExecutor (io.netty.util.concurrent.AbstractEventExecutor)2 ImmediateEventExecutor (io.netty.util.concurrent.ImmediateEventExecutor)2 UnorderedThreadPoolEventExecutor (io.netty.util.concurrent.UnorderedThreadPoolEventExecutor)2 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 ChannelHandler (io.netty.channel.ChannelHandler)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 ChannelGroup (io.netty.channel.group.ChannelGroup)1 DefaultChannelGroup (io.netty.channel.group.DefaultChannelGroup)1 ServerSocketChannel (io.netty.channel.socket.ServerSocketChannel)1 SocketChannel (io.netty.channel.socket.SocketChannel)1