@Override public void flush(ChannelHandlerContext ctx) throws Exception { if (queue.isEmpty()) { return; } ByteBuf buf = null; try { ChannelPromise promise = ctx.newPromise(); int readableBytes = queue.readableBytes(); buf = queue.remove(readableBytes, promise); byte[] bytes = new byte[readableBytes]; buf.readBytes(bytes); byte[] wrapperBytes = saslClient.wrap(bytes, 0, bytes.length); ChannelPromise lenPromise = ctx.newPromise(); ctx.write(ctx.alloc().buffer(4).writeInt(wrapperBytes.length), lenPromise); ChannelPromise contentPromise = ctx.newPromise(); ctx.write(Unpooled.wrappedBuffer(wrapperBytes), contentPromise); PromiseCombiner combiner = new PromiseCombiner(); combiner.addAll(lenPromise, contentPromise); combiner.finish(promise); ctx.flush(); } finally { if (buf != null) { ReferenceCountUtil.safeRelease(buf); } } }
PromiseCombiner combiner = new PromiseCombiner(); try { ChannelPromise promise = write.promise; recycle(write, false); combiner.add(promise); ctx.write(msg, promise); write = next; combiner.finish(p); } catch (Throwable cause) { p.setFailure(cause);
/** * Adds new promises to be combined. New promises may be added until an aggregate promise is added via the * {@link PromiseCombiner#finish(Promise)} method. * * @param promises the promises to add to this promise combiner * * @deprecated Replaced by {@link PromiseCombiner#addAll(Future[])} */ @Deprecated public void addAll(Promise... promises) { addAll((Future[]) promises); }
/** * Adds new futures to be combined. New futures may be added until an aggregate promise is added via the * {@link PromiseCombiner#finish(Promise)} method. * * @param futures the futures to add to this promise combiner */ @SuppressWarnings({ "unchecked", "rawtypes" }) public void addAll(Future... futures) { for (Future future : futures) { this.add(future); } }
/** * Adds a new future to be combined. New futures may be added until an aggregate promise is added via the * {@link PromiseCombiner#finish(Promise)} method. * * @param future the future to add to this promise combiner */ @SuppressWarnings({ "unchecked", "rawtypes" }) public void add(Future future) { checkAddAllowed(); ++expectedCount; future.addListener(listener); }
/** * <p>Sets the promise to be notified when all combined futures have finished. If all combined futures succeed, * then the aggregate promise will succeed. If one or more combined futures fails, then the aggregate promise will * fail with the cause of one of the failed futures. If more than one combined future fails, then exactly which * failure will be assigned to the aggregate promise is undefined.</p> * * <p>After this method is called, no more futures may be added via the {@link PromiseCombiner#add(Future)} or * {@link PromiseCombiner#addAll(Future[])} methods.</p> * * @param aggregatePromise the promise to notify when all combined futures have finished */ public void finish(Promise<Void> aggregatePromise) { if (doneAdding) { throw new IllegalStateException("Already finished"); } doneAdding = true; this.aggregatePromise = ObjectUtil.checkNotNull(aggregatePromise, "aggregatePromise"); if (doneCount == expectedCount) { tryPromise(); } }
PromiseCombiner combiner = new PromiseCombiner(); for (;;) { ByteBuf nextBuf = nextReadableBuf(channel); combiner.add(bufPromise); super.writeData(ctx, streamId, buf, padding, compressedEndOfStream, bufPromise); if (nextBuf == null) { buf = nextBuf; combiner.finish(promise); } catch (Throwable cause) { promise.tryFailure(cause);
/** * Adds a new promise to be combined. New promises may be added until an aggregate promise is added via the * {@link PromiseCombiner#finish(Promise)} method. * * @param promise the promise to add to this promise combiner * * @deprecated Replaced by {@link PromiseCombiner#add(Future)}. */ @Deprecated public void add(Promise promise) { add((Future) promise); }
@Override public void flush(ChannelHandlerContext ctx) throws Exception { if (queue.isEmpty()) { return; } ByteBuf buf = null; try { ChannelPromise promise = ctx.newPromise(); int readableBytes = queue.readableBytes(); buf = queue.remove(readableBytes, promise); byte[] bytes = new byte[readableBytes]; buf.readBytes(bytes); byte[] wrapperBytes = cryptoAES.wrap(bytes, 0, bytes.length); ChannelPromise lenPromise = ctx.newPromise(); ctx.write(ctx.alloc().buffer(4).writeInt(wrapperBytes.length), lenPromise); ChannelPromise contentPromise = ctx.newPromise(); ctx.write(Unpooled.wrappedBuffer(wrapperBytes), contentPromise); PromiseCombiner combiner = new PromiseCombiner(); combiner.addAll(lenPromise, contentPromise); combiner.finish(promise); ctx.flush(); } finally { if (buf != null) { ReferenceCountUtil.safeRelease(buf); } } }
ChannelPromise cellBlockPromise = ctx.newPromise(); ctx.write(cellBlock, cellBlockPromise); PromiseCombiner combiner = new PromiseCombiner(); combiner.addAll(withoutCellBlockPromise, cellBlockPromise); combiner.finish(promise); } else { ctx.write(buf, promise);
@Override public void flush(ChannelHandlerContext ctx) throws Exception { if (queue.isEmpty()) { return; } ByteBuf buf = null; try { ChannelPromise promise = ctx.newPromise(); int readableBytes = queue.readableBytes(); buf = queue.remove(readableBytes, promise); byte[] bytes = new byte[readableBytes]; buf.readBytes(bytes); byte[] wrapperBytes = saslClient.wrap(bytes, 0, bytes.length); ChannelPromise lenPromise = ctx.newPromise(); ctx.write(ctx.alloc().buffer(4).writeInt(wrapperBytes.length), lenPromise); ChannelPromise contentPromise = ctx.newPromise(); ctx.write(Unpooled.wrappedBuffer(wrapperBytes), contentPromise); PromiseCombiner combiner = new PromiseCombiner(); combiner.addAll(lenPromise, contentPromise); combiner.finish(promise); ctx.flush(); } finally { if (buf != null) { ReferenceCountUtil.safeRelease(buf); } } }
@Override public void flush(ChannelHandlerContext ctx) throws Exception { if (queue.isEmpty()) { return; } ByteBuf buf = null; try { ChannelPromise promise = ctx.newPromise(); int readableBytes = queue.readableBytes(); buf = queue.remove(readableBytes, promise); byte[] bytes = new byte[readableBytes]; buf.readBytes(bytes); byte[] wrapperBytes = cryptoAES.wrap(bytes, 0, bytes.length); ChannelPromise lenPromise = ctx.newPromise(); ctx.write(ctx.alloc().buffer(4).writeInt(wrapperBytes.length), lenPromise); ChannelPromise contentPromise = ctx.newPromise(); ctx.write(Unpooled.wrappedBuffer(wrapperBytes), contentPromise); PromiseCombiner combiner = new PromiseCombiner(); combiner.addAll(lenPromise, contentPromise); combiner.finish(promise); ctx.flush(); } finally { if (buf != null) { ReferenceCountUtil.safeRelease(buf); } } }
ChannelPromise cellBlockPromise = ctx.newPromise(); ctx.write(cellBlock, cellBlockPromise); PromiseCombiner combiner = new PromiseCombiner(); combiner.addAll(withoutCellBlockPromise, cellBlockPromise); combiner.finish(promise); } else { ctx.write(buf, promise);
@Override public void flush(ChannelHandlerContext ctx) throws Exception { if (queue.isEmpty()) { return; } ByteBuf buf = null; try { ChannelPromise promise = ctx.newPromise(); int readableBytes = queue.readableBytes(); buf = queue.remove(readableBytes, promise); byte[] bytes = new byte[readableBytes]; buf.readBytes(bytes); byte[] wrapperBytes = saslClient.wrap(bytes, 0, bytes.length); ChannelPromise lenPromise = ctx.newPromise(); ctx.write(ctx.alloc().buffer(4).writeInt(wrapperBytes.length), lenPromise); ChannelPromise contentPromise = ctx.newPromise(); ctx.write(Unpooled.wrappedBuffer(wrapperBytes), contentPromise); PromiseCombiner combiner = new PromiseCombiner(); combiner.addAll(lenPromise, contentPromise); combiner.finish(promise); ctx.flush(); } finally { if (buf != null) { ReferenceCountUtil.safeRelease(buf); } } }
@Override public void flush(ChannelHandlerContext ctx) throws Exception { if (queue.isEmpty()) { return; } ByteBuf buf = null; try { ChannelPromise promise = ctx.newPromise(); int readableBytes = queue.readableBytes(); buf = queue.remove(readableBytes, promise); byte[] bytes = new byte[readableBytes]; buf.readBytes(bytes); byte[] wrapperBytes = cryptoAES.wrap(bytes, 0, bytes.length); ChannelPromise lenPromise = ctx.newPromise(); ctx.write(ctx.alloc().buffer(4).writeInt(wrapperBytes.length), lenPromise); ChannelPromise contentPromise = ctx.newPromise(); ctx.write(Unpooled.wrappedBuffer(wrapperBytes), contentPromise); PromiseCombiner combiner = new PromiseCombiner(); combiner.addAll(lenPromise, contentPromise); combiner.finish(promise); ctx.flush(); } finally { if (buf != null) { ReferenceCountUtil.safeRelease(buf); } } }
ChannelPromise cellBlockPromise = ctx.newPromise(); ctx.write(cellBlock, cellBlockPromise); PromiseCombiner combiner = new PromiseCombiner(); combiner.addAll(withoutCellBlockPromise, cellBlockPromise); combiner.finish(promise); } else { ctx.write(buf, promise);