StreamCreationPermit is used to keep track of that limit and is expected to be
used before attempting to open a Quic stream. Either of tryAcquire() or
tryAcquire(long, TimeUnit, Executor) must be used before attempting to open a new stream. Stream
must only be opened if that method returns true which implies the stream creation limit
hasn't yet reached.
It is expected that for each of the stream types (remote uni, remote bidi, local uni
and local bidi) a separate instance of StreamCreationPermit will be used.
An instance of StreamCreationPermit starts with an initial limit and that limit can be
increased to newer higher values whenever necessary. The limit however cannot be reduced to a
lower value.
None of the methods, including tryAcquire(long, TimeUnit, Executor) and tryAcquire()
block the caller thread.
| Modifier and Type | Class and Description |
|---|---|
| private static class | StreamCreationPermit.
A |
| private class | StreamCreationPermit.
A task which iterates over the waiting acquirers and attempt to acquire a permit. |
| private static record |
| Modifier and Type | Field and Description |
|---|---|
| private final ConcurrentLinkedQueue | |
| private final SequentialScheduler | |
| private final StreamCreationPermit. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv long | Returns: the current limit for stream creationReturns the current limit for stream creation. |
| pack-priv boolean | Returns: true if the permit was acquired and a new stream is allowed to be opened. false otherwise.Attempts to acquire a permit to open a new stream. |
| pack-priv CompletableFuture | Returns: aCompletableFuture whose result will be true if the permit was
acquired and false otherwisethe maximum amount of time to attempt acquiring a permit, after which the
timeout, final TimeUnit CompletableFuture will complete with a result of falsethe timeout unit unit, final Executor the executor that will be used to asynchronously complete the
returned executor)CompletableFuture if a permit is acquired after this
method has returnedAttempts to acquire a permit to open a new stream. |
| pack-priv boolean | Returns: true if the limit was successfully increased tonewLimit, false otherwise.the new limit newLimit)Attempts to increase the limit to |
| acquirers | back to summary |
|---|---|
| private final ConcurrentLinkedQueue<StreamCreationPermit. | |
| permitAcquisitionScheduler | back to summary |
|---|---|
| private final SequentialScheduler permitAcquisitionScheduler | |
| semaphore | back to summary |
|---|---|
| private final StreamCreationPermit. | |
| StreamCreationPermit | back to summary |
|---|---|
pack-priv StreamCreationPermit(final long initialMaxStreams)
| |
| currentLimit | back to summary |
|---|---|
| pack-priv long currentLimit() Returns the current limit for stream creation.
| |
| tryAcquire | back to summary |
|---|---|
| pack-priv boolean tryAcquire() Attempts to acquire a permit to open a new stream. This method does not block and returns immediately. A stream should only be opened if the permit was successfully acquired.
| |
| tryAcquire | back to summary |
|---|---|
| pack-priv CompletableFuture Attempts to acquire a permit to open a new stream. If the permit is available then this method
returns immediately with a
| |
| tryIncreaseLimitTo | back to summary |
|---|---|
| pack-priv boolean tryIncreaseLimitTo(final long newLimit) Attempts to increase the limit to
| |
AbstractQueuedLongSynchronizer whose state represents
the number of permits that have currently been acquired. This Semaphore only
supports "shared" mode; i.e. exclusive mode isn't supported.
The Semaphore maintains a limit which represents
the maximum number of permits that can be acquired through an instance of this class.
The limit can be increased but cannot be
reduced from the previous set limit.
| Modifier and Type | Field and Description |
|---|---|
| private final AtomicLong | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private long | |
| protected long | Returns: -1 If no permits can be acquired. Value >=0, representing the permits that are still available for acquisition.the additional permits that are requested additionalAcquisitions)Overrides java. Attempts to acquire additional permits. |
| private boolean | Returns: true if the limit was increased tonewLimit. false otherwiseThe new limit to set newLimit)Tries to increase the limit to the |
| protected boolean | Returns: true if the permits were released, false otherwisethe number of permits to release releases)Overrides java. Attempts to release permits |
| limit | back to summary |
|---|---|
| private final AtomicLong limit | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. | |
| InternalSemaphore | back to summary |
|---|---|
private InternalSemaphore(final long initialLimit)
| |
| currentLimit | back to summary |
|---|---|
| private long currentLimit() Returns the current limit.
| |
| tryAcquireShared | back to summary |
|---|---|
| protected long tryAcquireShared(final long additionalAcquisitions) Overrides java. Attempts to acquire additional permits. If no permits can be acquired,
then this method returns -1. Upon successfully acquiring the
| |
| tryIncreaseLimitTo | back to summary |
|---|---|
| private boolean tryIncreaseLimitTo(final long newLimit) Tries to increase the limit to the
| |
| tryReleaseShared | back to summary |
|---|---|
| protected boolean tryReleaseShared(final long releases) Overrides java. Attempts to release permits
| |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| TryAcquireTask | back to summary |
|---|---|
| private TryAcquireTask() | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final CompletableFuture | acquirer
Record Component accessed by acquirer(). |
| private final Executor | executor
Record Component accessed by executor(). |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public CompletableFuture | |
| public final boolean | equals(Object o)
Implements abstract java. Indicates whether some other object is "equal to" this one. |
| public Executor | |
| public final int | |
| public final String | toString()
Implements abstract java. Returns a string representation of the record. |
| acquirer | back to summary |
|---|---|
| private final CompletableFuture<Boolean> acquirer Record Component accessed by acquirer(). | |
| executor | back to summary |
|---|---|
| private final Executor executor Record Component accessed by executor(). | |
| Waiter | back to summary |
|---|---|
| pack-priv Waiter(CompletableFuture<Boolean> acquirer, Executor executor) | |
| acquirer | back to summary |
|---|---|
| public CompletableFuture Record Component getter of acquirer. | |
| equals | back to summary |
|---|---|
| public final boolean equals(Object o) Implements abstract java. Doc from java. Indicates whether some other object is "equal to" this one. In addition
to the general contract of
R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
| |
| executor | back to summary |
|---|---|
| public Executor executor() Record Component getter of executor. | |
| hashCode | back to summary |
|---|---|
| public final int hashCode() Implements abstract java. Doc from java. Returns a hash code value for the record.
Obeys the general contract of | |
| toString | back to summary |
|---|---|
| public final String toString() Implements abstract java. Doc from java. Returns a string representation of the record.
In accordance with the general contract of In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves. | |