public class MultiLimiter extends Object implements Limiter
Limiter that contains multiple underlying Limiters and requests permits from all those limiters.
Permits are requested serially from the underlying brokers in the order they appear in the constructor. If an underlying
limiter is unable to provide permits, permits from previous underlying limiters are closed. However, for
NonRefillableLimiters, the permits are lost permanently.
Note: MultiLimiter does some optimization of the underlying limiters:
* underlying MultiLimiters are opened, and their underlying limiters are used instead.
* NoopLimiters are ignored.
* underlying Limiters are deduplicated to avoid requesting permits from the same limiter twice.
Deduplication is done based on the Object.equals(Object) method of the underlying limiters.
| Constructor and Description |
|---|
MultiLimiter(Limiter... underlyingLimiters) |
| Modifier and Type | Method and Description |
|---|---|
Closeable |
acquirePermits(long permits)
Acquire a given number of permits.
|
void |
start()
Start the
Limiter. |
void |
stop()
Stop the
Limiter. |
public MultiLimiter(Limiter... underlyingLimiters)
public void start()
LimiterLimiter.
See Limiter.stop()public Closeable acquirePermits(long permits) throws InterruptedException
LimiterDepending on the implementation, the caller of this method may be blocked. It is also up to the caller to decide how to deal with the return value.
acquirePermits in interface Limiterpermits - number of permits to getCloseable instance if the requested permits have been successfully acquired,
or null if otherwise; in the former case, calling Closeable.close() on
the returned Closeable instance will release the acquired permits.InterruptedException - if the caller is interrupted while being blockedpublic void stop()
LimiterLimiter.
See Limiter.start()