Interface TimeLimiter

All Known Implementing Classes:
TimeLimiterImpl

public interface TimeLimiter
A TimeLimiter decorator stops execution after a configurable duration.
  • Field Details

  • Method Details

    • ofDefaults

      static TimeLimiter ofDefaults()
      Creates a TimeLimiter decorator with a default TimeLimiterConfig configuration.
      Returns:
      The TimeLimiter
    • ofDefaults

      static TimeLimiter ofDefaults(String name)
      Creates a TimeLimiter decorator with a default TimeLimiterConfig configuration.
      Returns:
      The TimeLimiter
    • of

      static TimeLimiter of(TimeLimiterConfig timeLimiterConfig)
      Creates a TimeLimiter decorator with a TimeLimiterConfig configuration.
      Parameters:
      timeLimiterConfig - the TimeLimiterConfig
      Returns:
      The TimeLimiter
    • of

      static TimeLimiter of(String name, TimeLimiterConfig timeLimiterConfig)
      Creates a TimeLimiter decorator with a TimeLimiterConfig configuration.
      Parameters:
      name - the name of the TimeLimiter
      timeLimiterConfig - the TimeLimiterConfig
      Returns:
      The TimeLimiter
    • of

      static TimeLimiter of(String name, TimeLimiterConfig timeLimiterConfig, Map<String,String> tags)
      Creates a TimeLimiter with a custom TimeLimiter configuration.

      The tags passed will be appended to the tags already configured for the registry. When tags (keys) of the two collide the tags passed with this method will override the tags of the registry.

      Parameters:
      name - the name of the TimeLimiter
      timeLimiterConfig - a custom TimeLimiter configuration
      tags - tags added to the Retry
      Returns:
      a TimeLimiter with a custom TimeLimiter configuration.
    • of

      static TimeLimiter of(Duration timeoutDuration)
      Creates a TimeLimiter decorator with a timeout Duration.
      Parameters:
      timeoutDuration - the timeout Duration
      Returns:
      The TimeLimiter
    • decorateFutureSupplier

      static <T, F extends Future<T>> Callable<T> decorateFutureSupplier(TimeLimiter timeLimiter, Supplier<F> futureSupplier)
      Creates a Callback that is restricted by a TimeLimiter.
      Type Parameters:
      T - the type of results supplied by the supplier
      F - the future type supplied
      Parameters:
      timeLimiter - the TimeLimiter
      futureSupplier - the original future supplier
      Returns:
      a future supplier which is restricted by a TimeLimiter.
    • decorateCompletionStage

      static <T, F extends CompletionStage<T>> Supplier<CompletionStage<T>> decorateCompletionStage(TimeLimiter timeLimiter, ScheduledExecutorService scheduler, Supplier<F> supplier)
      Decorate a CompletionStage supplier which is decorated by a TimeLimiter
      Type Parameters:
      T - the type of the returned CompletionStage's result
      F - the CompletionStage type supplied
      Parameters:
      timeLimiter - the TimeLimiter
      scheduler - execution service to use to schedule timeout
      supplier - the original CompletionStage supplier
      Returns:
      a CompletionStage supplier which is decorated by a TimeLimiter
    • getName

      String getName()
    • getTags

      Map<String,String> getTags()
      Returns an unmodifiable map with tags assigned to this TimeLimiter.
      Returns:
      the tags assigned to this TimeLimiter in an unmodifiable map
    • getTimeLimiterConfig

      TimeLimiterConfig getTimeLimiterConfig()
      Get the TimeLimiterConfig of this TimeLimiter decorator.
      Returns:
      the TimeLimiterConfig of this TimeLimiter decorator
    • executeFutureSupplier

      default <T, F extends Future<T>> T executeFutureSupplier(Supplier<F> futureSupplier) throws Exception
      Decorates and executes the Future Supplier.
      Type Parameters:
      T - the result type of the future
      F - the type of Future
      Parameters:
      futureSupplier - the original future supplier
      Returns:
      the result of the Future.
      Throws:
      Exception - if unable to compute a result
    • executeCompletionStage

      default <T, F extends CompletionStage<T>> CompletionStage<T> executeCompletionStage(ScheduledExecutorService scheduler, Supplier<F> supplier)
      Decorates and executes the CompletionStage Supplier
      Type Parameters:
      T - the type of the returned CompletionStage's result
      F - the CompletionStage type supplied
      Parameters:
      scheduler - execution service to use to schedule timeout
      supplier - the original CompletionStage supplier
      Returns:
      the decorated CompletionStage
    • decorateFutureSupplier

      <T, F extends Future<T>> Callable<T> decorateFutureSupplier(Supplier<F> futureSupplier)
      Creates a Callback that is restricted by a TimeLimiter.
      Type Parameters:
      T - the type of results supplied by the supplier
      F - the future type supplied
      Parameters:
      futureSupplier - the original future supplier
      Returns:
      a future supplier which is restricted by a TimeLimiter.
    • decorateCompletionStage

      <T, F extends CompletionStage<T>> Supplier<CompletionStage<T>> decorateCompletionStage(ScheduledExecutorService scheduler, Supplier<F> supplier)
      Decorate a CompletionStage supplier which is decorated by a TimeLimiter
      Type Parameters:
      T - the type of the returned CompletionStage's result
      F - the CompletionStage type supplied
      Parameters:
      scheduler - execution service to use to schedule timeout
      supplier - the original CompletionStage supplier
      Returns:
      a CompletionStage supplier which is decorated by a TimeLimiter
    • getEventPublisher

      TimeLimiter.EventPublisher getEventPublisher()
      Returns an EventPublisher which can be used to register event consumers.
      Returns:
      an EventPublisher
    • onSuccess

      void onSuccess()
      Records a successful call.

      This method must be invoked when a call was successful.

    • onError

      void onError(Throwable throwable)
      Records a failed call. This method must be invoked when a call failed.
      Parameters:
      throwable - The throwable which must be recorded
    • createdTimeoutExceptionWithName

      static TimeoutException createdTimeoutExceptionWithName(String name, @Nullable Throwable t)