public interface Bulkhead
A Bulkhead represent an entity limiting the amount of parallel operations. It does not
assume nor does it mandate usage of any particular concurrency and/or io model. These details are
left for the client to manage. This bulkhead, depending on the underlying concurrency/io model
can be used to shed load, and, where it makes sense, limit resource use (i.e. limit amount of
threads/actors involved in a particular flow, etc).
In order to execute an operation protected by this bulkhead, a permission must be obtained by
calling tryAcquirePermission() ()} If the bulkhead is full, no additional
operations will be permitted to execute until space is available.
Once the operation is complete, regardless of the result, client needs to call onComplete() in order to maintain integrity of internal bulkhead state.
| Modifier and Type | Interface and Description |
|---|---|
static class |
Bulkhead.BulkheadFuture<T>
This class decorates future with Bulkhead functionality around invocation.
|
static interface |
Bulkhead.EventPublisher
An EventPublisher which can be used to register event consumers.
|
static interface |
Bulkhead.Metrics |
| Modifier and Type | Method and Description |
|---|---|
void |
acquirePermission()
Acquires a permission to execute a call, only if one is available at the time of invocation
If the current thread is interrupted while waiting for a permit
then it won't throw InterruptedException, but its interrupt status will be set.
|
void |
changeConfig(BulkheadConfig newConfig)
Dynamic bulkhead configuration change.
|
static <T> java.util.concurrent.Callable<T> |
decorateCallable(Bulkhead bulkhead,
java.util.concurrent.Callable<T> callable)
Returns a callable which is decorated by a bulkhead.
|
static <T> io.vavr.CheckedConsumer<T> |
decorateCheckedConsumer(Bulkhead bulkhead,
io.vavr.CheckedConsumer<T> consumer)
Returns a consumer which is decorated by a bulkhead.
|
static <T,R> io.vavr.CheckedFunction1<T,R> |
decorateCheckedFunction(Bulkhead bulkhead,
io.vavr.CheckedFunction1<T,R> function)
Returns a function which is decorated by a bulkhead.
|
static io.vavr.CheckedRunnable |
decorateCheckedRunnable(Bulkhead bulkhead,
io.vavr.CheckedRunnable runnable)
Returns a runnable which is decorated by a bulkhead.
|
static <T> io.vavr.CheckedFunction0<T> |
decorateCheckedSupplier(Bulkhead bulkhead,
io.vavr.CheckedFunction0<T> supplier)
Returns a supplier which is decorated by a bulkhead.
|
static <T> java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> |
decorateCompletionStage(Bulkhead bulkhead,
java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> supplier)
Returns a supplier which is decorated by a bulkhead.
|
static <T> java.util.function.Consumer<T> |
decorateConsumer(Bulkhead bulkhead,
java.util.function.Consumer<T> consumer)
Returns a consumer which is decorated by a bulkhead.
|
static <T> java.util.function.Supplier<io.vavr.control.Either<java.lang.Exception,T>> |
decorateEitherSupplier(Bulkhead bulkhead,
java.util.function.Supplier<io.vavr.control.Either<? extends java.lang.Exception,T>> supplier)
Returns a supplier which is decorated by a bulkhead.
|
static <T,R> java.util.function.Function<T,R> |
decorateFunction(Bulkhead bulkhead,
java.util.function.Function<T,R> function)
Returns a function which is decorated by a bulkhead.
|
static <T> java.util.function.Supplier<java.util.concurrent.Future<T>> |
decorateFuture(Bulkhead bulkhead,
java.util.function.Supplier<java.util.concurrent.Future<T>> supplier)
Returns a supplier of type Future which is decorated by a bulkhead.
|
static java.lang.Runnable |
decorateRunnable(Bulkhead bulkhead,
java.lang.Runnable runnable)
Returns a runnable which is decorated by a bulkhead.
|
static <T> java.util.function.Supplier<T> |
decorateSupplier(Bulkhead bulkhead,
java.util.function.Supplier<T> supplier)
Returns a supplier which is decorated by a bulkhead.
|
static <T> java.util.function.Supplier<io.vavr.control.Try<T>> |
decorateTrySupplier(Bulkhead bulkhead,
java.util.function.Supplier<io.vavr.control.Try<T>> supplier)
Returns a supplier which is decorated by a bulkhead.
|
default <T> T |
executeCallable(java.util.concurrent.Callable<T> callable)
Decorates and executes the decorated Callable.
|
default <T> T |
executeCheckedSupplier(io.vavr.CheckedFunction0<T> checkedSupplier)
Decorates and executes the decorated Supplier.
|
default <T> java.util.concurrent.CompletionStage<T> |
executeCompletionStage(java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> supplier)
Decorates and executes the decorated CompletionStage.
|
default <T> io.vavr.control.Either<java.lang.Exception,T> |
executeEitherSupplier(java.util.function.Supplier<io.vavr.control.Either<? extends java.lang.Exception,T>> supplier)
Decorates and executes the decorated Supplier.
|
default void |
executeRunnable(java.lang.Runnable runnable)
Decorates and executes the decorated Runnable.
|
default <T> T |
executeSupplier(java.util.function.Supplier<T> supplier)
Decorates and executes the decorated Supplier.
|
default <T> io.vavr.control.Try<T> |
executeTrySupplier(java.util.function.Supplier<io.vavr.control.Try<T>> supplier)
Decorates and executes the decorated Supplier.
|
BulkheadConfig |
getBulkheadConfig()
Returns the BulkheadConfig of this Bulkhead.
|
Bulkhead.EventPublisher |
getEventPublisher()
Returns an EventPublisher which subscribes to the reactive stream of BulkheadEvent and can be
used to register event consumers.
|
Bulkhead.Metrics |
getMetrics()
Get the Metrics of this Bulkhead.
|
java.lang.String |
getName()
Returns the name of this bulkhead.
|
io.vavr.collection.Map<java.lang.String,java.lang.String> |
getTags()
Returns an unmodifiable map with tags assigned to this Bulkhead.
|
static Bulkhead |
of(java.lang.String name,
BulkheadConfig config)
Creates a bulkhead with a custom configuration
|
static Bulkhead |
of(java.lang.String name,
BulkheadConfig config,
io.vavr.collection.Map<java.lang.String,java.lang.String> tags)
Creates a bulkhead with a custom configuration
|
static Bulkhead |
of(java.lang.String name,
java.util.function.Supplier<BulkheadConfig> bulkheadConfigSupplier)
Creates a bulkhead with a custom configuration
|
static Bulkhead |
of(java.lang.String name,
java.util.function.Supplier<BulkheadConfig> bulkheadConfigSupplier,
io.vavr.collection.Map<java.lang.String,java.lang.String> tags)
Creates a bulkhead with a custom configuration
|
static Bulkhead |
ofDefaults(java.lang.String name)
Create a Bulkhead with a default configuration.
|
void |
onComplete()
Records a completed call and releases a permission.
|
void |
releasePermission()
Releases a permission and increases the number of available permits by one.
|
boolean |
tryAcquirePermission()
Acquires a permission to execute a call, only if one is available at the time of invocation.
|
static <T> io.vavr.CheckedFunction0<T> decorateCheckedSupplier(Bulkhead bulkhead, io.vavr.CheckedFunction0<T> supplier)
T - the type of results supplied by this supplierbulkhead - the Bulkheadsupplier - the original supplierstatic <T> java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> decorateCompletionStage(Bulkhead bulkhead, java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> supplier)
T - the type of the returned CompletionStage's resultbulkhead - the bulkheadsupplier - the original supplierstatic <T> java.util.function.Supplier<java.util.concurrent.Future<T>> decorateFuture(Bulkhead bulkhead, java.util.function.Supplier<java.util.concurrent.Future<T>> supplier)
Future.get()
or Future.get(long, TimeUnit) is evaluated even if the underlying call took less time to return. Any delays in evaluating
future will result in holding of permission in the underlying Semaphore.T - the type of the returned Future resultbulkhead - the bulkheadsupplier - the original supplierstatic io.vavr.CheckedRunnable decorateCheckedRunnable(Bulkhead bulkhead, io.vavr.CheckedRunnable runnable)
bulkhead - the bulkheadrunnable - the original runnablestatic <T> java.util.concurrent.Callable<T> decorateCallable(Bulkhead bulkhead, java.util.concurrent.Callable<T> callable)
T - the result type of callablebulkhead - the bulkheadcallable - the original Callablestatic <T> java.util.function.Supplier<T> decorateSupplier(Bulkhead bulkhead, java.util.function.Supplier<T> supplier)
T - the type of results supplied by this supplierbulkhead - the bulkheadsupplier - the original supplierstatic <T> java.util.function.Supplier<io.vavr.control.Try<T>> decorateTrySupplier(Bulkhead bulkhead, java.util.function.Supplier<io.vavr.control.Try<T>> supplier)
T - the type of results supplied by this supplierbulkhead - the bulkheadsupplier - the original supplierstatic <T> java.util.function.Supplier<io.vavr.control.Either<java.lang.Exception,T>> decorateEitherSupplier(Bulkhead bulkhead, java.util.function.Supplier<io.vavr.control.Either<? extends java.lang.Exception,T>> supplier)
T - the type of results supplied by this supplierbulkhead - the bulkheadsupplier - the original supplierstatic <T> java.util.function.Consumer<T> decorateConsumer(Bulkhead bulkhead, java.util.function.Consumer<T> consumer)
T - the type of the input to the consumerbulkhead - the bulkheadconsumer - the original consumerstatic <T> io.vavr.CheckedConsumer<T> decorateCheckedConsumer(Bulkhead bulkhead, io.vavr.CheckedConsumer<T> consumer)
T - the type of the input to the consumerbulkhead - the bulkheadconsumer - the original consumerstatic java.lang.Runnable decorateRunnable(Bulkhead bulkhead, java.lang.Runnable runnable)
bulkhead - the bulkheadrunnable - the original runnablestatic <T,R> java.util.function.Function<T,R> decorateFunction(Bulkhead bulkhead, java.util.function.Function<T,R> function)
T - the type of the input to the functionR - the type of the result of the functionbulkhead - the bulkheadfunction - the original functionstatic <T,R> io.vavr.CheckedFunction1<T,R> decorateCheckedFunction(Bulkhead bulkhead, io.vavr.CheckedFunction1<T,R> function)
T - the type of the input to the functionR - the type of the result of the functionbulkhead - the bulkheadfunction - the original functionstatic Bulkhead ofDefaults(java.lang.String name)
name - the name of the bulkheadstatic Bulkhead of(java.lang.String name, BulkheadConfig config)
name - the name of the bulkheadconfig - a custom BulkheadConfig configurationstatic Bulkhead of(java.lang.String name, BulkheadConfig config, io.vavr.collection.Map<java.lang.String,java.lang.String> tags)
name - the name of the bulkheadconfig - a custom BulkheadConfig configurationtags - tags added to the Bulkheadstatic Bulkhead of(java.lang.String name, java.util.function.Supplier<BulkheadConfig> bulkheadConfigSupplier)
name - the name of the bulkheadbulkheadConfigSupplier - custom configuration supplierstatic Bulkhead of(java.lang.String name, java.util.function.Supplier<BulkheadConfig> bulkheadConfigSupplier, io.vavr.collection.Map<java.lang.String,java.lang.String> tags)
name - the name of the bulkheadbulkheadConfigSupplier - custom configuration suppliertags - tags added to the Bulkheadvoid changeConfig(BulkheadConfig newConfig)
newConfig - new BulkheadConfigboolean tryAcquirePermission()
true if a permission was acquired and false otherwisevoid acquirePermission()
BulkheadFullException - when the Bulkhead is full and no further calls
are permitted.io.github.resilience4j.core.exception.AcquirePermissionCancelledException - if thread was interrupted during permission waitvoid releasePermission()
Should only be used when a permission was acquired but not used. Otherwise use onComplete() to signal a completed call and release a permission.
void onComplete()
java.lang.String getName()
BulkheadConfig getBulkheadConfig()
Bulkhead.Metrics getMetrics()
io.vavr.collection.Map<java.lang.String,java.lang.String> getTags()
Bulkhead.EventPublisher getEventPublisher()
default <T> T executeSupplier(java.util.function.Supplier<T> supplier)
T - the type of results supplied by this suppliersupplier - the original Supplierdefault <T> io.vavr.control.Try<T> executeTrySupplier(java.util.function.Supplier<io.vavr.control.Try<T>> supplier)
T - the type of results supplied by this suppliersupplier - the original Supplierdefault <T> io.vavr.control.Either<java.lang.Exception,T> executeEitherSupplier(java.util.function.Supplier<io.vavr.control.Either<? extends java.lang.Exception,T>> supplier)
T - the type of results supplied by this suppliersupplier - the original Supplierdefault <T> T executeCallable(java.util.concurrent.Callable<T> callable)
throws java.lang.Exception
T - the result type of callablecallable - the original Callablejava.lang.Exception - if unable to compute a resultdefault void executeRunnable(java.lang.Runnable runnable)
runnable - the original Runnabledefault <T> T executeCheckedSupplier(io.vavr.CheckedFunction0<T> checkedSupplier)
throws java.lang.Throwable
T - the type of results supplied by this suppliercheckedSupplier - the original Supplierjava.lang.Throwable - if something goes wrong applying this function to the given argumentsdefault <T> java.util.concurrent.CompletionStage<T> executeCompletionStage(java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> supplier)
T - the type of results supplied by this suppliersupplier - the original CompletionStage