public interface Bulkhead
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 isCallPermitted()
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 interface |
Bulkhead.EventPublisher
An EventPublisher which can be used to register event consumers.
|
static interface |
Bulkhead.Metrics |
Modifier and Type | Method and Description |
---|---|
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,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 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.
|
default <T> T |
executeCallable(java.util.concurrent.Callable<T> callable)
Decorates and executes the decorated Callable.
|
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 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.
|
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.
|
boolean |
isCallPermitted()
Attempts to acquire a permit, which allows an call to be executed.
|
static Bulkhead |
of(java.lang.String name,
BulkheadConfig config)
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 |
ofDefaults(java.lang.String name)
Create a Bulkhead with a default configuration.
|
void |
onComplete()
Records a completed call.
|
void changeConfig(BulkheadConfig newConfig)
newConfig
- new BulkheadConfigboolean isCallPermitted()
void onComplete()
java.lang.String getName()
BulkheadConfig getBulkheadConfig()
Bulkhead.Metrics getMetrics()
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> 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> 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 CompletionStagestatic <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 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.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, java.util.function.Supplier<BulkheadConfig> bulkheadConfigSupplier)
name
- the name of the bulkheadbulkheadConfigSupplier
- custom configuration supplier