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 voidacquirePermit()Attempts to acquire a permit to perform an execution against within the bulkhead, waiting until one is available or the thread is interrupted.default voidacquirePermit(java.time.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.BulkheadConfig<R>getConfig()Returns theBulkheadConfigthat the Bulkhead was built with.static <R> Bulkhead<R>of(int maxConcurrency)Returns a Bulkhead for themaxConcurrencythat haszero wait.voidreleasePermit()Releases a permit to execute.booleantryAcquirePermit()Tries to acquire a permit to perform an execution within the bulkhead, returning immediately without waiting.booleantryAcquirePermit(java.time.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 dev.failsafe.Policy
toExecutor
-
-
-
-
Method Detail
-
builder
static <R> BulkheadBuilder<R> builder(int maxConcurrency)
Returns a Bulkhead for themaxConcurrencythat 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 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:
builder(int)
-
getConfig
BulkheadConfig<R> getConfig()
Returns theBulkheadConfigthat the Bulkhead was built with.
-
acquirePermit
void acquirePermit() throws java.lang.InterruptedExceptionAttempts 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:
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.InterruptedExceptionAttempts 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:
java.lang.NullPointerException- ifmaxWaitTimeis nullBulkheadFullException- if the bulkhead cannot acquire a permit within themaxWaitTimejava.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 bereleasedback to the bulkhead.- Returns:
- whether the requested
permitsare successfully acquired or not
-
tryAcquirePermit
boolean tryAcquirePermit(java.time.Duration maxWaitTime) throws java.lang.InterruptedExceptionTries 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:
java.lang.NullPointerException- ifmaxWaitTimeis nulljava.lang.InterruptedException- if the current thread is interrupted while waiting to acquire a permit
-
releasePermit
void releasePermit()
Releases a permit to execute.
-
-