Interface Resilient<T>
- All Known Implementing Classes:
Bulkhead,CircuitBreaker,FakeResilient,Policy,RateLimiter,Retry,Timeout
public interface Resilient<T>
Base interface for all resilience patterns.
Patterns implement this to provide call execution with resilience guarantees.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptioncall(Resilient.Operation<T> operation) Execute an operation with resilience guarantees.default CompletableFuture<T> callAsync(Resilient.Operation<T> operation) Execute an operation asynchronously on a new virtual thread and return a handle to its result.default booleanWhether this pattern already enforces its own upper bound on total duration, independent of any outer Timeout.outcome(Resilient.Operation<T> operation) Execute an operation and capture the result or failure as an Outcome.default PatternKindThe kind of this pattern, used for internal comparisons (e.g.default StringThe name of this pattern, e.g.
-
Method Details
-
call
Execute an operation with resilience guarantees. May throw ResilienciaException or a specific pattern exception.- Throws:
ResilientException
-
outcome
Execute 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. -
callAsync
Execute an operation asynchronously on a new virtual thread and return a handle to its result. The future completes with the value ofcall(io.github.teceli.resiliencia.core.api.Resilient.Operation<T>), or exceptionally with whatevercall(io.github.teceli.resiliencia.core.api.Resilient.Operation<T>)throws. Ifcall(io.github.teceli.resiliencia.core.api.Resilient.Operation<T>)lets anErrorpropagate, the future is still completed exceptionally with it (so a waiter on the future is not left hanging), but theErroris also rethrown on the worker thread afterward — it is never treated as a recoverable business outcome (see "Error handling" indocs/architecture/ARCHITECTURE.md). Cancelling the returned future interrupts the virtual thread, so cancellation propagates through whichever pattern is currently blocking — a Timeout wait, a Retry backoff, a Bulkhead or RateLimiter permit wait — including across a full Policy chain. -
patternName
The 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. -
patternKind
The kind of this pattern, used for internal comparisons (e.g. Policy order validation). UnlikepatternName(), 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. -
hasOwnDeadline
default boolean hasOwnDeadline()Whether this pattern already enforces its own upper bound on total duration, independent of any outer Timeout. Used by Policy to decide whether a Timeout-wraps-Retry ordering warning still applies. Defaults to false for user-defined Resilient implementations.
-