Interface HandlerInterceptor
- All Superinterfaces:
HandlerDecorator
- All Known Implementing Classes:
AuthenticatingInterceptor
,DataProtectionInterceptor
,DisableMetrics
,ErrorReportingInterceptor
,HandlerMonitor
,SchedulingInterceptor
,ValidatingInterceptor
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A HandlerInterceptor
can be used to inspect or modify messages before they are passed to a handler, monitor
and log handler executions, block certain messages from being handled, or inspect and modify the return value after
handling.
Interceptors are typically configured via
Consumer.handlerInterceptors()
, or applied programmatically using the
wrap(Handler)
method.
Common Use Cases:
- Validating or transforming a message before it reaches the handler
- Adding logging, tracing, or metrics for observability
- Conditionally suppressing handler invocation
- Decorating or modifying the result of a handler method
Example:
public class LoggingHandlerInterceptor implements HandlerInterceptor {
@Override
public Function<DeserializingMessage, Object> interceptHandling(
Function<DeserializingMessage, Object> next, HandlerInvoker invoker) {
return message -> {
log.info("Before handling: {}", message.getPayload());
Object result = next.apply(message);
log.info("After handling: {}", result);
return result;
};
}
}
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
Implementation ofHandler
that delegates to another handler and applies aHandlerInterceptor
.Nested classes/interfaces inherited from interface io.fluxcapacitor.javaclient.tracking.handling.HandlerDecorator
HandlerDecorator.MergedDecorator
-
Field Summary
Fields inherited from interface io.fluxcapacitor.javaclient.tracking.handling.HandlerDecorator
noOp
-
Method Summary
Modifier and TypeMethodDescriptioninterceptHandling
(Function<DeserializingMessage, Object> function, HandlerInvoker invoker) Intercepts the message handling logic.default Handler
<DeserializingMessage> wrap
(Handler<DeserializingMessage> handler) Wraps aHandler
with this interceptor, producing an intercepted handler.Methods inherited from interface io.fluxcapacitor.javaclient.tracking.handling.HandlerDecorator
andThen
-
Method Details
-
interceptHandling
Function<DeserializingMessage,Object> interceptHandling(Function<DeserializingMessage, Object> function, HandlerInvoker invoker) Intercepts the message handling logic.The
function
parameter represents the next step in the handling chain— typically the actual message handler. Theinvoker
provides metadata and invocation logic for the underlying handler method.Within this method, an interceptor may:
- Modify the
DeserializingMessage
before passing it to the handler - Bypass the handler entirely and return a value directly
- Wrap the result after the handler is invoked
Note: Interceptors may return a different
DeserializingMessage
, but it must be compatible with a handler method in the same target class. If no suitable handler is found, an exception will be thrown.- Parameters:
function
- the next step in the handler chain (typically the handler itself)invoker
- the metadata and execution strategy for the actual handler method- Returns:
- a decorated function that wraps handling behavior
- Modify the
-
wrap
Wraps aHandler
with this interceptor, producing an intercepted handler.- Specified by:
wrap
in interfaceHandlerDecorator
- Parameters:
handler
- the original handler to wrap- Returns:
- an intercepted handler that applies this interceptor to all handled messages
-