public static final class ServiceRejectionPolicy.Builder
extends Object
ServiceRejectionPolicy builder to support a custom policy.| Constructor and Description |
|---|
Builder() |
| Modifier and Type | Method and Description |
|---|---|
ServiceRejectionPolicy |
build()
Return a custom
ServiceRejectionPolicy based on the options of this builder. |
ServiceRejectionPolicy.Builder |
onLimitResponseBuilder(BiFunction<HttpRequestMetaData,StreamingHttpResponseFactory,Single<StreamingHttpResponse>> onLimitResponseBuilder)
Determines the
StreamingHttpResponse when a capacity limit is met. |
ServiceRejectionPolicy.Builder |
onLimitRetryAfter(Consumer<HttpResponseMetaData> onLimitRetryAfter)
Determines a
retry-after header in the
StreamingHttpResponse when a capacity limit is met. |
ServiceRejectionPolicy.Builder |
onLimitStopAcceptingConnections(boolean stopAccepting)
When a certain
CapacityLimiter rejects a request due to the active limit,
(e.g., no CapacityLimiter.Ticket is returned) influence the server to also stop accepting new connections
until the capacity is under healthy conditions again. |
ServiceRejectionPolicy.Builder |
onOpenCircuitResponseBuilder(BiFunction<HttpRequestMetaData,StreamingHttpResponseFactory,Single<StreamingHttpResponse>> onOpenCircuitResponseBuilder)
Determines the
StreamingHttpResponse when a circuit-breaker limit is met. |
ServiceRejectionPolicy.Builder |
onOpenCircuitRetryAfter(BiConsumer<HttpResponseMetaData,StateContext> onOpenCircuitRetryAfter)
Determines a
retry-after header in the
StreamingHttpResponse when a capacity limit is met. |
public ServiceRejectionPolicy.Builder onLimitResponseBuilder(BiFunction<HttpRequestMetaData,StreamingHttpResponseFactory,Single<StreamingHttpResponse>> onLimitResponseBuilder)
StreamingHttpResponse when a capacity limit is met.onLimitResponseBuilder - A factory function used to generate a StreamingHttpResponse based
on the request when a capacity limit is observed.this.public ServiceRejectionPolicy.Builder onLimitRetryAfter(Consumer<HttpResponseMetaData> onLimitRetryAfter)
retry-after header in the
StreamingHttpResponse when a capacity limit is met.onLimitRetryAfter - A HttpResponseMetaData consumer, 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.this.public ServiceRejectionPolicy.Builder onLimitStopAcceptingConnections(boolean stopAccepting)
CapacityLimiter rejects a request due to the active limit,
(e.g., no CapacityLimiter.Ticket is returned) influence the server to also stop accepting new connections
until the capacity is under healthy conditions again.
This setting only works when a CapacityLimiter matches 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 the ticket's terminal callback (dropped,
failed, completed, ignored) returns a positive or negative value, demonstrating available capacity or not_supported
respectively. When the returned value is 0 that 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 backlog to 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 backlog will give a
better behavior.
stopAccepting - true will allow this filter to control the connection acceptance of the
overall server socket.this.public ServiceRejectionPolicy.Builder onOpenCircuitResponseBuilder(BiFunction<HttpRequestMetaData,StreamingHttpResponseFactory,Single<StreamingHttpResponse>> onOpenCircuitResponseBuilder)
StreamingHttpResponse when a circuit-breaker limit is met.onOpenCircuitResponseBuilder - A factory function used to generate a StreamingHttpResponse
based on the request when an open breaker is observed.this.public ServiceRejectionPolicy.Builder onOpenCircuitRetryAfter(BiConsumer<HttpResponseMetaData,StateContext> onOpenCircuitRetryAfter)
retry-after header in the
StreamingHttpResponse when a capacity limit is met.onOpenCircuitRetryAfter - A HttpResponseMetaData consumer, 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.this.public ServiceRejectionPolicy build()
ServiceRejectionPolicy based on the options of this builder.ServiceRejectionPolicy based on the options of this builder.