private void scheduleFlush(final ChannelHandlerContext ctx) { if (nextScheduledFlush == null) { // Run as soon as possible, but still yield to give a chance for additional writes to enqueue. nextScheduledFlush = ctx.channel().eventLoop().submit(flushTask); } }
private void scheduleFlush(final ChannelHandlerContext ctx) { if (nextScheduledFlush == null) { // Run as soon as possible, but still yield to give a chance for additional writes to enqueue. nextScheduledFlush = ctx.channel().eventLoop().submit(flushTask); } }
@Override public Future<?> submit(Runnable task) { return next().submit(task); }
@Override public <T> Future<T> submit(Callable<T> task) { return next().submit(task); }
@Override public <T> Future<T> submit(Runnable task, T result) { return next().submit(task, result); }
@Override public void call(Subscriber<? super Void> subscriber) { if (null == c) { subscriber.onCompleted(); } else { /** * Executing the release on the eventloop to avoid race-conditions between code cleaning up * connection in the pipeline and the connecting being released to the pool. */ c.unsafeNettyChannel() .eventLoop() .submit(new ReleaseTask(c, subscriber)); } } });
@Override public void cancel(@Nullable String message, @Nullable Throwable cause) { if (ctx.eventLoop().inEventLoop()) { doCancel(message, cause); } else { ctx.eventLoop().submit(() -> doCancel(message, cause)); } }
@Override public void halfClose() { if (ctx.eventLoop().inEventLoop()) { req.close(); } else { ctx.eventLoop().submit((Runnable) req::close); } }
@Override public void close(Status status, Metadata unusedGrpcMetadata) { if (ctx.eventLoop().inEventLoop()) { doClose(status, unusedGrpcMetadata); } else { ctx.eventLoop().submit(() -> doClose(status, unusedGrpcMetadata)); } }
@Override public void request(int numMessages) { if (ctx.eventLoop().inEventLoop()) { responseReader.request(numMessages); } else { ctx.eventLoop().submit(() -> responseReader.request(numMessages)); } }
public Future<Void> runFromChannelEventLoop(Callable<Void> runnable) throws Exception { Future<Void> toReturn = channel.eventLoop().submit(runnable); runAllPendingTasksOnChannel(); return toReturn; }
@Override public void request(int numMessages) { if (ctx.eventLoop().inEventLoop()) { messageReader.request(numMessages); } else { ctx.eventLoop().submit(() -> messageReader.request(numMessages)); } }
@Override public void sendHeaders(Metadata unusedGrpcMetadata) { if (ctx.eventLoop().inEventLoop()) { doSendHeaders(unusedGrpcMetadata); } else { ctx.eventLoop().submit(() -> doSendHeaders(unusedGrpcMetadata)); } }
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 void sendMessage(O message) { pendingMessagesUpdater.incrementAndGet(this); if (ctx.eventLoop().inEventLoop()) { doSendMessage(message); } else { ctx.eventLoop().submit(() -> doSendMessage(message)); } }
@Override public void sendMessage(I message) { pendingMessagesUpdater.incrementAndGet(this); if (ctx.eventLoop().inEventLoop()) { doSendMessage(message); } else { ctx.eventLoop().submit(() -> doSendMessage(message)); } }
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); } }
@Test public void messageReadAfterClose_byteBuf() { call.close(Status.ABORTED, new Metadata()); // messageRead is always called from the event loop. eventLoop.get().submit(() -> { call.messageRead(new ByteBufOrStream(GrpcTestUtil.requestByteBuf())); verify(listener, never()).onMessage(any()); }).syncUninterruptibly(); }
@Test public void messageReadAfterClose_stream() { call.close(Status.ABORTED, new Metadata()); // messageRead is always called from the event loop. eventLoop.get().submit(() -> { call.messageRead(new ByteBufOrStream(new ByteBufInputStream(GrpcTestUtil.requestByteBuf(), true))); verify(listener, never()).onMessage(any()); }).syncUninterruptibly(); }
@After public void tearDown() { // HttpStreamReader must be invoked from an event loop. eventLoop.get().submit(() -> call.messageReader().cancel()).syncUninterruptibly(); if (!call.isCloseCalled()) { call.close(Status.OK, new Metadata()); } }