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.
  • Constructor Details

    • SemaphoreBulkhead

      public SemaphoreBulkhead​(java.lang.String name, @Nullable BulkheadConfig bulkheadConfig)
      Creates a bulkhead using a configuration supplied
      Parameters:
      name - the name of this bulkhead
      bulkheadConfig - 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 bulkhead
      bulkheadConfig - custom bulkhead configuration
      tags - 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 bulkhead
      configSupplier - 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 bulkhead
      configSupplier - BulkheadConfig supplier
      tags - tags to add to the Bulkhead
  • Method Details

    • changeConfig

      public void changeConfig​(BulkheadConfig newConfig)
      Dynamic bulkhead configuration change. NOTE! New `maxWaitTime` duration won't affect threads that are currently waiting for permission.
      Specified by:
      changeConfig in interface Bulkhead
      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 interface Bulkhead
      Returns:
      true if a permission was acquired and false 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 interface Bulkhead
    • 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 interface Bulkhead
    • onComplete

      public void onComplete()
      Records a completed call and releases a permission.
      Specified by:
      onComplete in interface Bulkhead
    • getName

      public java.lang.String getName()
      Returns the name of this bulkhead.
      Specified by:
      getName in interface Bulkhead
      Returns:
      the name of this bulkhead
    • getBulkheadConfig

      public BulkheadConfig getBulkheadConfig()
      Returns the BulkheadConfig of this Bulkhead.
      Specified by:
      getBulkheadConfig in interface Bulkhead
      Returns:
      bulkhead config
    • getMetrics

      public Bulkhead.Metrics getMetrics()
      Get the Metrics of this Bulkhead.
      Specified by:
      getMetrics in interface Bulkhead
      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.
      Specified by:
      getTags in interface Bulkhead
      Returns:
      the tags assigned to this Retry in an unmodifiable map
    • getEventPublisher

      public Bulkhead.EventPublisher getEventPublisher()
      Returns an EventPublisher which subscribes to the reactive stream of BulkheadEvent and can be used to register event consumers.
      Specified by:
      getEventPublisher in interface Bulkhead
      Returns:
      an EventPublisher
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object