Class SemaphoreBulkhead
java.lang.Object
io.github.resilience4j.bulkhead.internal.SemaphoreBulkhead
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionSemaphoreBulkhead(String name) Creates a bulkhead with a default config.SemaphoreBulkhead(String name, BulkheadConfig bulkheadConfig) Creates a bulkhead using a configuration suppliedSemaphoreBulkhead(String name, BulkheadConfig bulkheadConfig, Map<String, String> tags) Creates a bulkhead using a configuration suppliedSemaphoreBulkhead(String name, Supplier<BulkheadConfig> configSupplier) Create a bulkhead using a configuration supplierSemaphoreBulkhead(String name, Supplier<BulkheadConfig> configSupplier, Map<String, String> tags) Create a bulkhead using a configuration supplier -
Method Summary
Modifier and TypeMethodDescriptionvoidAcquires 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.voidchangeConfig(BulkheadConfig newConfig) Dynamic bulkhead configuration change.Returns the BulkheadConfig of this Bulkhead.Returns an EventPublisher which subscribes to the reactive stream of BulkheadEvent and can be used to register event consumers.Get the Metrics of this Bulkhead.getName()Returns the name of this bulkhead.getTags()Returns an unmodifiable map with tags assigned to this Bulkhead.voidRecords a completed call and releases a permission.voidReleases a permission and increases the number of available permits by one.toString()booleanAcquires 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, waitMethods inherited from interface io.github.resilience4j.bulkhead.Bulkhead
executeCallable, executeCheckedSupplier, executeCompletionStage, executeRunnable, executeSupplier
-
Constructor Details
-
SemaphoreBulkhead
Creates a bulkhead using a configuration supplied- Parameters:
name- the name of this bulkheadbulkheadConfig- custom bulkhead configuration
-
SemaphoreBulkhead
public SemaphoreBulkhead(String name, @Nullable BulkheadConfig bulkheadConfig, Map<String, 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
Creates a bulkhead with a default config.- Parameters:
name- the name of this bulkhead
-
SemaphoreBulkhead
Create a bulkhead using a configuration supplier- Parameters:
name- the name of this bulkheadconfigSupplier- BulkheadConfig supplier
-
SemaphoreBulkhead
public SemaphoreBulkhead(String name, Supplier<BulkheadConfig> configSupplier, Map<String, 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:
changeConfigin 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:
tryAcquirePermissionin interfaceBulkhead- Returns:
trueif a permission was acquired andfalseotherwise
-
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:
acquirePermissionin 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:
releasePermissionin interfaceBulkhead
-
onComplete
public void onComplete()Records a completed call and releases a permission.- Specified by:
onCompletein interfaceBulkhead
-
getName
Returns the name of this bulkhead. -
getBulkheadConfig
Returns the BulkheadConfig of this Bulkhead.- Specified by:
getBulkheadConfigin interfaceBulkhead- Returns:
- bulkhead config
-
getMetrics
Get the Metrics of this Bulkhead.- Specified by:
getMetricsin interfaceBulkhead- Returns:
- the Metrics of this Bulkhead
-
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:
getEventPublisherin interfaceBulkhead- Returns:
- an EventPublisher
-
toString
-