Interface TimeLimiter
-
- All Known Implementing Classes:
TimeLimiterImpl
public interface TimeLimiterA TimeLimiter decorator stops execution after a configurable duration.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceTimeLimiter.EventPublisherAn EventPublisher which can be used to register event consumers.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_NAME
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static java.util.concurrent.TimeoutExceptioncreatedTimeoutExceptionWithName(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 TimeLimiterstatic <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 Supplierdefault <T,F extends java.util.concurrent.Future<T>>
TexecuteFutureSupplier(java.util.function.Supplier<F> futureSupplier)Decorates and executes the Future Supplier.TimeLimiter.EventPublishergetEventPublisher()Returns an EventPublisher which can be used to register event consumers.java.lang.StringgetName()io.vavr.collection.Map<java.lang.String,java.lang.String>getTags()Returns an unmodifiable map with tags assigned to this TimeLimiter.TimeLimiterConfiggetTimeLimiterConfig()Get the TimeLimiterConfig of this TimeLimiter decorator.static TimeLimiterof(TimeLimiterConfig timeLimiterConfig)Creates a TimeLimiter decorator with a TimeLimiterConfig configuration.static TimeLimiterof(java.lang.String name, TimeLimiterConfig timeLimiterConfig)Creates a TimeLimiter decorator with a TimeLimiterConfig configuration.static TimeLimiterof(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 TimeLimiterof(java.time.Duration timeoutDuration)Creates a TimeLimiter decorator with a timeout Duration.static TimeLimiterofDefaults()Creates a TimeLimiter decorator with a default TimeLimiterConfig configuration.static TimeLimiterofDefaults(java.lang.String name)Creates a TimeLimiter decorator with a default TimeLimiterConfig configuration.voidonError(java.lang.Throwable throwable)Records a failed call.voidonSuccess()Records a successful call.
-
-
-
Field Detail
-
DEFAULT_NAME
static final java.lang.String DEFAULT_NAME
- See Also:
- Constant Field Values
-
-
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 TimeLimitertimeLimiterConfig- 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
tagspassed 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 TimeLimitertimeLimiterConfig- a custom TimeLimiter configurationtags- 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 supplierF- the future type supplied- Parameters:
timeLimiter- the TimeLimiterfutureSupplier- 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 resultF- the CompletionStage type supplied- Parameters:
timeLimiter- the TimeLimiterscheduler- execution service to use to schedule timeoutsupplier- 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.ExceptionDecorates and executes the Future Supplier.- Type Parameters:
T- the result type of the futureF- 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 resultF- the CompletionStage type supplied- Parameters:
scheduler- execution service to use to schedule timeoutsupplier- 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 supplierF- 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 resultF- the CompletionStage type supplied- Parameters:
scheduler- execution service to use to schedule timeoutsupplier- 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)
-
-