List of usage examples for io.netty.channel EventLoop inEventLoop
boolean inEventLoop();
From source file:org.opendaylight.tcpmd5.netty.MD5NioSocketChannel.java
License:Open Source License
@Override public ChannelFuture shutdownOutput(final ChannelPromise future) { EventLoop loop = eventLoop(); if (loop.inEventLoop()) { try {//from w w w . j a v a 2 s .c o m javaChannel().socket().shutdownOutput(); future.setSuccess(); } catch (Exception e) { future.setFailure(e); } } else { loop.execute(new Runnable() { @Override public void run() { shutdownOutput(future); } }); } return future; }
From source file:ratpack.exec.internal.DefaultExecControl.java
License:Apache License
@Override public ExecStarter exec() { return new ExecStarter() { private Action<? super Throwable> onError = LOG_UNCAUGHT; private Action<? super Execution> onComplete = noop(); private Action<? super RegistrySpec> registry; private EventLoop eventLoop = execController.getEventLoopGroup().next(); @Override/* w ww. ja va2 s. co m*/ public ExecStarter eventLoop(EventLoop eventLoop) { this.eventLoop = eventLoop; return this; } @Override public ExecStarter onError(Action<? super Throwable> onError) { List<Throwable> seen = Lists.newLinkedList(); this.onError = t -> { if (seen.size() < MAX_ERRORS_THRESHOLD) { seen.add(t); onError.execute(t); } else { seen.forEach(t::addSuppressed); LOGGER.error("Error handler " + onError + "reached maximum error threshold (might be caught in an error loop)", t); } }; return this; } @Override public ExecStarter onComplete(Action<? super Execution> onComplete) { this.onComplete = onComplete; return this; } @Override public ExecStarter register(Action<? super RegistrySpec> registry) { this.registry = registry; return this; } @Override public void start(Action<? super Execution> action) { Optional<StackTraceElement[]> startTrace = ExecutionBacking.TRACE ? Optional.of(Thread.currentThread().getStackTrace()) : Optional.empty(); Action<? super Execution> effectiveAction = registry == null ? action : Action.join(registry, action); if (eventLoop.inEventLoop() && ExecutionBacking.get() == null) { new ExecutionBacking(execController, eventLoop, startTrace, effectiveAction, onError, onComplete); } else { eventLoop.submit(() -> new ExecutionBacking(execController, eventLoop, startTrace, effectiveAction, onError, onComplete)); } } }; }