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 FutureLinkedListprivate final intprivate static final CompletableFuture<Void> private int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAttempts 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 theBulkheadConfigthat the Bulkhead was built with.voidReleases a permit to execute.toExecutor(int policyIndex) Returns aPolicyExecutorcapable of handling an execution for the Policy.booleanTries to acquire a permit to perform an execution within the bulkhead, returning immediately without waiting.booleantryAcquirePermit(Duration maxWaitTime) Tries to acquire a permit to perform an execution within the bulkhead, waiting up to themaxWaitTimeuntil they are available.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:BulkheadReturns theBulkheadConfigthat the Bulkhead was built with. -
acquirePermit
Description copied from interface:BulkheadAttempts 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 bereleasedback to the bulkhead.- Specified by:
acquirePermitin 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:BulkheadTries to acquire a permit to perform an execution within the bulkhead, returning immediately without waiting. After execution is complete, the permit should bereleasedback to the bulkhead.- Specified by:
tryAcquirePermitin interfaceBulkhead<R>- Returns:
- whether the requested
permitsare successfully acquired or not
-
tryAcquirePermit
Description copied from interface:BulkheadTries to acquire a permit to perform an execution within the bulkhead, waiting up to themaxWaitTimeuntil they are available. After execution is complete, the permit should bereleasedback to the bulkhead.- Specified by:
tryAcquirePermitin 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:BulkheadReleases a permit to execute.- Specified by:
releasePermitin interfaceBulkhead<R>
-
toExecutor
Description copied from interface:PolicyReturns aPolicyExecutorcapable of handling an execution for the Policy.- Specified by:
toExecutorin interfacePolicy<R>
-