Interface TimeLimiter

  • All Known Implementing Classes:
    TimeLimiterImpl

    public interface TimeLimiter
    A TimeLimiter decorator stops execution after a configurable duration.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  TimeLimiter.EventPublisher
      An EventPublisher which can be used to register event consumers.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEFAULT_NAME  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      static java.util.concurrent.TimeoutException createdTimeoutExceptionWithName​(java.lang.String name, java.lang.Throwable t)  
      static <T,​F extends java.util.concurrent.CompletionStage<T>>
      java.util.function.Supplier<java.util.concurrent.CompletionStage<T>>
      decorateCompletionStage​(TimeLimiter timeLimiter, java.util.concurrent.ScheduledExecutorService scheduler, java.util.function.Supplier<F> supplier)
      Decorate a CompletionStage supplier which is decorated by a TimeLimiter
      <T,​F extends java.util.concurrent.CompletionStage<T>>
      java.util.function.Supplier<java.util.concurrent.CompletionStage<T>>
      decorateCompletionStage​(java.util.concurrent.ScheduledExecutorService scheduler, java.util.function.Supplier<F> supplier)
      Decorate a CompletionStage supplier which is decorated by a TimeLimiter
      static <T,​F extends java.util.concurrent.Future<T>>
      java.util.concurrent.Callable<T>
      decorateFutureSupplier​(TimeLimiter timeLimiter, java.util.function.Supplier<F> futureSupplier)
      Creates a Callback that is restricted by a TimeLimiter.
      <T,​F extends java.util.concurrent.Future<T>>
      java.util.concurrent.Callable<T>
      decorateFutureSupplier​(java.util.function.Supplier<F> futureSupplier)
      Creates a Callback that is restricted by a TimeLimiter.
      default <T,​F extends java.util.concurrent.CompletionStage<T>>
      java.util.concurrent.CompletionStage<T>
      executeCompletionStage​(java.util.concurrent.ScheduledExecutorService scheduler, java.util.function.Supplier<F> supplier)
      Decorates and executes the CompletionStage Supplier
      default <T,​F extends java.util.concurrent.Future<T>>
      T
      executeFutureSupplier​(java.util.function.Supplier<F> futureSupplier)
      Decorates and executes the Future Supplier.
      TimeLimiter.EventPublisher getEventPublisher()
      Returns an EventPublisher which can be used to register event consumers.
      java.lang.String getName()  
      io.vavr.collection.Map<java.lang.String,​java.lang.String> getTags()
      Returns an unmodifiable map with tags assigned to this TimeLimiter.
      TimeLimiterConfig getTimeLimiterConfig()
      Get the TimeLimiterConfig of this TimeLimiter decorator.
      static TimeLimiter of​(TimeLimiterConfig timeLimiterConfig)
      Creates a TimeLimiter decorator with a TimeLimiterConfig configuration.
      static TimeLimiter of​(java.lang.String name, TimeLimiterConfig timeLimiterConfig)
      Creates a TimeLimiter decorator with a TimeLimiterConfig configuration.
      static TimeLimiter of​(java.lang.String name, TimeLimiterConfig timeLimiterConfig, io.vavr.collection.Map<java.lang.String,​java.lang.String> tags)
      Creates a TimeLimiter with a custom TimeLimiter configuration.
      static TimeLimiter of​(java.time.Duration timeoutDuration)
      Creates a TimeLimiter decorator with a timeout Duration.
      static TimeLimiter ofDefaults()
      Creates a TimeLimiter decorator with a default TimeLimiterConfig configuration.
      static TimeLimiter ofDefaults​(java.lang.String name)
      Creates a TimeLimiter decorator with a default TimeLimiterConfig configuration.
      void onError​(java.lang.Throwable throwable)
      Records a failed call.
      void onSuccess()
      Records a successful call.
    • Method Detail

      • ofDefaults

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

        static TimeLimiter ofDefaults​(java.lang.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​(java.lang.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​(java.lang.String name,
                              TimeLimiterConfig timeLimiterConfig,
                              io.vavr.collection.Map<java.lang.String,​java.lang.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​(java.time.Duration timeoutDuration)
        Creates a TimeLimiter decorator with a timeout Duration.
        Parameters:
        timeoutDuration - the timeout Duration
        Returns:
        The TimeLimiter
      • decorateFutureSupplier

        static <T,​F extends java.util.concurrent.Future<T>> java.util.concurrent.Callable<T> decorateFutureSupplier​(TimeLimiter timeLimiter,
                                                                                                                          java.util.function.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 java.util.concurrent.CompletionStage<T>> java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> decorateCompletionStage​(TimeLimiter timeLimiter,
                                                                                                                                                                        java.util.concurrent.ScheduledExecutorService scheduler,
                                                                                                                                                                        java.util.function.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

        java.lang.String getName()
      • getTags

        io.vavr.collection.Map<java.lang.String,​java.lang.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 java.util.concurrent.Future<T>> T executeFutureSupplier​(java.util.function.Supplier<F> futureSupplier)
                                                                                    throws java.lang.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:
        java.lang.Exception - if unable to compute a result
      • executeCompletionStage

        default <T,​F extends java.util.concurrent.CompletionStage<T>> java.util.concurrent.CompletionStage<T> executeCompletionStage​(java.util.concurrent.ScheduledExecutorService scheduler,
                                                                                                                                           java.util.function.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 java.util.concurrent.Future<T>> java.util.concurrent.Callable<T> decorateFutureSupplier​(java.util.function.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 java.util.concurrent.CompletionStage<T>> java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> decorateCompletionStage​(java.util.concurrent.ScheduledExecutorService scheduler,
                                                                                                                                                                 java.util.function.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​(java.lang.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 java.util.concurrent.TimeoutException createdTimeoutExceptionWithName​(java.lang.String name,
                                                                                     @Nullable
                                                                                     java.lang.Throwable t)