Example usage for io.netty.util.concurrent EventExecutor inEventLoop

List of usage examples for io.netty.util.concurrent EventExecutor inEventLoop

Introduction

In this page you can find the example usage for io.netty.util.concurrent EventExecutor inEventLoop.

Prototype

boolean inEventLoop();

Source Link

Document

Calls #inEventLoop(Thread) with Thread#currentThread() as argument

Usage

From source file:com.caricah.iotracah.server.netty.channelgroup.IotChannelGroupFuture.java

License:Apache License

@Override
protected void checkDeadLock() {
    EventExecutor e = executor();
    if (e != null && e != ImmediateEventExecutor.INSTANCE && e.inEventLoop()) {
        throw new BlockingOperationException();
    }/* w  ww.  j  a v a  2  s. c  om*/
}

From source file:com.datastax.driver.core.AbstractSession.java

License:Apache License

/**
 * Checks that the current thread is not one of the Netty I/O threads used by the driver.
 * <p/>/*from  w  w w  . j  a v  a  2  s .  c o  m*/
 * This method is called from all the synchronous methods of this class to prevent deadlock issues.
 * <p/>
 * User code extending this class can also call this method at any time to check if any code
 * making blocking calls is being wrongly executed on a Netty I/O thread.
 * <p/>
 * Note that the check performed by this method has a small overhead; if
 * that is an issue, checks can be disabled by setting the System property
 * {@code com.datastax.driver.CHECK_IO_DEADLOCKS} to {@code false}.
 *
 * @throws IllegalStateException if the current thread is one of the Netty I/O thread used by the driver.
 */
public void checkNotInEventLoop() {
    Connection.Factory connectionFactory = getCluster().manager.connectionFactory;
    if (!CHECK_IO_DEADLOCKS || connectionFactory == null)
        return;
    for (EventExecutor executor : connectionFactory.eventLoopGroup) {
        if (executor.inEventLoop()) {
            throw new IllegalStateException(
                    "Detected a synchronous call on an I/O thread, this can cause deadlocks or unpredictable "
                            + "behavior. This generally happens when a Future callback calls a synchronous Session "
                            + "method (execute() or prepare()), or iterates a result set past the fetch size "
                            + "(causing an internal synchronous fetch of the next page of results). "
                            + "Avoid this in your callbacks, or schedule them on a different executor.");
        }
    }
}

From source file:com.datastax.driver.core.SessionManager.java

License:Apache License

@Override
protected void checkNotInEventLoop() {
    Connection.Factory connectionFactory = cluster.manager.connectionFactory;
    if (!CHECK_IO_DEADLOCKS || connectionFactory == null)
        return;//ww  w .j a v a2s  .  c  o  m
    for (EventExecutor executor : connectionFactory.eventLoopGroup) {
        if (executor.inEventLoop()) {
            throw new IllegalStateException(
                    "Detected a synchronous Session call (execute() or prepare()) on an I/O thread, "
                            + "this can cause deadlocks or unpredictable behavior. "
                            + "Make sure your Future callbacks only use async calls, or schedule them on a "
                            + "different executor.");
        }
    }
}

From source file:io.reactivex.netty.pipeline.ReadTimeoutPipelineConfigurator.java

License:Apache License

public static void disableReadTimeout(ChannelPipeline pipeline) {

    /**/* w  ww .  j a v  a 2s .c o  m*/
     * Since, ChannelPipeline.remove() is blocking when not called from the associated eventloop, we do not remove
     * the handler. Instead we decativate the handler (invoked by the associated eventloop) here so that it does not
     * generate any more timeouts.
     * The handler is activated on next write to this pipeline.
     *
     * See issue: https://github.com/Netflix/RxNetty/issues/145
     */
    final ChannelHandler timeoutHandler = pipeline.get(READ_TIMEOUT_HANDLER_NAME);
    if (timeoutHandler != null) {
        final ChannelHandlerContext handlerContext = pipeline.context(timeoutHandler);
        EventExecutor executor = handlerContext.executor();

        // Since, we are calling the handler directly, we need to make sure, it is in the owner eventloop, else it
        // can get concurrent callbacks.
        if (executor.inEventLoop()) {
            disableHandler(timeoutHandler, handlerContext);
        } else {
            executor.submit(new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    disableHandler(timeoutHandler, handlerContext);
                    return null;
                }
            });
        }
    }
}

From source file:io.vertx.core.http.impl.VertxHttp2ConnectionHandler.java

License:Open Source License

void writeHeaders(Http2Stream stream, Http2Headers headers, boolean end) {
    EventExecutor executor = ctx.executor();
    if (executor.inEventLoop()) {
        _writeHeaders(stream, headers, end);
    } else {/*  w  w w.j a  va 2  s .  co  m*/
        executor.execute(() -> {
            _writeHeaders(stream, headers, end);
        });
    }
}

From source file:io.vertx.core.http.impl.VertxHttp2ConnectionHandler.java

License:Open Source License

void writeData(Http2Stream stream, ByteBuf chunk, boolean end) {
    EventExecutor executor = ctx.executor();
    if (executor.inEventLoop()) {
        _writeData(stream, chunk, end);/*from w w  w  .  j a  va 2 s.com*/
    } else {
        executor.execute(() -> {
            _writeData(stream, chunk, end);
        });
    }
}

From source file:io.vertx.core.http.impl.VertxHttp2ConnectionHandler.java

License:Open Source License

ChannelFuture writePing(ByteBuf data) {
    ChannelPromise promise = ctx.newPromise();
    EventExecutor executor = ctx.executor();
    if (executor.inEventLoop()) {
        _writePing(data, promise);/*from  ww w  .  j  av a  2s .  c  o m*/
    } else {
        executor.execute(() -> {
            _writePing(data, promise);
        });
    }
    return promise;
}

From source file:io.vertx.core.http.impl.VertxHttp2ConnectionHandler.java

License:Open Source License

void writeFrame(Http2Stream stream, byte type, short flags, ByteBuf payload) {
    EventExecutor executor = ctx.executor();
    if (executor.inEventLoop()) {
        _writeFrame(stream, type, flags, payload);
    } else {//from   ww  w  .j  a va  2  s.c o m
        executor.execute(() -> {
            _writeFrame(stream, type, flags, payload);
        });
    }
}

From source file:io.vertx.core.http.impl.VertxHttp2ConnectionHandler.java

License:Open Source License

void writeReset(int streamId, long code) {
    EventExecutor executor = ctx.executor();
    if (executor.inEventLoop()) {
        _writeReset(streamId, code);//from   ww w.j  a  va  2s .  c  o  m
    } else {
        executor.execute(() -> {
            _writeReset(streamId, code);
        });
    }
}

From source file:io.vertx.core.http.impl.VertxHttp2ConnectionHandler.java

License:Open Source License

void writeGoAway(long errorCode, int lastStreamId, ByteBuf debugData) {
    EventExecutor executor = ctx.executor();
    if (executor.inEventLoop()) {
        _writeGoAway(errorCode, lastStreamId, debugData);
    } else {/*from   w  ww. ja v a  2  s .c o m*/
        executor.execute(() -> {
            _writeGoAway(errorCode, lastStreamId, debugData);
        });
    }
}