Class Bulkhead<T>
java.lang.Object
io.github.teceli.resiliencia.patterns.bulkhead.Bulkhead<T>
- All Implemented Interfaces:
Resilient<T>
Bulkhead pattern: bound how many calls may execute concurrently, isolating the protected
resource from overload. Built on a
Semaphore — callers over the limit either fail
fast with BulkheadFullException (default, maxWait zero) or block for up to
maxWait until a permit frees up; blocking a virtual thread is cheap.
Holds live state (the permits). Immutable in configuration and thread-safe by design — share
one instance across all callers that must compete for the same permits. Each withX
method returns a new, independent Bulkhead with a fresh, unused set of permits.-
Nested Class Summary
Nested classes/interfaces inherited from interface io.github.teceli.resiliencia.core.api.Resilient
Resilient.Operation<T> -
Method Summary
Modifier and TypeMethodDescriptioncall(Resilient.Operation<T> operation) Execute an operation with resilience guarantees.intThe configured maximum number of concurrent calls.maxWait()How long an excess call may wait for a permit before being rejected.name()The name identifying this bulkhead instance, used in events and rejection exceptions.static <T> Bulkhead<T> ABulkheadallowing the given number of concurrent calls, rejecting excess calls immediately (maxWaitzero).outcome(Resilient.Operation<T> operation) Execute an operation and capture the result or failure as an Outcome.The kind of this pattern, used for internal comparisons (e.g.The name of this pattern, e.g.Use a customClockinstead of the system clock for event timestamps.withListener(ResilienceEvent.Listener listener) Add a listener notified of everyBulkheadEventemitted by this instance.withMaxConcurrentCalls(int maxConcurrentCalls) Maximum number of calls allowed to execute concurrently.withMaxWait(Duration maxWait) How long an excess call may wait for a permit before being rejected.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.github.teceli.resiliencia.core.api.Resilient
callAsync, hasOwnDeadline
-
Method Details
-
of
ABulkheadallowing the given number of concurrent calls, rejecting excess calls immediately (maxWaitzero). Refine viawithXmethods, e.g.withMaxWait(java.time.Duration)to let excess calls wait for a permit instead. -
withMaxConcurrentCalls
Maximum number of calls allowed to execute concurrently. Must be at least 1. -
withMaxWait
How long an excess call may wait for a permit before being rejected. Zero (the default) rejects immediately. -
withListener
Add a listener notified of everyBulkheadEventemitted by this instance. Listener exceptions are logged and otherwise ignored — a broken listener never affects the outcome. -
withClock
Use a customClockinstead of the system clock for event timestamps. The permit wait is enforced against real elapsed time. -
name
The name identifying this bulkhead instance, used in events and rejection exceptions. -
maxConcurrentCalls
public int maxConcurrentCalls()The configured maximum number of concurrent calls. -
maxWait
How long an excess call may wait for a permit before being rejected. -
patternName
Description copied from interface:ResilientThe name of this pattern, e.g. "retry", "timeout", "circuit-breaker". Used for identification (e.g. by Policy) without coupling to concrete pattern types. Defaults to "custom" for user-defined Resilient implementations.- Specified by:
patternNamein interfaceResilient<T>
-
patternKind
Description copied from interface:ResilientThe kind of this pattern, used for internal comparisons (e.g. Policy order validation). UnlikeResilient.patternName(), which is a free-form observability label, this is a closed enum the library can reason about exhaustively. Defaults toPatternKind.CUSTOMfor user-defined Resilient implementations.- Specified by:
patternKindin interfaceResilient<T>
-
call
Description copied from interface:ResilientExecute an operation with resilience guarantees. May throw ResilienciaException or a specific pattern exception.- Specified by:
callin interfaceResilient<T>- Throws:
ResilientException
-
outcome
Description copied from interface:ResilientExecute an operation and capture the result or failure as an Outcome. Never throws for a recordedException— always returns Success, Failure, or a pattern-specific outcome. AnErrorthrown by the operation propagates uncaught instead of being captured as a Failure: fatal JVM conditions (e.g.OutOfMemoryError) should not be treated as a recoverable result.
-