Package dev.failsafe

Interface Bulkhead<R>

Type Parameters:
R - result type
All Superinterfaces:
Policy<R>
All Known Implementing Classes:
BulkheadImpl

public interface Bulkhead<R> extends Policy<R>
A bulkhead allows you to restrict concurrent executions as a way of preventing system overload.

This class is threadsafe.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Attempts to acquire a permit to perform an execution against within the bulkhead, waiting until one is available or the thread is interrupted.
    default void
    acquirePermit(Duration maxWaitTime)
    Attempts to acquire a permit to perform an execution within the bulkhead, waiting up to the maxWaitTime until one is available, else throwing BulkheadFullException if a permit will not be available in time.
    static <R> BulkheadBuilder<R>
    builder(int maxConcurrency)
    Returns a Bulkhead for the maxConcurrency that has zero wait.
    static <R> BulkheadBuilder<R>
    Creates a new BulkheadBuilder that will be based on the config.
    Returns the BulkheadConfig that the Bulkhead was built with.
    static <R> Bulkhead<R>
    of(int maxConcurrency)
    Returns a Bulkhead for the maxConcurrency that has zero wait.
    void
    Releases a permit to execute.
    boolean
    Tries to acquire a permit to perform an execution within the bulkhead, returning immediately without waiting.
    boolean
    Tries to acquire a permit to perform an execution within the bulkhead, waiting up to the maxWaitTime until they are available.

    Methods inherited from interface dev.failsafe.Policy

    toExecutor
  • Method Details

    • builder

      static <R> BulkheadBuilder<R> builder(int maxConcurrency)
      Returns a Bulkhead for the maxConcurrency that has zero wait.
      Parameters:
      maxConcurrency - controls the max concurrent executions that are permitted within the bulkhead
    • builder

      static <R> BulkheadBuilder<R> builder(BulkheadConfig<R> config)
      Creates a new BulkheadBuilder that will be based on the config.
    • of

      static <R> Bulkhead<R> of(int maxConcurrency)
      Returns a Bulkhead for the maxConcurrency that has zero wait. Alias for Bulkhead.builder(maxConcurrency).build(). To configure additional options on a Bulkhead, use builder(int) instead.
      Parameters:
      maxConcurrency - controls the max concurrent executions that are permitted within the bulkhead
      See Also:
    • getConfig

      BulkheadConfig<R> getConfig()
      Returns the BulkheadConfig that the Bulkhead was built with.
      Specified by:
      getConfig in interface Policy<R>
    • acquirePermit

      void acquirePermit() throws InterruptedException
      Attempts to acquire a permit to perform an execution against within the bulkhead, waiting until one is available or the thread is interrupted. After execution is complete, the permit should be released back to the bulkhead.
      Throws:
      InterruptedException - if the current thread is interrupted while waiting to acquire a permit
      See Also:
    • acquirePermit

      default void acquirePermit(Duration maxWaitTime) throws InterruptedException
      Attempts to acquire a permit to perform an execution within the bulkhead, waiting up to the maxWaitTime until one is available, else throwing BulkheadFullException if a permit will not be available in time. After execution is complete, the permit should be released back to the bulkhead.
      Throws:
      NullPointerException - if maxWaitTime is null
      BulkheadFullException - if the bulkhead cannot acquire a permit within the maxWaitTime
      InterruptedException - if the current thread is interrupted while waiting to acquire a permit
      See Also:
    • tryAcquirePermit

      boolean tryAcquirePermit()
      Tries to acquire a permit to perform an execution within the bulkhead, returning immediately without waiting. After execution is complete, the permit should be released back to the bulkhead.
      Returns:
      whether the requested permits are successfully acquired or not
    • tryAcquirePermit

      boolean tryAcquirePermit(Duration maxWaitTime) throws InterruptedException
      Tries to acquire a permit to perform an execution within the bulkhead, waiting up to the maxWaitTime until they are available. After execution is complete, the permit should be released back to the bulkhead.
      Returns:
      whether a permit is successfully acquired
      Throws:
      NullPointerException - if maxWaitTime is null
      InterruptedException - if the current thread is interrupted while waiting to acquire a permit
    • releasePermit

      void releasePermit()
      Releases a permit to execute.