Class BulkheadImpl<R>

  • Type Parameters:
    R - result type
    All Implemented Interfaces:
    Bulkhead<R>, Policy<R>

    public class BulkheadImpl<R>
    extends java.lang.Object
    implements Bulkhead<R>
    A Bulkhead implementation that supports sync and async waiting.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void acquirePermit()
      Attempts to acquire a permit to perform an execution against within the bulkhead, waiting until one is available or the thread is interrupted.
      (package private) java.util.concurrent.CompletableFuture<java.lang.Void> acquirePermitAsync()
      Returns a CompletableFuture that is completed when a permit is acquired.
      BulkheadConfig<R> getConfig()
      Returns the BulkheadConfig that the Bulkhead was built with.
      void releasePermit()
      Releases a permit to execute.
      PolicyExecutor<R> toExecutor​(int policyIndex)
      Returns a PolicyExecutor capable of handling an execution for the Policy.
      boolean tryAcquirePermit()
      Tries to acquire a permit to perform an execution within the bulkhead, returning immediately without waiting.
      boolean tryAcquirePermit​(java.time.Duration maxWaitTime)
      Tries to acquire a permit to perform an execution within the bulkhead, waiting up to the maxWaitTime until they are available.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NULL_FUTURE

        private static final java.util.concurrent.CompletableFuture<java.lang.Void> NULL_FUTURE
      • maxPermits

        private final int maxPermits
      • permits

        private int permits
    • Method Detail

      • acquirePermit

        public void acquirePermit()
                           throws java.lang.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:
        java.lang.InterruptedException - if the current thread is interrupted while waiting to acquire a permit
        See Also:
        Bulkhead.tryAcquirePermit()
      • 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​(java.time.Duration maxWaitTime)
                                 throws java.lang.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:
        java.lang.InterruptedException - if the current thread is interrupted while waiting to acquire a permit
      • acquirePermitAsync

        java.util.concurrent.CompletableFuture<java.lang.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>