Package io.grpc.alts.internal
Class ProtectedPromise
- All Implemented Interfaces:
io.netty.channel.ChannelFuture,io.netty.channel.ChannelPromise,io.netty.util.concurrent.Future<Void>,io.netty.util.concurrent.Promise<Void>,Future<Void>
@Internal
public final class ProtectedPromise
extends io.netty.channel.DefaultChannelPromise
Promise used when flushing the
pendingUnprotectedWrites queue. It manages the many-to
many relationship between pending unprotected messages and the individual writes. Each protected
frame will be written using the same instance of this promise and it will accumulate the results.
Once all frames have been successfully written (or any failed), all of the promises for the
pending unprotected writes are notified.
NOTE: this code is based on code in Netty's Http2CodecUtil.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate intprivate intprivate intprivate final List<io.netty.channel.ChannelPromise> Fields inherited from class io.netty.util.concurrent.DefaultPromise
PROPERTY_MAX_LISTENER_STACK_DEPTH -
Constructor Summary
ConstructorsConstructorDescriptionProtectedPromise(io.netty.channel.Channel channel, io.netty.util.concurrent.EventExecutor executor, int numUnprotectedPromises) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddUnprotectedPromise(io.netty.channel.ChannelPromise promise) Adds a promise for a pending unprotected write.private booleanio.netty.channel.ChannelPromiseSignify that no morenewPromise()allocations will be made.io.netty.channel.ChannelPromiseAllocate a new promise for the write of a protected frame.io.netty.channel.ChannelPromisesetFailure(Throwable cause) Fail this object if it has not already been failed.io.netty.channel.ChannelPromisesetSuccess(Void unused) booleantryFailure(Throwable cause) private voidtryFailureInternal(Throwable cause) booleantrySuccess(Void unused) private voidMethods inherited from class io.netty.channel.DefaultChannelPromise
addListener, addListeners, await, awaitUninterruptibly, channel, checkDeadLock, executor, flushCheckpoint, flushCheckpoint, isVoid, promise, removeListener, removeListeners, setSuccess, sync, syncUninterruptibly, trySuccess, unvoidMethods inherited from class io.netty.util.concurrent.DefaultPromise
await, await, awaitUninterruptibly, awaitUninterruptibly, cancel, cause, get, get, getNow, isCancellable, isCancelled, isDone, isSuccess, notifyListener, setUncancellable, toString, toStringBuilderMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.netty.util.concurrent.Future
await, await, awaitUninterruptibly, awaitUninterruptibly, cancel, cause, getNow, isCancellable, isSuccessMethods inherited from interface java.util.concurrent.Future
get, get, isCancelled, isDoneMethods inherited from interface io.netty.util.concurrent.Promise
setUncancellable
-
Field Details
-
unprotectedPromises
-
expectedCount
private int expectedCount -
successfulCount
private int successfulCount -
failureCount
private int failureCount -
doneAllocating
private boolean doneAllocating
-
-
Constructor Details
-
ProtectedPromise
public ProtectedPromise(io.netty.channel.Channel channel, io.netty.util.concurrent.EventExecutor executor, int numUnprotectedPromises)
-
-
Method Details
-
addUnprotectedPromise
public void addUnprotectedPromise(io.netty.channel.ChannelPromise promise) Adds a promise for a pending unprotected write. This will be notified after all of the writes complete. -
newPromise
public io.netty.channel.ChannelPromise newPromise()Allocate a new promise for the write of a protected frame. This will be used to aggregate the overall success of the unprotected promises.- Returns:
thispromise.
-
doneAllocatingPromises
public io.netty.channel.ChannelPromise doneAllocatingPromises()Signify that no morenewPromise()allocations will be made. The aggregation can not be successful until this method is called.- Returns:
thispromise.
-
tryFailure
-
setFailure
Fail this object if it has not already been failed.This method will NOT throw an
IllegalStateExceptionif called multiple times because that may be expected.- Specified by:
setFailurein interfaceio.netty.channel.ChannelPromise- Specified by:
setFailurein interfaceio.netty.util.concurrent.Promise<Void>- Overrides:
setFailurein classio.netty.channel.DefaultChannelPromise
-
awaitingPromises
private boolean awaitingPromises() -
setSuccess
- Specified by:
setSuccessin interfaceio.netty.channel.ChannelPromise- Specified by:
setSuccessin interfaceio.netty.util.concurrent.Promise<Void>- Overrides:
setSuccessin classio.netty.channel.DefaultChannelPromise
-
trySuccess
-
trySuccessInternal
private void trySuccessInternal() -
tryFailureInternal
-