Package io.fluxcapacitor.common.handling
Interface Handler<M>
- Type Parameters:
M
- the type of messages this handler supports (usuallyDeserializingMessage
)
- All Known Implementing Classes:
DefaultHandler
,DocumentHandlerDecorator.DocumentHandler
,Handler.DelegatingHandler
,HandlerInterceptor.InterceptedHandler
,MutableHandler
,SocketEndpointHandler
,StatefulHandler
public interface Handler<M>
Represents a container for a message handler and the mechanism to resolve a
HandlerInvoker
for a given
message.
A Handler
encapsulates a target class and a provider for an instance of that class. It acts as a factory for
HandlerInvoker
instances that can be used to invoke the appropriate handler method for a given message.
This abstraction allows support for both stateless and stateful handlers:
- Stateless: A singleton handler instance is reused for every message (e.g., typical application service).
- Stateful: The handler instance is dynamically retrieved, e.g., from a repository, based on message content (e.g., aggregates or projections).
A handler may or may not be able to process a given message. If it can, it returns a non-empty
Optional
containing a HandlerInvoker
; otherwise, it returns Optional.empty()
.
Handler Architecture
┌────────────────────┐ │ HandlerInspector │ └────────┬───────────┘ │ inspects target class ▼ ┌────────────────────┐ creates ┌──────────────────────┐ │ HandlerMatcher │──────────────────────▶│ HandlerInvoker │ └────────┬───────────┘ └──────────────────────┘ │ produces invoker if message │ matches a method ▼ ┌────────────────────┐ │ Handler │◀───────────── target instance └────────────────────┘
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
Abstract base class forHandler
implementations that delegate to another handler. -
Method Summary
Modifier and TypeMethodDescriptiongetInvoker
(M message) Returns aHandlerInvoker
capable of processing the given message, if available.Class
<?> Returns the class of the handler's target object.Creates a composite handler that executes the current handler and then delegates to the specified next handler if the current handler cannot handle the message or does not provide an invoker.
-
Method Details
-
getTargetClass
Class<?> getTargetClass()Returns the class of the handler's target object. This may be used for reflective operations, logging, or framework-level behavior.- Returns:
- the class of the handler's target
-
getInvoker
Returns aHandlerInvoker
capable of processing the given message, if available.- Parameters:
message
- the message to be handled- Returns:
- an optional
HandlerInvoker
if this handler can handle the message; otherwiseOptional.empty()
-
or
Creates a composite handler that executes the current handler and then delegates to the specified next handler if the current handler cannot handle the message or does not provide an invoker.- Parameters:
next
- the next handler to be invoked if this handler does not handle the message- Returns:
- a new handler combining the current handler and the specified next handler
-