Package dev.failsafe
Interface Bulkhead<R>
-
- Type Parameters:
R
- result type
- All Superinterfaces:
Policy<R>
- All Known Implementing Classes:
BulkheadImpl
public interface Bulkhead<R> extends Policy<R>
A bulkhead allows you to restrict concurrent executions as a way of preventing system overload.This class is threadsafe.
- See Also:
BulkheadConfig
,BulkheadBuilder
,BulkheadFullException
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
acquirePermit()
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(java.time.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
.BulkheadConfig<R>
getConfig()
Returns theBulkheadConfig
that the Bulkhead was built with.static <R> Bulkhead<R>
of(int maxConcurrency)
Returns a Bulkhead for themaxConcurrency
that haszero wait
.void
releasePermit()
Releases a permit to execute.boolean
tryAcquirePermit()
Tries to acquire a permit to perform an execution within the bulkhead, returning immediately without waiting.boolean
tryAcquirePermit(java.time.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 Detail
-
builder
static <R> BulkheadBuilder<R> builder(int maxConcurrency)
Returns a Bulkhead for themaxConcurrency
that haszero wait
.- Parameters:
maxConcurrency
- controls the max concurrent executions that are permitted within the bulkhead
-
builder
static <R> BulkheadBuilder<R> builder(BulkheadConfig<R> config)
Creates a new BulkheadBuilder that will be based on theconfig
.
-
of
static <R> Bulkhead<R> of(int maxConcurrency)
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:
builder(int)
-
getConfig
BulkheadConfig<R> getConfig()
Returns theBulkheadConfig
that the Bulkhead was built with.
-
acquirePermit
void acquirePermit() throws java.lang.InterruptedException
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:
java.lang.InterruptedException
- if the current thread is interrupted while waiting to acquire a permit- See Also:
tryAcquirePermit()
-
acquirePermit
default void acquirePermit(java.time.Duration maxWaitTime) throws java.lang.InterruptedException
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:
java.lang.NullPointerException
- ifmaxWaitTime
is nullBulkheadFullException
- if the bulkhead cannot acquire a permit within themaxWaitTime
java.lang.InterruptedException
- if the current thread is interrupted while waiting to acquire a permit- See Also:
tryAcquirePermit(Duration)
-
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
boolean tryAcquirePermit(java.time.Duration maxWaitTime) throws java.lang.InterruptedException
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:
java.lang.NullPointerException
- ifmaxWaitTime
is nulljava.lang.InterruptedException
- if the current thread is interrupted while waiting to acquire a permit
-
releasePermit
void releasePermit()
Releases a permit to execute.
-
-