Class ThrottlingStrategy<T extends Request>
java.lang.Object
com.linecorp.armeria.server.throttling.ThrottlingStrategy<T>
- Direct Known Subclasses:
TokenBucketThrottlingStrategy
Determines whether a request should be throttled.
-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a newThrottlingStrategy
with a default name.protected
Creates a newThrottlingStrategy
with specified name. -
Method Summary
Modifier and TypeMethodDescriptionabstract CompletionStage<Boolean>
accept
(ServiceRequestContext ctx, T request) Returns whether a given request should be treated as failed before it is handled actually.static <T extends Request>
ThrottlingStrategy<T>always()
Returns a singletonThrottlingStrategy
that always accepts requests.final String
name()
Returns the name of thisThrottlingStrategy
.static <T extends Request>
ThrottlingStrategy<T>never()
Returns a singletonThrottlingStrategy
that never accepts requests.static <T extends Request>
ThrottlingStrategy<T>of
(BiFunction<? super ServiceRequestContext, T, ? extends CompletionStage<Boolean>> function) Creates a newThrottlingStrategy
that determines whether a request should be accepted or not using a givenBiFunction
instance.static <T extends Request>
ThrottlingStrategy<T>of
(BiFunction<? super ServiceRequestContext, T, ? extends CompletionStage<Boolean>> function, String strategyName) Returns a newThrottlingStrategy
that determines whether a request should be accepted or not using a givenBiFunction
instance.static <T extends Request>
ThrottlingStrategy<T>rateLimiting
(double requestsPerSecond) Returns a newThrottlingStrategy
that provides a throttling strategy based on requests per second.static <T extends Request>
ThrottlingStrategy<T>rateLimiting
(double requestsPerSecond, String name) Returns a newThrottlingStrategy
that provides a throttling strategy based on requests per second.
-
Constructor Details
-
ThrottlingStrategy
protected ThrottlingStrategy()Creates a newThrottlingStrategy
with a default name. -
ThrottlingStrategy
Creates a newThrottlingStrategy
with specified name.
-
-
Method Details
-
never
Returns a singletonThrottlingStrategy
that never accepts requests. -
always
Returns a singletonThrottlingStrategy
that always accepts requests. -
of
public static <T extends Request> ThrottlingStrategy<T> of(BiFunction<? super ServiceRequestContext, T, ? extends CompletionStage<Boolean>> function, String strategyName) Returns a newThrottlingStrategy
that determines whether a request should be accepted or not using a givenBiFunction
instance. -
of
public static <T extends Request> ThrottlingStrategy<T> of(BiFunction<? super ServiceRequestContext, T, ? extends CompletionStage<Boolean>> function) Creates a newThrottlingStrategy
that determines whether a request should be accepted or not using a givenBiFunction
instance. -
rateLimiting
Returns a newThrottlingStrategy
that provides a throttling strategy based on requests per second.- Parameters:
requestsPerSecond
- the number of requests per one second thisThrottlingStrategy
accepts
-
rateLimiting
public static <T extends Request> ThrottlingStrategy<T> rateLimiting(double requestsPerSecond, String name) Returns a newThrottlingStrategy
that provides a throttling strategy based on requests per second.- Parameters:
requestsPerSecond
- the number of requests per one second thisThrottlingStrategy
acceptsname
- the name of theThrottlingStrategy
-
accept
Returns whether a given request should be treated as failed before it is handled actually. -
name
Returns the name of thisThrottlingStrategy
.
-