Package dev.failsafe.internal
Class BulkheadImpl<R>
java.lang.Object
dev.failsafe.internal.BulkheadImpl<R>
- Type Parameters:
R
- result type
A Bulkhead implementation that supports sync and async waiting.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BulkheadConfig
<R> private final FutureLinkedList
private final int
private static final CompletableFuture
<Void> private int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
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) CompletableFuture
<Void> Returns a CompletableFuture that is completed when a permit is acquired.Returns theBulkheadConfig
that the Bulkhead was built with.void
Releases a permit to execute.toExecutor
(int policyIndex) Returns aPolicyExecutor
capable of handling an execution for the Policy.boolean
Tries to acquire a permit to perform an execution within the bulkhead, returning immediately without waiting.boolean
tryAcquirePermit
(Duration maxWaitTime) Tries to acquire a permit to perform an execution within the bulkhead, waiting up to themaxWaitTime
until they are available.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface dev.failsafe.Bulkhead
acquirePermit
-
Field Details
-
NULL_FUTURE
-
config
-
maxPermits
private final int maxPermits -
permits
private int permits -
futures
-
-
Constructor Details
-
BulkheadImpl
-
-
Method Details
-
getConfig
Description copied from interface:Bulkhead
Returns theBulkheadConfig
that the Bulkhead was built with. -
acquirePermit
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 bereleased
back to the bulkhead.- Specified by:
acquirePermit
in interfaceBulkhead<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 bereleased
back to the bulkhead.- Specified by:
tryAcquirePermit
in interfaceBulkhead<R>
- Returns:
- whether the requested
permits
are successfully acquired or not
-
tryAcquirePermit
Description copied from interface:Bulkhead
Tries to acquire a permit to perform an execution within the bulkhead, waiting up to themaxWaitTime
until they are available. After execution is complete, the permit should bereleased
back to the bulkhead.- Specified by:
tryAcquirePermit
in interfaceBulkhead<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 interfaceBulkhead<R>
-
toExecutor
Description copied from interface:Policy
Returns aPolicyExecutor
capable of handling an execution for the Policy.- Specified by:
toExecutor
in interfacePolicy<R>
-