Search in sources :

Example 31 with EventExecutor

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

the class DefaultChannelPipeline method destroyUp.

private void destroyUp(AbstractChannelHandlerContext ctx, boolean inEventLoop) {
    final Thread currentThread = Thread.currentThread();
    final AbstractChannelHandlerContext tail = this.tail;
    for (; ; ) {
        if (ctx == tail) {
            destroyDown(currentThread, tail.prev, inEventLoop);
            break;
        }
        final EventExecutor executor = ctx.executor();
        if (!inEventLoop && !executor.inEventLoop(currentThread)) {
            final AbstractChannelHandlerContext finalCtx = ctx;
            executor.execute(new Runnable() {

                @Override
                public void run() {
                    destroyUp(finalCtx, true);
                }
            });
            break;
        }
        ctx = ctx.next;
        inEventLoop = false;
    }
}
Also used : EventExecutor(io.netty.util.concurrent.EventExecutor)

Example 32 with EventExecutor

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

the class AbstractChannelHandlerContext method close.

@Override
public ChannelFuture close(final ChannelPromise promise) {
    if (isNotValidPromise(promise, false)) {
        // cancelled
        return promise;
    }
    final AbstractChannelHandlerContext next = findContextOutbound();
    EventExecutor executor = next.executor();
    if (executor.inEventLoop()) {
        next.invokeClose(promise);
    } else {
        safeExecute(executor, new Runnable() {

            @Override
            public void run() {
                next.invokeClose(promise);
            }
        }, promise, null);
    }
    return promise;
}
Also used : EventExecutor(io.netty.util.concurrent.EventExecutor) OrderedEventExecutor(io.netty.util.concurrent.OrderedEventExecutor)

Example 33 with EventExecutor

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

the class AbstractChannelHandlerContext method flush.

@Override
public ChannelHandlerContext flush() {
    final AbstractChannelHandlerContext next = findContextOutbound();
    EventExecutor executor = next.executor();
    if (executor.inEventLoop()) {
        next.invokeFlush();
    } else {
        Runnable task = next.invokeFlushTask;
        if (task == null) {
            next.invokeFlushTask = task = new Runnable() {

                @Override
                public void run() {
                    next.invokeFlush();
                }
            };
        }
        safeExecute(executor, task, channel().voidPromise(), null);
    }
    return this;
}
Also used : EventExecutor(io.netty.util.concurrent.EventExecutor) OrderedEventExecutor(io.netty.util.concurrent.OrderedEventExecutor)

Example 34 with EventExecutor

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

the class AbstractChannelHandlerContext method invokeChannelWritabilityChanged.

static void invokeChannelWritabilityChanged(final AbstractChannelHandlerContext next) {
    EventExecutor executor = next.executor();
    if (executor.inEventLoop()) {
        next.invokeChannelWritabilityChanged();
    } else {
        Runnable task = next.invokeChannelWritableStateChangedTask;
        if (task == null) {
            next.invokeChannelWritableStateChangedTask = task = new Runnable() {

                @Override
                public void run() {
                    next.invokeChannelWritabilityChanged();
                }
            };
        }
        executor.execute(task);
    }
}
Also used : EventExecutor(io.netty.util.concurrent.EventExecutor) OrderedEventExecutor(io.netty.util.concurrent.OrderedEventExecutor)

Example 35 with EventExecutor

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

the class AbstractChannelHandlerContext method invokeExceptionCaught.

static void invokeExceptionCaught(final AbstractChannelHandlerContext next, final Throwable cause) {
    ObjectUtil.checkNotNull(cause, "cause");
    EventExecutor executor = next.executor();
    if (executor.inEventLoop()) {
        next.invokeExceptionCaught(cause);
    } else {
        try {
            executor.execute(new Runnable() {

                @Override
                public void run() {
                    next.invokeExceptionCaught(cause);
                }
            });
        } catch (Throwable t) {
            if (logger.isWarnEnabled()) {
                logger.warn("Failed to submit an exceptionCaught() event.", t);
                logger.warn("The exceptionCaught() event that was failed to submit was:", cause);
            }
        }
    }
}
Also used : EventExecutor(io.netty.util.concurrent.EventExecutor) OrderedEventExecutor(io.netty.util.concurrent.OrderedEventExecutor)

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