Package com.linecorp.armeria.common
Interface SuccessFunction
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A function that determines whether a
Client
and Service
handled a request successfully
or not.
This function can be used by the decorators like the following to determine
whether the request was handled successfully or not:
Example:
ServerBuilder sb = Server
.builder()
.successFunction((ctx, req) -> req.responseHeaders().status().code() == 200 ||
req.responseHeaders().status().code() == 404)
.decorator(MetricCollectingService.newDecorator(MeterIdPrefixFunction.ofDefault("myServer")))
.decorator(LoggingService.newDecorator()));
WebClient client = WebClient
.builder(uri)
.successFunction((ctx, req) -> req.responseHeaders().status().code() == 200 ||
req.responseHeaders().status().code() == 404)
.decorator(MetricCollectingClient.newDecorator(MeterIdPrefixFunction.ofDefault("myClient")))
.decorator(LoggingClient.newDecorator()))
.build();
-
Method Summary
Modifier and TypeMethodDescriptionstatic SuccessFunction
always()
Returns aSuccessFunction
that will always returntrue
.boolean
isSuccess
(RequestContext ctx, RequestLog log) Returnstrue
if the request was handled successfully.static SuccessFunction
never()
Returns aSuccessFunction
that will always returnfalse
.static SuccessFunction
Returns the default success classification function which checksRequestLog.responseCause()
is null, 100 <=HttpStatus
< 400 andRpcResponse.isCompletedExceptionally()
==false
.
-
Method Details
-
never
Returns aSuccessFunction
that will always returnfalse
. -
always
Returns aSuccessFunction
that will always returntrue
. -
ofDefault
Returns the default success classification function which checksRequestLog.responseCause()
is null, 100 <=HttpStatus
< 400 andRpcResponse.isCompletedExceptionally()
==false
. -
isSuccess
Returnstrue
if the request was handled successfully.
-