예제 #1
0
  private void flush0(
      final ChannelHandlerContext ctx, final int bytesConsumed, final Throwable cause) {
    ChannelFuture flushFuture =
        ctx.flush(
            ctx.newFuture()
                .addListener(
                    new ChannelFutureListener() {
                      @Override
                      public void operationComplete(ChannelFuture future) throws Exception {
                        if (ctx.executor() == ctx.channel().eventLoop()) {
                          notifyFlushFutures(bytesConsumed, cause, future);
                        } else {
                          synchronized (flushFutureNotifier) {
                            notifyFlushFutures(bytesConsumed, cause, future);
                          }
                        }
                      }

                      private void notifyFlushFutures(
                          int bytesConsumed, Throwable cause, ChannelFuture future) {
                        flushFutureNotifier.increaseWriteCounter(bytesConsumed);
                        if (future.isSuccess()) {
                          flushFutureNotifier.notifyFlushFutures(cause);
                        } else {
                          flushFutureNotifier.notifyFlushFutures(cause, future.cause());
                        }
                      }
                    }));

    safeClose(ctx, flushFuture, ctx.newFuture());
  }
예제 #2
0
  private void closeOutboundAndChannel(
      final ChannelHandlerContext ctx, final ChannelFuture future, boolean disconnect)
      throws Exception {
    if (!ctx.channel().isActive()) {
      if (disconnect) {
        ctx.disconnect(future);
      } else {
        ctx.close(future);
      }
      return;
    }

    engine.closeOutbound();

    ChannelFuture closeNotifyFuture = ctx.newFuture();
    flush(ctx, closeNotifyFuture);
    safeClose(ctx, closeNotifyFuture, future);
  }
예제 #3
0
  private void closeOutboundAndChannel(
      final ChannelHandlerContext ctx, final ChannelPromise promise, boolean disconnect)
      throws Exception {
    if (!ctx.channel().isActive()) {
      if (disconnect) {
        ctx.disconnect(promise);
      } else {
        ctx.close(promise);
      }
      return;
    }

    engine.closeOutbound();

    ChannelPromise closeNotifyFuture = ctx.newPromise();
    write(ctx, Unpooled.EMPTY_BUFFER, closeNotifyFuture);
    flush(ctx);
    safeClose(ctx, closeNotifyFuture, promise);
  }