Interface Bulkhead<R>
- Type Parameters:
R- result type
- All Superinterfaces:
Policy<R>
- All Known Implementing Classes:
BulkheadImpl
A bulkhead allows you to restrict concurrent executions as a way of preventing system overload.
This class is threadsafe.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidAttempts to acquire a permit to perform an execution against within the bulkhead, waiting until one is available or the thread is interrupted.default voidacquirePermit(Duration maxWaitTime) Attempts to acquire a permit to perform an execution within the bulkhead, waiting up to themaxWaitTimeuntil one is available, else throwingBulkheadFullExceptionif a permit will not be available in time.static <R> BulkheadBuilder<R> builder(int maxConcurrency) Returns a Bulkhead for themaxConcurrencythat haszero wait.static <R> BulkheadBuilder<R> builder(BulkheadConfig<R> config) Creates a new BulkheadBuilder that will be based on theconfig.Returns theBulkheadConfigthat the Bulkhead was built with.static <R> Bulkhead<R> of(int maxConcurrency) Returns a Bulkhead for themaxConcurrencythat haszero wait.voidReleases a permit to execute.booleanTries to acquire a permit to perform an execution within the bulkhead, returning immediately without waiting.booleantryAcquirePermit(Duration maxWaitTime) Tries to acquire a permit to perform an execution within the bulkhead, waiting up to themaxWaitTimeuntil they are available.Methods inherited from interface Policy
toExecutor
-
Method Details
-
builder
Returns a Bulkhead for themaxConcurrencythat haszero wait.- Parameters:
maxConcurrency- controls the max concurrent executions that are permitted within the bulkhead
-
builder
Creates a new BulkheadBuilder that will be based on theconfig. -
of
Returns a Bulkhead for themaxConcurrencythat haszero wait. Alias forBulkhead.builder(maxConcurrency).build(). To configure additional options on a Bulkhead, usebuilder(int)instead.- Parameters:
maxConcurrency- controls the max concurrent executions that are permitted within the bulkhead- See Also:
-
getConfig
BulkheadConfig<R> getConfig()Returns theBulkheadConfigthat the Bulkhead was built with. -
acquirePermit
Attempts to acquire a permit to perform an execution against within the bulkhead, waiting until one is available or the thread is interrupted. After execution is complete, the permit should bereleasedback to the bulkhead.- Throws:
InterruptedException- if the current thread is interrupted while waiting to acquire a permit- See Also:
-
acquirePermit
Attempts to acquire a permit to perform an execution within the bulkhead, waiting up to themaxWaitTimeuntil one is available, else throwingBulkheadFullExceptionif a permit will not be available in time. After execution is complete, the permit should bereleasedback to the bulkhead.- Throws:
NullPointerException- ifmaxWaitTimeis nullBulkheadFullException- if the bulkhead cannot acquire a permit within themaxWaitTimeInterruptedException- if the current thread is interrupted while waiting to acquire a permit- See Also:
-
tryAcquirePermit
boolean tryAcquirePermit()Tries to acquire a permit to perform an execution within the bulkhead, returning immediately without waiting. After execution is complete, the permit should bereleasedback to the bulkhead.- Returns:
- whether the requested
permitsare successfully acquired or not
-
tryAcquirePermit
Tries to acquire a permit to perform an execution within the bulkhead, waiting up to themaxWaitTimeuntil they are available. After execution is complete, the permit should bereleasedback to the bulkhead.- Returns:
- whether a permit is successfully acquired
- Throws:
NullPointerException- ifmaxWaitTimeis nullInterruptedException- if the current thread is interrupted while waiting to acquire a permit
-
releasePermit
void releasePermit()Releases a permit to execute.
-