public final class ThresholdBackPressureValve extends java.lang.Object implements BackPressureValve
BackPressureValve
.
There are two cases where a backpressure would be triggered:
pendingAsynchronousOperationsCount
, it is incremented when an
async operation is registered, and decremented when it is completed.
blockedAddressSet
. The method notifyAsyncOperationCompleted(Address)
is meant to be called
when ANY async operation has been completed.
Constructor and Description |
---|
ThresholdBackPressureValve(int maximumPendingAsynchronousOperations)
Constructs a ThresholdBackPressureValve.
|
Modifier and Type | Method and Description |
---|---|
void |
blockAddress(Address address)
Requests to stop processing any further input for that address, as long as there is an
uncompleted async operation (registered by @address).
|
boolean |
isAddressBlocked(Address address)
Checks whether a given address was previously blocked with
BackPressureValve.blockAddress(Address) . |
void |
notifyAsyncOperationCompleted(Address owningAddress)
Notifies when a async operation, registered by @owningAddress was completed.
|
void |
notifyAsyncOperationRegistered()
Notifies the back pressure mechanism that a async operation was registered via
Context.registerAsyncOperation(Object, CompletableFuture) . |
boolean |
shouldBackPressure()
Indicates rather a back pressure is needed.
|
public ThresholdBackPressureValve(int maximumPendingAsynchronousOperations)
maximumPendingAsynchronousOperations
- the total allowed async operations to be inflight
per StreamTask, or -1
to disable back pressure.public boolean shouldBackPressure()
shouldBackPressure
in interface BackPressureValve
public void blockAddress(Address address)
NOTE: The address would unblocked as soon as some (one) async operation registered by that address completes.
blockAddress
in interface BackPressureValve
address
- the addresspublic void notifyAsyncOperationRegistered()
Context.registerAsyncOperation(Object, CompletableFuture)
.notifyAsyncOperationRegistered
in interface BackPressureValve
public void notifyAsyncOperationCompleted(Address owningAddress)
notifyAsyncOperationCompleted
in interface BackPressureValve
owningAddress
- the owner of the completed async operation.public boolean isAddressBlocked(Address address)
BackPressureValve.blockAddress(Address)
.isAddressBlocked
in interface BackPressureValve
address
- the address to checkCopyright © 2014–2024 The Apache Software Foundation. All rights reserved.