Search in sources :

Example 16 with EventExecutor

use of io.netty.util.concurrent.EventExecutor in project netty by netty.

the class Bzip2Encoder method close.

/**
     * Close this {@link Bzip2Encoder} and so finish the encoding.
     * The given {@link ChannelFuture} will be notified once the operation
     * completes and will also be returned.
     */
public ChannelFuture close(final ChannelPromise promise) {
    ChannelHandlerContext ctx = ctx();
    EventExecutor executor = ctx.executor();
    if (executor.inEventLoop()) {
        return finishEncode(ctx, promise);
    } else {
        executor.execute(new Runnable() {

            @Override
            public void run() {
                ChannelFuture f = finishEncode(ctx(), promise);
                f.addListener(new ChannelPromiseNotifier(promise));
            }
        });
        return promise;
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) EventExecutor(io.netty.util.concurrent.EventExecutor) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelPromiseNotifier(io.netty.channel.ChannelPromiseNotifier)

Example 17 with EventExecutor

use of io.netty.util.concurrent.EventExecutor in project netty by netty.

the class AbstractChannelHandlerContext method invokeUserEventTriggered.

static void invokeUserEventTriggered(final AbstractChannelHandlerContext next, final Object event) {
    ObjectUtil.checkNotNull(event, "event");
    EventExecutor executor = next.executor();
    if (executor.inEventLoop()) {
        next.invokeUserEventTriggered(event);
    } else {
        executor.execute(new Runnable() {

            @Override
            public void run() {
                next.invokeUserEventTriggered(event);
            }
        });
    }
}
Also used : EventExecutor(io.netty.util.concurrent.EventExecutor) OrderedEventExecutor(io.netty.util.concurrent.OrderedEventExecutor)

Example 18 with EventExecutor

use of io.netty.util.concurrent.EventExecutor in project netty by netty.

the class JZlibEncoder method close.

@Override
public ChannelFuture close(final ChannelPromise promise) {
    ChannelHandlerContext ctx = ctx();
    EventExecutor executor = ctx.executor();
    if (executor.inEventLoop()) {
        return finishEncode(ctx, promise);
    } else {
        final ChannelPromise p = ctx.newPromise();
        executor.execute(new Runnable() {

            @Override
            public void run() {
                ChannelFuture f = finishEncode(ctx(), p);
                f.addListener(new ChannelPromiseNotifier(promise));
            }
        });
        return p;
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) EventExecutor(io.netty.util.concurrent.EventExecutor) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelPromise(io.netty.channel.ChannelPromise) ChannelPromiseNotifier(io.netty.channel.ChannelPromiseNotifier)

Example 19 with EventExecutor

use of io.netty.util.concurrent.EventExecutor in project netty by netty.

the class ThreadPerChannelEventLoopGroupTest method runTest.

private static void runTest(ThreadPerChannelEventLoopGroup loopGroup) throws InterruptedException {
    int taskCount = 100;
    EventExecutor testExecutor = new TestEventExecutor();
    ChannelGroup channelGroup = new DefaultChannelGroup(testExecutor);
    while (taskCount-- > 0) {
        Channel channel = new EmbeddedChannel(NOOP_HANDLER);
        loopGroup.register(new DefaultChannelPromise(channel, testExecutor));
        channelGroup.add(channel);
    }
    channelGroup.close().sync();
    loopGroup.shutdownGracefully(100, 200, TimeUnit.MILLISECONDS).sync();
    assertTrue(loopGroup.isTerminated());
}
Also used : DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) EventExecutor(io.netty.util.concurrent.EventExecutor) SingleThreadEventExecutor(io.netty.util.concurrent.SingleThreadEventExecutor) GlobalEventExecutor(io.netty.util.concurrent.GlobalEventExecutor) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelGroup(io.netty.channel.group.ChannelGroup) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup)

Example 20 with EventExecutor

use of io.netty.util.concurrent.EventExecutor in project netty by netty.

the class DefaultChannelPipelineTest method testNotPinExecutor.

@Test
public void testNotPinExecutor() {
    EventExecutorGroup group = new DefaultEventExecutorGroup(2);
    ChannelPipeline pipeline = new LocalChannel().pipeline();
    pipeline.channel().config().setOption(ChannelOption.SINGLE_EVENTEXECUTOR_PER_GROUP, false);
    pipeline.addLast(group, "h1", new ChannelInboundHandlerAdapter());
    pipeline.addLast(group, "h2", new ChannelInboundHandlerAdapter());
    EventExecutor executor1 = pipeline.context("h1").executor();
    EventExecutor executor2 = pipeline.context("h2").executor();
    assertNotNull(executor1);
    assertNotNull(executor2);
    assertNotSame(executor1, 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