Package io.grpc.alts.internal
Class ProtectedPromise
- java.lang.Object
-
- io.netty.util.concurrent.AbstractFuture<V>
-
- io.netty.util.concurrent.DefaultPromise<java.lang.Void>
-
- io.netty.channel.DefaultChannelPromise
-
- io.grpc.alts.internal.ProtectedPromise
-
- All Implemented Interfaces:
io.netty.channel.ChannelFuture
,io.netty.channel.ChannelPromise
,io.netty.util.concurrent.Future<java.lang.Void>
,io.netty.util.concurrent.Promise<java.lang.Void>
,java.util.concurrent.Future<java.lang.Void>
@Internal public final class ProtectedPromise extends io.netty.channel.DefaultChannelPromise
Promise used when flushing thependingUnprotectedWrites
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
Fields Modifier and Type Field Description private boolean
doneAllocating
private int
expectedCount
private int
failureCount
private int
successfulCount
private java.util.List<io.netty.channel.ChannelPromise>
unprotectedPromises
-
Constructor Summary
Constructors Constructor Description ProtectedPromise(io.netty.channel.Channel channel, io.netty.util.concurrent.EventExecutor executor, int numUnprotectedPromises)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addUnprotectedPromise(io.netty.channel.ChannelPromise promise)
Adds a promise for a pending unprotected write.private boolean
awaitingPromises()
io.netty.channel.ChannelPromise
doneAllocatingPromises()
Signify that no morenewPromise()
allocations will be made.io.netty.channel.ChannelPromise
newPromise()
Allocate a new promise for the write of a protected frame.io.netty.channel.ChannelPromise
setFailure(java.lang.Throwable cause)
Fail this object if it has not already been failed.io.netty.channel.ChannelPromise
setSuccess(java.lang.Void unused)
boolean
tryFailure(java.lang.Throwable cause)
private void
tryFailureInternal(java.lang.Throwable cause)
boolean
trySuccess(java.lang.Void unused)
private void
trySuccessInternal()
-
Methods inherited from class io.netty.channel.DefaultChannelPromise
addListener, addListeners, await, awaitUninterruptibly, channel, checkDeadLock, executor, flushCheckpoint, flushCheckpoint, isVoid, promise, removeListener, removeListeners, setSuccess, sync, syncUninterruptibly, trySuccess, unvoid
-
Methods inherited from class io.netty.util.concurrent.DefaultPromise
await, await, awaitUninterruptibly, awaitUninterruptibly, cancel, cause, get, get, getNow, isCancellable, isCancelled, isDone, isSuccess, notifyListener, setUncancellable, toString, toStringBuilder
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Method Detail
-
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:
this
promise.
-
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:
this
promise.
-
tryFailure
public boolean tryFailure(java.lang.Throwable cause)
- Specified by:
tryFailure
in interfaceio.netty.util.concurrent.Promise<java.lang.Void>
- Overrides:
tryFailure
in classio.netty.util.concurrent.DefaultPromise<java.lang.Void>
-
setFailure
public io.netty.channel.ChannelPromise setFailure(java.lang.Throwable cause)
Fail this object if it has not already been failed.This method will NOT throw an
IllegalStateException
if called multiple times because that may be expected.- Specified by:
setFailure
in interfaceio.netty.channel.ChannelPromise
- Specified by:
setFailure
in interfaceio.netty.util.concurrent.Promise<java.lang.Void>
- Overrides:
setFailure
in classio.netty.channel.DefaultChannelPromise
-
awaitingPromises
private boolean awaitingPromises()
-
setSuccess
public io.netty.channel.ChannelPromise setSuccess(java.lang.Void unused)
- Specified by:
setSuccess
in interfaceio.netty.channel.ChannelPromise
- Specified by:
setSuccess
in interfaceio.netty.util.concurrent.Promise<java.lang.Void>
- Overrides:
setSuccess
in classio.netty.channel.DefaultChannelPromise
-
trySuccess
public boolean trySuccess(java.lang.Void unused)
- Specified by:
trySuccess
in interfaceio.netty.util.concurrent.Promise<java.lang.Void>
- Overrides:
trySuccess
in classio.netty.util.concurrent.DefaultPromise<java.lang.Void>
-
trySuccessInternal
private void trySuccessInternal()
-
tryFailureInternal
private void tryFailureInternal(java.lang.Throwable cause)
-
-