private static void initialize(Configuration conf, Channel channel, DatanodeInfo dnInfo, Enum<?> storageType, OpWriteBlockProto.Builder writeBlockProtoBuilder, int timeoutMs, DFSClient client, Token<BlockTokenIdentifier> accessToken, Promise<Channel> promise) throws IOException { Promise<Void> saslPromise = channel.eventLoop().newPromise(); trySaslNegotiate(conf, channel, dnInfo, timeoutMs, client, accessToken, saslPromise); saslPromise.addListener(new FutureListener<Void>() { @Override public void operationComplete(Future<Void> future) throws Exception { if (future.isSuccess()) { // setup response processing pipeline first, then send request. processWriteBlockResponse(channel, dnInfo, promise, timeoutMs); requestWriteBlock(channel, storageType, writeBlockProtoBuilder); } else { promise.tryFailure(future.cause()); } } }); }
if (ch.eventLoop().inEventLoop()) { write(ch, call); } else { ch.eventLoop().execute(new Runnable() {
private void assertEventLoop() { assert !registered || eventLoop.inEventLoop(); }
@Override protected void doBeginRead() throws Exception { if (readPending) { return; } readPending = true; eventLoop().execute(readTask); }
private void runFinishPeerReadTask(final LocalChannel peer) { // If the peer is writing, we must wait until after reads are completed for that peer before we can read. So // we keep track of the task, and coordinate later that our read can't happen until the peer is done. final Runnable finishPeerReadTask = new Runnable() { @Override public void run() { finishPeerRead0(peer); } }; try { if (peer.writeInProgress) { peer.finishReadFuture = peer.eventLoop().submit(finishPeerReadTask); } else { peer.eventLoop().execute(finishPeerReadTask); } } catch (Throwable cause) { logger.warn("Closing Local channels {}-{} because exception occurred!", this, peer, cause); close(); peer.close(); PlatformDependent.throwException(cause); } }
@Override public boolean isTerminated() { for (EventLoop l: activeChildren) { if (!l.isTerminated()) { return false; } } for (EventLoop l: idleChildren) { if (!l.isTerminated()) { return false; } } return true; }
@Override public boolean isShutdown() { for (EventLoop l: activeChildren) { if (!l.isShutdown()) { return false; } } for (EventLoop l: idleChildren) { if (!l.isShutdown()) { return false; } } return true; }
@Override public boolean isShuttingDown() { for (EventLoop l: activeChildren) { if (!l.isShuttingDown()) { return false; } } for (EventLoop l: idleChildren) { if (!l.isShuttingDown()) { return false; } } return true; }
@Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long deadline = System.nanoTime() + unit.toNanos(timeout); for (EventLoop l: activeChildren) { for (;;) { long timeLeft = deadline - System.nanoTime(); if (timeLeft <= 0) { return isTerminated(); } if (l.awaitTermination(timeLeft, TimeUnit.NANOSECONDS)) { break; } } } for (EventLoop l: idleChildren) { for (;;) { long timeLeft = deadline - System.nanoTime(); if (timeLeft <= 0) { return isTerminated(); } if (l.awaitTermination(timeLeft, TimeUnit.NANOSECONDS)) { break; } } } return isTerminated(); }
@Override protected void initChannel(Channel ch) throws Exception { assert ch.eventLoop().inEventLoop(); handler.channelCreated(ch); } });
private static void doBind0( final ChannelFuture regFuture, final Channel channel, final SocketAddress localAddress, final ChannelPromise promise) { // This method is invoked before channelRegistered() is triggered. Give user handlers a chance to set up // the pipeline in its channelRegistered() implementation. channel.eventLoop().execute(new Runnable() { @Override public void run() { if (regFuture.isSuccess()) { channel.bind(localAddress, promise).addListener(ChannelFutureListener.CLOSE_ON_FAILURE); } else { promise.setFailure(regFuture.cause()); } } }); }
if (ch.eventLoop().inEventLoop()) { write(ch, call); } else { ch.eventLoop().execute(new Runnable() {
return; Promise<Boolean> saslPromise = ch.eventLoop().newPromise(); final NettyHBaseSaslRpcClientHandler saslHandler; try {
final void invokeHandlerAddedIfNeeded() { assert channel.eventLoop().inEventLoop(); if (firstRegistration) { firstRegistration = false; // We are now registered to the EventLoop. It's time to call the callbacks for the ChannelHandlers, // that were added before the registration was done. callHandlerAddedForAllHandlers(); } }
private static void doConnect( final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise connectPromise) { // This method is invoked before channelRegistered() is triggered. Give user handlers a chance to set up // the pipeline in its channelRegistered() implementation. final Channel channel = connectPromise.channel(); channel.eventLoop().execute(new Runnable() { @Override public void run() { if (localAddress == null) { channel.connect(remoteAddress, connectPromise); } else { channel.connect(remoteAddress, localAddress, connectPromise); } connectPromise.addListener(ChannelFutureListener.CLOSE_ON_FAILURE); } }); }
private void addToSpliceQueue(final SpliceInTask task) { EventLoop eventLoop = eventLoop(); if (eventLoop.inEventLoop()) { addToSpliceQueue0(task); } else { eventLoop.execute(new Runnable() { @Override public void run() { addToSpliceQueue0(task); } }); } }
Promise<Boolean> connectionHeaderPromise = ch.eventLoop().newPromise();
private void releaseInboundBuffers() { assert eventLoop() == null || eventLoop().inEventLoop(); readInProgress = false; Queue<Object> inboundBuffer = this.inboundBuffer; Object msg; while ((msg = inboundBuffer.poll()) != null) { ReferenceCountUtil.release(msg); } }
private void invokeLater(Runnable task) { try { // This method is used by outbound operation implementations to trigger an inbound event later. // They do not trigger an inbound event immediately because an outbound operation might have been // triggered by another inbound event handler method. If fired immediately, the call stack // will look like this for example: // // handlerA.inboundBufferUpdated() - (1) an inbound handler method closes a connection. // -> handlerA.ctx.close() // -> channel.unsafe.close() // -> handlerA.channelInactive() - (2) another inbound handler method called while in (1) yet // // which means the execution of two inbound handler methods of the same handler overlap undesirably. eventLoop().execute(task); } catch (RejectedExecutionException e) { logger.warn("Can't invoke task later as EventLoop rejected it", e); } }
@Override public ChannelFuture shutdownInput(final ChannelPromise promise) { EventLoop loop = eventLoop(); if (loop.inEventLoop()) { shutdownInput0(promise); } else { loop.execute(new Runnable() { @Override public void run() { shutdownInput0(promise); } }); } return promise; }