Package dev.failsafe.internal
Class BulkheadImpl<R>
- java.lang.Object
-
- dev.failsafe.internal.BulkheadImpl<R>
-
-
Field Summary
Fields Modifier and Type Field Description private BulkheadConfig<R>configprivate FutureLinkedListfuturesprivate intmaxPermitsprivate static java.util.concurrent.CompletableFuture<java.lang.Void>NULL_FUTUREprivate intpermits
-
Constructor Summary
Constructors Constructor Description BulkheadImpl(BulkheadConfig<R> config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidacquirePermit()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 theBulkheadConfigthat the Bulkhead was built with.voidreleasePermit()Releases a permit to execute.PolicyExecutor<R>toExecutor(int policyIndex)Returns aPolicyExecutorcapable of handling an execution for the Policy.booleantryAcquirePermit()Tries to acquire a permit to perform an execution within the bulkhead, returning immediately without waiting.booleantryAcquirePermit(java.time.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, wait
-
Methods inherited from interface dev.failsafe.Bulkhead
acquirePermit
-
-
-
-
Field Detail
-
NULL_FUTURE
private static final java.util.concurrent.CompletableFuture<java.lang.Void> NULL_FUTURE
-
config
private final BulkheadConfig<R> config
-
maxPermits
private final int maxPermits
-
permits
private int permits
-
futures
private final FutureLinkedList futures
-
-
Constructor Detail
-
BulkheadImpl
public BulkheadImpl(BulkheadConfig<R> config)
-
-
Method Detail
-
getConfig
public BulkheadConfig<R> getConfig()
Description copied from interface:BulkheadReturns theBulkheadConfigthat the Bulkhead was built with.
-
acquirePermit
public void acquirePermit() throws java.lang.InterruptedExceptionDescription 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:
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: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
public boolean tryAcquirePermit(java.time.Duration maxWaitTime) throws java.lang.InterruptedExceptionDescription 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:
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:BulkheadReleases a permit to execute.- Specified by:
releasePermitin interfaceBulkhead<R>
-
toExecutor
public PolicyExecutor<R> toExecutor(int policyIndex)
Description copied from interface:PolicyReturns aPolicyExecutorcapable of handling an execution for the Policy.- Specified by:
toExecutorin interfacePolicy<R>
-
-