@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { if (msg instanceof Call) { Call call = (Call) msg; id2Call.put(call.id, call); // The call is already in track so here we set the write operation as success. // We will fail the call directly if we can not write it out. promise.trySuccess(); } else { ctx.write(msg, promise); } }
@Override public void close(ChannelPromise promise) { if (!promise.setUncancellable()) { return; if (closePromise.isDone()) { promise.setFailure(new ClosedChannelException()); return; pendingClosePromise.addListener(new DelegatingChannelPromiseNotifier(promise)); return; deregister(unsafe().voidPromise()); promise.setSuccess(); closePromise.setSuccess(); } finally { pendingClosePromise = null;
if (cause == null) { if (tryNotify) { promise.trySuccess(); } else { promise.setSuccess(); promise.tryFailure(cause); } else { promise.setFailure(cause);
@Override public void connect( final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) { if (!promise.setUncancellable() || !ensureOpen(promise)) { return; promise.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { promise.tryFailure(annotateConnectException(t, remoteAddress));
void success(long total) { if (promise.isDone()) { // No need to notify the progress or fulfill the promise because it's done already. return; } if (promise instanceof ChannelProgressivePromise) { // Now we know what the total is. ((ChannelProgressivePromise) promise).tryProgress(total, total); } promise.trySuccess(); }
private boolean tryPromise() { if (lastFailure == null) { promise.trySuccess(); return super.trySuccess(null); } else { promise.tryFailure(lastFailure); return super.tryFailure(lastFailure); } } }
if (promise.isDone()) { if (promise.isCancelled()) { return true; if (promise.channel() != channel()) { throw new IllegalArgumentException(String.format( "promise.channel does not match: %s (expected: %s)", promise.channel(), channel()));
} catch (Http2Exception cause) { if (connection.remote().mayHaveCreatedStream(streamId)) { promise.tryFailure(new IllegalStateException("Stream no longer exists: " + streamId, cause)); return promise; promise = promise.unvoid().addListener(closeStreamLocalListener); promise.tryFailure(t); return promise;
final int streamId = connection.local().incrementAndGetNextStreamId(); if (streamId < 0) { promise.setFailure(new Http2NoMoreStreamIdsException()); return; if (writePromise.isDone()) { notifyHeaderWritePromise(writePromise, promise); } else { numBufferedStreams++; writePromise.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception {
@Override public ChannelPromise addListener(GenericFutureListener<? extends Future<? super Void>> listener) { delegate.addListener(listener); return this; }
aggregatePromise.addListener((ChannelFutureListener) entry); continue; ReferenceCountUtil.safeRelease(entryBuffer); ReferenceCountUtil.safeRelease(toReturn); aggregatePromise.setFailure(cause); PlatformDependent.throwException(cause);
@Override public Channel channel() { return delegate.channel(); }
@Override public void write(ChannelHandlerContext ctx, int allowedBytes) { boolean isInformational = validateHeadersSentState(stream, headers, connection.isServer(), endOfStream); if (promise.isVoid()) { promise = ctx.newPromise(); } promise.addListener(this); ChannelFuture f = frameWriter.writeHeaders(ctx, stream.id(), headers, streamDependency, weight, exclusive, padding, endOfStream, promise); // Writing headers may fail during the encode state if they violate HPACK limits. Throwable failureCause = f.cause(); if (failureCause == null) { stream.headersSent(isInformational); } else { lifecycleManager.onError(ctx, failureCause); } }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { // modify message on way out to add headers if needed if (msg instanceof HttpResponse) { final HttpResponse response = (HttpResponse) msg; trackResponse(response); // Assume the response writer knows if they can persist or not and sets isKeepAlive on the response if (!isKeepAlive(response) || !isSelfDefinedMessageLength(response)) { // No longer keep alive as the client can't tell when the message is done unless we close connection pendingResponses = 0; persistentConnection = false; } // Server might think it can keep connection alive, but we should fix response header if we know better if (!shouldKeepAlive()) { setKeepAlive(response, false); } } if (msg instanceof LastHttpContent && !shouldKeepAlive()) { promise = promise.unvoid().addListener(ChannelFutureListener.CLOSE); } super.write(ctx, msg, promise); }
@Override public ChannelPromise await() throws InterruptedException { delegate.await(); return this; }
@Override public boolean awaitUninterruptibly(long timeout, TimeUnit unit) { return delegate.awaitUninterruptibly(timeout, unit); }
@Override public Void get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return delegate.get(timeout, unit); }
@Override public Throwable cause() { return delegate.cause(); } }
@Override public boolean cancel(boolean mayInterruptIfRunning) { return delegate.cancel(mayInterruptIfRunning); }
@Override public ChannelPromise addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) { delegate.addListeners(listeners); return this; }