ContextT
- public final class BlockingLimiter<ContextT> extends java.lang.Object implements Limiter<ContextT>
Limiter
that blocks the caller when the limit has been reached. The caller is
blocked until the limiter has been released, or a timeout is reached. This limiter is
commonly used in batch clients that use the limiter as a back-pressure mechanism.Limiter.Listener
Modifier and Type | Field and Description |
---|---|
static java.time.Duration |
MAX_TIMEOUT |
Modifier and Type | Method and Description |
---|---|
java.util.Optional<Limiter.Listener> |
acquire(ContextT context)
Acquire a token from the limiter.
|
java.lang.String |
toString() |
static <ContextT> BlockingLimiter<ContextT> |
wrap(Limiter<ContextT> delegate)
Wrap a limiter such that acquire will block up to
MAX_TIMEOUT if the limit was reached
instead of return an empty listener immediately |
static <ContextT> BlockingLimiter<ContextT> |
wrap(Limiter<ContextT> delegate,
java.time.Duration timeout)
Wrap a limiter such that acquire will block up to a provided timeout if the limit was reached
instead of return an empty listener immediately
|
public static <ContextT> BlockingLimiter<ContextT> wrap(Limiter<ContextT> delegate)
MAX_TIMEOUT
if the limit was reached
instead of return an empty listener immediatelydelegate
- Non-blocking limiter to wrappublic static <ContextT> BlockingLimiter<ContextT> wrap(Limiter<ContextT> delegate, java.time.Duration timeout)
delegate
- Non-blocking limiter to wraptimeout
- Max amount of time to wait for the wait for the limit to be released. Cannot exceed MAX_TIMEOUT
public java.util.Optional<Limiter.Listener> acquire(ContextT context)
Limiter
public java.lang.String toString()
toString
in class java.lang.Object