Package dev.failsafe
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 TypeMethodDescriptionvoid
Attempts to acquire a permit to perform an execution against within the bulkhead, waiting until one is available or the thread is interrupted.default void
acquirePermit
(Duration maxWaitTime) Attempts to acquire a permit to perform an execution within the bulkhead, waiting up to themaxWaitTime
until one is available, else throwingBulkheadFullException
if a permit will not be available in time.static <R> BulkheadBuilder
<R> builder
(int maxConcurrency) Returns a Bulkhead for themaxConcurrency
that haszero wait
.static <R> BulkheadBuilder
<R> builder
(BulkheadConfig<R> config) Creates a new BulkheadBuilder that will be based on theconfig
.Returns theBulkheadConfig
that the Bulkhead was built with.static <R> Bulkhead
<R> of
(int maxConcurrency) Returns a Bulkhead for themaxConcurrency
that haszero wait
.void
Releases a permit to execute.boolean
Tries to acquire a permit to perform an execution within the bulkhead, returning immediately without waiting.boolean
tryAcquirePermit
(Duration maxWaitTime) Tries to acquire a permit to perform an execution within the bulkhead, waiting up to themaxWaitTime
until they are available.Methods inherited from interface dev.failsafe.Policy
toExecutor
-
Method Details
-
builder
Returns a Bulkhead for themaxConcurrency
that 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 themaxConcurrency
that 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 theBulkheadConfig
that 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 bereleased
back 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 themaxWaitTime
until one is available, else throwingBulkheadFullException
if a permit will not be available in time. After execution is complete, the permit should bereleased
back to the bulkhead.- Throws:
NullPointerException
- ifmaxWaitTime
is nullBulkheadFullException
- if the bulkhead cannot acquire a permit within themaxWaitTime
InterruptedException
- 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 bereleased
back to the bulkhead.- Returns:
- whether the requested
permits
are successfully acquired or not
-
tryAcquirePermit
Tries to acquire a permit to perform an execution within the bulkhead, waiting up to themaxWaitTime
until they are available. After execution is complete, the permit should bereleased
back to the bulkhead.- Returns:
- whether a permit is successfully acquired
- Throws:
NullPointerException
- ifmaxWaitTime
is nullInterruptedException
- if the current thread is interrupted while waiting to acquire a permit
-
releasePermit
void releasePermit()Releases a permit to execute.
-