Class SemaphoreBulkhead
java.lang.Object
io.github.resilience4j.bulkhead.internal.SemaphoreBulkhead
- All Implemented Interfaces:
Bulkhead
public class SemaphoreBulkhead extends java.lang.Object implements Bulkhead
A Bulkhead implementation based on a semaphore.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.github.resilience4j.bulkhead.Bulkhead
Bulkhead.BulkheadFuture<T>, Bulkhead.EventPublisher, Bulkhead.Metrics
-
Constructor Summary
Constructors Constructor Description SemaphoreBulkhead(java.lang.String name)
Creates a bulkhead with a default config.SemaphoreBulkhead(java.lang.String name, BulkheadConfig bulkheadConfig)
Creates a bulkhead using a configuration suppliedSemaphoreBulkhead(java.lang.String name, BulkheadConfig bulkheadConfig, io.vavr.collection.Map<java.lang.String,java.lang.String> tags)
Creates a bulkhead using a configuration suppliedSemaphoreBulkhead(java.lang.String name, java.util.function.Supplier<BulkheadConfig> configSupplier)
Create a bulkhead using a configuration supplierSemaphoreBulkhead(java.lang.String name, java.util.function.Supplier<BulkheadConfig> configSupplier, io.vavr.collection.Map<java.lang.String,java.lang.String> tags)
Create a bulkhead using a configuration supplier -
Method Summary
Modifier and Type Method 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.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.void
onComplete()
Records a completed call and releases a permission.void
releasePermission()
Releases a permission and increases the number of available permits by one.java.lang.String
toString()
boolean
tryAcquirePermission()
Acquires a permission to execute a call, only if one is available at the time of invocation.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.github.resilience4j.bulkhead.Bulkhead
executeCallable, executeCheckedSupplier, executeCompletionStage, executeEitherSupplier, executeRunnable, executeSupplier, executeTrySupplier
-
Constructor Details
-
SemaphoreBulkhead
Creates a bulkhead using a configuration supplied- Parameters:
name
- the name of this bulkheadbulkheadConfig
- custom bulkhead configuration
-
SemaphoreBulkhead
public SemaphoreBulkhead(java.lang.String name, @Nullable BulkheadConfig bulkheadConfig, io.vavr.collection.Map<java.lang.String,java.lang.String> tags)Creates a bulkhead using a configuration supplied- Parameters:
name
- the name of this bulkheadbulkheadConfig
- custom bulkhead configurationtags
- the tags to add to the Bulkhead
-
SemaphoreBulkhead
public SemaphoreBulkhead(java.lang.String name)Creates a bulkhead with a default config.- Parameters:
name
- the name of this bulkhead
-
SemaphoreBulkhead
public SemaphoreBulkhead(java.lang.String name, java.util.function.Supplier<BulkheadConfig> configSupplier)Create a bulkhead using a configuration supplier- Parameters:
name
- the name of this bulkheadconfigSupplier
- BulkheadConfig supplier
-
SemaphoreBulkhead
public SemaphoreBulkhead(java.lang.String name, java.util.function.Supplier<BulkheadConfig> configSupplier, io.vavr.collection.Map<java.lang.String,java.lang.String> tags)Create a bulkhead using a configuration supplier- Parameters:
name
- the name of this bulkheadconfigSupplier
- BulkheadConfig suppliertags
- tags to add to the Bulkhead
-
-
Method Details
-
changeConfig
Dynamic bulkhead configuration change. NOTE! New `maxWaitTime` duration won't affect threads that are currently waiting for permission.- Specified by:
changeConfig
in interfaceBulkhead
- Parameters:
newConfig
- new BulkheadConfig
-
tryAcquirePermission
public boolean tryAcquirePermission()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.- Specified by:
tryAcquirePermission
in interfaceBulkhead
- Returns:
true
if a permission was acquired andfalse
otherwise
-
acquirePermission
public 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.- Specified by:
acquirePermission
in interfaceBulkhead
-
releasePermission
public void releasePermission()Releases a permission and increases the number of available permits by one.Should only be used when a permission was acquired but not used. Otherwise use
Bulkhead.onComplete()
to signal a completed call and release a permission.- Specified by:
releasePermission
in interfaceBulkhead
-
onComplete
public void onComplete()Records a completed call and releases a permission.- Specified by:
onComplete
in interfaceBulkhead
-
getName
public java.lang.String getName()Returns the name of this bulkhead. -
getBulkheadConfig
Returns the BulkheadConfig of this Bulkhead.- Specified by:
getBulkheadConfig
in interfaceBulkhead
- Returns:
- bulkhead config
-
getMetrics
Get the Metrics of this Bulkhead.- Specified by:
getMetrics
in interfaceBulkhead
- Returns:
- the Metrics of this Bulkhead
-
getTags
public io.vavr.collection.Map<java.lang.String,java.lang.String> getTags()Returns an unmodifiable map with tags assigned to this Bulkhead. -
getEventPublisher
Returns an EventPublisher which subscribes to the reactive stream of BulkheadEvent and can be used to register event consumers.- Specified by:
getEventPublisher
in interfaceBulkhead
- Returns:
- an EventPublisher
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-