Interface Decorators


  • public interface Decorators
    A Decorator builder which can be used to apply multiple decorators to a Supplier, Callable Function, Runnable, CompletionStage or Consumer.

    Decorators are applied in the order of the builder chain. For example, consider:
    
     Supplier<String> supplier = Decorators
         .ofSupplier(() -> service.method())
         .withCircuitBreaker(CircuitBreaker.ofDefaults("id"))
         .withRetry(Retry.ofDefaults("id"))
         .withFallback(CallNotPermittedException.class, e -> service.fallbackMethod())
         .decorate();
     
    This results in the following composition when executing the supplier:
    Fallback(Retry(CircuitBreaker(Supplier)))
    This means the Supplier is called first, then its result is handled by the CircuitBreaker, then Retry and then Fallback. Each Decorator makes its own determination whether an exception represents a failure.