Package dev.failsafe

Interface Bulkhead<R>

    • Method Detail

      • 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
      • 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:
        builder(int)
      • acquirePermit

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

        default void acquirePermit​(java.time.Duration maxWaitTime)
                            throws java.lang.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:
        java.lang.NullPointerException - if maxWaitTime is null
        BulkheadFullException - if the bulkhead cannot acquire a permit within the maxWaitTime
        java.lang.InterruptedException - if the current thread is interrupted while waiting to acquire a permit
        See Also:
        tryAcquirePermit(Duration)
      • 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​(java.time.Duration maxWaitTime)
                          throws java.lang.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:
        java.lang.NullPointerException - if maxWaitTime is null
        java.lang.InterruptedException - if the current thread is interrupted while waiting to acquire a permit
      • releasePermit

        void releasePermit()
        Releases a permit to execute.