Class ServiceRejectionPolicy.Builder
- Enclosing class:
- ServiceRejectionPolicy
ServiceRejectionPolicy
builder to support a custom policy.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Return a customServiceRejectionPolicy
based on the options of this builder.onLimitResponseBuilder
(BiFunction<HttpRequestMetaData, StreamingHttpResponseFactory, Single<StreamingHttpResponse>> onLimitResponseBuilder) Determines theStreamingHttpResponse
when a capacity limit is met.onLimitRetryAfter
(Consumer<HttpResponseMetaData> onLimitRetryAfter) Determines aretry-after
header in theStreamingHttpResponse
when a capacity limit is met.onLimitStopAcceptingConnections
(boolean stopAccepting) When a certainCapacityLimiter
rejects a request due to the active limit, (e.g., noCapacityLimiter.Ticket
is 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 theStreamingHttpResponse
when a circuit-breaker limit is met.onOpenCircuitRetryAfter
(BiConsumer<HttpResponseMetaData, StateContext> onOpenCircuitRetryAfter) Determines aretry-after
header in theStreamingHttpResponse
when a capacity limit is met.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
onLimitResponseBuilder
public ServiceRejectionPolicy.Builder onLimitResponseBuilder(BiFunction<HttpRequestMetaData, StreamingHttpResponseFactory, Single<StreamingHttpResponse>> onLimitResponseBuilder) Determines theStreamingHttpResponse
when a capacity limit is met.- Parameters:
onLimitResponseBuilder
- A factory function used to generate aStreamingHttpResponse
based on therequest
when acapacity
limit is observed.- Returns:
this
.
-
onLimitRetryAfter
public ServiceRejectionPolicy.Builder onLimitRetryAfter(Consumer<HttpResponseMetaData> onLimitRetryAfter) Determines aretry-after
header in theStreamingHttpResponse
when a capacity limit is met.- Parameters:
onLimitRetryAfter
- AHttpResponseMetaData
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.- Returns:
this
.
-
onLimitStopAcceptingConnections
When a certainCapacityLimiter
rejects a request due to the active limit, (e.g., noCapacityLimiter.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 aCapacityLimiter
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 theticket's
terminal callback (dropped
,failed
,completed
,ignored
) returns a positive or negative value, demonstrating available capacity or not_supported respectively. When the returned value is0
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.- Parameters:
stopAccepting
-true
will 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 theStreamingHttpResponse
when a circuit-breaker limit is met.- Parameters:
onOpenCircuitResponseBuilder
- A factory function used to generate aStreamingHttpResponse
based on therequest
when an openbreaker
is observed.- Returns:
this
.
-
onOpenCircuitRetryAfter
public ServiceRejectionPolicy.Builder onOpenCircuitRetryAfter(BiConsumer<HttpResponseMetaData, StateContext> onOpenCircuitRetryAfter) Determines aretry-after
header in theStreamingHttpResponse
when a capacity limit is met.- Parameters:
onOpenCircuitRetryAfter
- AHttpResponseMetaData
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.- Returns:
this
.
-
build
Return a customServiceRejectionPolicy
based on the options of this builder.- Returns:
- A custom
ServiceRejectionPolicy
based on the options of this builder.
-