Class SemaphoreBulkhead
java.lang.Object
io.github.resilience4j.bulkhead.internal.SemaphoreBulkhead
- All Implemented Interfaces:
Bulkhead
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classprivate final classNested classes/interfaces inherited from interface Bulkhead
Bulkhead.BulkheadFuture<T>, Bulkhead.EventPublisher, Bulkhead.Metrics -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BulkheadConfigprivate static final Stringprivate final Objectprivate final SemaphoreBulkhead.BulkheadEventProcessorprivate final SemaphoreBulkhead.BulkheadMetricsprivate final Stringprivate final Semaphoreprivate static final String -
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.private voidpublishBulkheadEvent(Supplier<BulkheadEvent> eventSupplier) 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.(package private) booleanMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Bulkhead
executeCallable, executeCheckedSupplier, executeCompletionStage, executeRunnable, executeSupplier
-
Field Details
-
CONFIG_MUST_NOT_BE_NULL
- See Also:
-
TAGS_MUST_NOTE_BE_NULL
- See Also:
-
name
-
semaphore
-
metrics
-
eventProcessor
-
configChangesLock
-
tags
-
config
-
-
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
-
-
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
-
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
-
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
-
tryEnterBulkhead
boolean tryEnterBulkhead()- Returns:
- true if caller was able to wait for permission without
Thread.interrupt()
-
publishBulkheadEvent
-