Class BulkheadImpl<R>

java.lang.Object
dev.failsafe.internal.BulkheadImpl<R>
Type Parameters:
R - result type
All Implemented Interfaces:
Bulkhead<R>, Policy<R>

public class BulkheadImpl<R> extends Object implements Bulkhead<R>
A Bulkhead implementation that supports sync and async waiting.
  • Field Details

  • Constructor Details

  • Method Details

    • getConfig

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

      public void acquirePermit() throws InterruptedException
      Description copied from interface: Bulkhead
      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.
      Specified by:
      acquirePermit in interface Bulkhead<R>
      Throws:
      InterruptedException - if the current thread is interrupted while waiting to acquire a permit
      See Also:
    • tryAcquirePermit

      public boolean tryAcquirePermit()
      Description copied from interface: Bulkhead
      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.
      Specified by:
      tryAcquirePermit in interface Bulkhead<R>
      Returns:
      whether the requested permits are successfully acquired or not
    • tryAcquirePermit

      public boolean tryAcquirePermit(Duration maxWaitTime) throws InterruptedException
      Description copied from interface: Bulkhead
      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.
      Specified by:
      tryAcquirePermit in interface Bulkhead<R>
      Returns:
      whether a permit is successfully acquired
      Throws:
      InterruptedException - if the current thread is interrupted while waiting to acquire a permit
    • acquirePermitAsync

      CompletableFuture<Void> acquirePermitAsync()
      Returns a CompletableFuture that is completed when a permit is acquired. Externally completing this future will remove the waiter from the bulkhead's internal queue.
    • releasePermit

      public void releasePermit()
      Description copied from interface: Bulkhead
      Releases a permit to execute.
      Specified by:
      releasePermit in interface Bulkhead<R>
    • toExecutor

      public PolicyExecutor<R> toExecutor(int policyIndex)
      Description copied from interface: Policy
      Returns a PolicyExecutor capable of handling an execution for the Policy.
      Specified by:
      toExecutor in interface Policy<R>