Class ServiceRejectionPolicy.Builder
- Enclosing class:
- ServiceRejectionPolicy
ServiceRejectionPolicy builder to support a custom policy.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Return a customServiceRejectionPolicybased on the options of this builder.onLimitResponseBuilder(BiFunction<HttpRequestMetaData, StreamingHttpResponseFactory, Single<StreamingHttpResponse>> onLimitResponseBuilder) Determines theStreamingHttpResponsewhen a capacity limit is met.onLimitRetryAfter(Consumer<HttpResponseMetaData> onLimitRetryAfter) Determines aretry-afterheader in theStreamingHttpResponsewhen a capacity limit is met.onLimitStopAcceptingConnections(boolean stopAccepting) When a certainCapacityLimiterrejects a request due to the active limit, (e.g., noCapacityLimiter.Ticketis returned) influence the server to also stop accepting new connections until the capacity is under healthy conditions again.onOpenCircuitResponseBuilder(BiFunction<HttpRequestMetaData, StreamingHttpResponseFactory, Single<StreamingHttpResponse>> onOpenCircuitResponseBuilder) Determines theStreamingHttpResponsewhen a circuit-breaker limit is met.onOpenCircuitRetryAfter(BiConsumer<HttpResponseMetaData, StateContext> onOpenCircuitRetryAfter) Determines aretry-afterheader in theStreamingHttpResponsewhen a capacity limit is met.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
onLimitResponseBuilder
public ServiceRejectionPolicy.Builder onLimitResponseBuilder(BiFunction<HttpRequestMetaData, StreamingHttpResponseFactory, Single<StreamingHttpResponse>> onLimitResponseBuilder) Determines theStreamingHttpResponsewhen a capacity limit is met.- Parameters:
onLimitResponseBuilder- A factory function used to generate aStreamingHttpResponsebased on therequestwhen acapacitylimit is observed.- Returns:
this.
-
onLimitRetryAfter
public ServiceRejectionPolicy.Builder onLimitRetryAfter(Consumer<HttpResponseMetaData> onLimitRetryAfter) Determines aretry-afterheader in theStreamingHttpResponsewhen a capacity limit is met.- Parameters:
onLimitRetryAfter- AHttpResponseMetaDataconsumer, that can allow response decoration with additional headers to hint the peer (upon capacity limits) about a possible wait-time before a retry could be issued.- Returns:
this.
-
onLimitStopAcceptingConnections
When a certainCapacityLimiterrejects a request due to the active limit, (e.g., noCapacityLimiter.Ticketis returned) influence the server to also stop accepting new connections until the capacity is under healthy conditions again. This setting only works when aCapacityLimitermatches the incoming request, in cases this doesn't hold (see.Builder(Supplier, boolean)Builder's rejectedNotMatched argument}) this won't be effective.When a server socket stops accepting new connections (see.
ServerListenContext.acceptConnections(boolean)) due to capacity concerns, the state will be toggled back when theticket'sterminal callback (dropped,failed,completed,ignored) returns a positive or negative value, demonstrating available capacity or not_supported respectively. When the returned value is0that means no-capacity available, which will keep the server in the not-accepting mode.When enabling this feature, it's recommended for clients using this service to configure timeouts for their opening connection time and connection idleness time. For example, a client without connection-timeout or idle-timeout on the outgoing connections towards this service, won't be able to detect on time the connection delays. Likewise, on the server side you can configure the
server backlogto a very small number or even disable it completely, to avoid holding established connections in the OS.Worth noting that established connections that stay in the OS backlog, usually have a First In First Out behavior, which depending on the size of that queue, may result in extending latencies on newer requests because older ones are served first. Disabling the
server backlogwill give a better behavior.- Parameters:
stopAccepting-truewill allow this filter to control the connection acceptance of the overall server socket.- Returns:
this.
-
onOpenCircuitResponseBuilder
public ServiceRejectionPolicy.Builder onOpenCircuitResponseBuilder(BiFunction<HttpRequestMetaData, StreamingHttpResponseFactory, Single<StreamingHttpResponse>> onOpenCircuitResponseBuilder) Determines theStreamingHttpResponsewhen a circuit-breaker limit is met.- Parameters:
onOpenCircuitResponseBuilder- A factory function used to generate aStreamingHttpResponsebased on therequestwhen an openbreakeris observed.- Returns:
this.
-
onOpenCircuitRetryAfter
public ServiceRejectionPolicy.Builder onOpenCircuitRetryAfter(BiConsumer<HttpResponseMetaData, StateContext> onOpenCircuitRetryAfter) Determines aretry-afterheader in theStreamingHttpResponsewhen a capacity limit is met.- Parameters:
onOpenCircuitRetryAfter- AHttpResponseMetaDataconsumer, that can allow response decoration with additional headers to hint the peer (upon open breaker) about a possible wait-time before a retry could be issued.- Returns:
this.
-
build
Return a customServiceRejectionPolicybased on the options of this builder.- Returns:
- A custom
ServiceRejectionPolicybased on the options of this builder.
-