Interface TimeLimiter
- All Known Implementing Classes:
TimeLimiterImpl
public interface TimeLimiter
A TimeLimiter decorator stops execution after a configurable duration.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceAn EventPublisher which can be used to register event consumers. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic TimeoutExceptionstatic <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<T,F extends CompletionStage<T>>
Supplier<CompletionStage<T>>decorateCompletionStage(ScheduledExecutorService scheduler, Supplier<F> supplier) Decorate a CompletionStage supplier which is decorated by a TimeLimiterdecorateFutureSupplier(TimeLimiter timeLimiter, Supplier<F> futureSupplier) Creates a Callback that is restricted by a TimeLimiter.decorateFutureSupplier(Supplier<F> futureSupplier) Creates a Callback that is restricted by a TimeLimiter.default <T,F extends CompletionStage<T>>
CompletionStage<T>executeCompletionStage(ScheduledExecutorService scheduler, Supplier<F> supplier) Decorates and executes the CompletionStage Supplierdefault <T,F extends Future<T>>
TexecuteFutureSupplier(Supplier<F> futureSupplier) Decorates and executes the Future Supplier.Returns an EventPublisher which can be used to register event consumers.getName()getTags()Returns an unmodifiable map with tags assigned to this TimeLimiter.Get the TimeLimiterConfig of this TimeLimiter decorator.static TimeLimiterof(TimeLimiterConfig timeLimiterConfig) Creates a TimeLimiter decorator with a TimeLimiterConfig configuration.static TimeLimiterof(String name, TimeLimiterConfig timeLimiterConfig) Creates a TimeLimiter decorator with a TimeLimiterConfig configuration.static TimeLimiterCreates a TimeLimiter with a custom TimeLimiter configuration.static TimeLimiterCreates a TimeLimiter decorator with a timeout Duration.static TimeLimiterCreates a TimeLimiter decorator with a default TimeLimiterConfig configuration.static TimeLimiterofDefaults(String name) Creates a TimeLimiter decorator with a default TimeLimiterConfig configuration.voidRecords a failed call.voidRecords a successful call.
-
Field Details
-
DEFAULT_NAME
- See Also:
-
-
Method Details
-
ofDefaults
Creates a TimeLimiter decorator with a default TimeLimiterConfig configuration.- Returns:
- The
TimeLimiter
-
ofDefaults
Creates a TimeLimiter decorator with a default TimeLimiterConfig configuration.- Returns:
- The
TimeLimiter
-
of
Creates a TimeLimiter decorator with a TimeLimiterConfig configuration.- Parameters:
timeLimiterConfig- the TimeLimiterConfig- Returns:
- The
TimeLimiter
-
of
Creates a TimeLimiter decorator with a TimeLimiterConfig configuration.- Parameters:
name- the name of the TimeLimitertimeLimiterConfig- the TimeLimiterConfig- Returns:
- The
TimeLimiter
-
of
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
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 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 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 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
String getName() -
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 futureF- 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 resultF- the CompletionStage type supplied- Parameters:
scheduler- execution service to use to schedule timeoutsupplier- the original CompletionStage supplier- Returns:
- the decorated CompletionStage
-
decorateFutureSupplier
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 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 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
Records a failed call. This method must be invoked when a call failed.- Parameters:
throwable- The throwable which must be recorded
-
createdTimeoutExceptionWithName
-