public abstract class ThrottlingStrategy<T extends Request> extends Object
| Modifier | Constructor and Description |
|---|---|
protected |
ThrottlingStrategy()
Creates a new
ThrottlingStrategy with a default name. |
protected |
ThrottlingStrategy(String name)
Creates a new
ThrottlingStrategy with specified name. |
| Modifier and Type | Method and Description |
|---|---|
abstract 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> |
always()
Returns a singleton
ThrottlingStrategy that always accepts requests. |
String |
name()
Returns the name of this
ThrottlingStrategy. |
static <T extends Request> |
never()
Returns a singleton
ThrottlingStrategy that never accepts requests. |
static <T extends Request> |
of(BiFunction<ServiceRequestContext,T,CompletionStage<Boolean>> function)
Creates a new
ThrottlingStrategy that determines whether a request should be accepted or not
using a given BiFunction instance. |
static <T extends Request> |
of(BiFunction<ServiceRequestContext,T,CompletionStage<Boolean>> function,
String strategyName)
Creates a new
ThrottlingStrategy that determines whether a request should be accepted or not
using a given BiFunction instance. |
protected ThrottlingStrategy()
ThrottlingStrategy with a default name.protected ThrottlingStrategy(String name)
ThrottlingStrategy with specified name.public static <T extends Request> ThrottlingStrategy<T> never()
ThrottlingStrategy that never accepts requests.public static <T extends Request> ThrottlingStrategy<T> always()
ThrottlingStrategy that always accepts requests.public static <T extends Request> ThrottlingStrategy<T> of(BiFunction<ServiceRequestContext,T,CompletionStage<Boolean>> function, String strategyName)
ThrottlingStrategy that determines whether a request should be accepted or not
using a given BiFunction instance.public static <T extends Request> ThrottlingStrategy<T> of(BiFunction<ServiceRequestContext,T,CompletionStage<Boolean>> function)
ThrottlingStrategy that determines whether a request should be accepted or not
using a given BiFunction instance.public abstract CompletionStage<Boolean> accept(ServiceRequestContext ctx, T request)
public String name()
ThrottlingStrategy.Copyright © 2020 LeanCloud. All rights reserved.