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>
config
private FutureLinkedList
futures
private int
maxPermits
private static java.util.concurrent.CompletableFuture<java.lang.Void>
NULL_FUTURE
private int
permits
-
Constructor Summary
Constructors Constructor Description BulkheadImpl(BulkheadConfig<R> config)
-
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 theBulkheadConfig
that the Bulkhead was built with.void
releasePermit()
Releases a permit to execute.PolicyExecutor<R>
toExecutor(int policyIndex)
Returns aPolicyExecutor
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 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 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:Bulkhead
Returns theBulkheadConfig
that the Bulkhead was built with.
-
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 bereleased
back to the bulkhead.- Specified by:
acquirePermit
in 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: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
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 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:
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 interfaceBulkhead<R>
-
toExecutor
public PolicyExecutor<R> toExecutor(int policyIndex)
Description copied from interface:Policy
Returns aPolicyExecutor
capable of handling an execution for the Policy.- Specified by:
toExecutor
in interfacePolicy<R>
-
-