Class DefaultHandlerFactory
java.lang.Object
io.fluxcapacitor.javaclient.tracking.handling.DefaultHandlerFactory
- All Implemented Interfaces:
HandlerFactory
Default implementation of the
HandlerFactory
for creating message handlers based on reflection.
This factory supports a wide range of handler types including:
- Simple class-based handlers (e.g., annotated with
@HandleCommand
,@HandleQuery
, etc.) Stateful
handlers — persisted and associated viaAssociation
SocketEndpoint
handlers — WebSocket-based interaction handlersTrackSelf
annotated classes — handlers for self-tracking message types
Customization
The factory is configured with the following pluggable components:- A
MessageType
indicating the type of messages it supports (e.g., COMMAND, QUERY) - A
HandlerDecorator
used to wrap all created handlers with additional behavior - A list of
ParameterResolver
s to inject method parameters during handler invocation - A
MessageFilter
that determines whether a message is applicable to a handler method - A
HandlerRepository
supplier for managing persisted state in@Stateful
handlers - A
RepositoryProvider
for shared caching of handler state (e.g., inSocketEndpointHandler
)
Handler Resolution Process
The factory inspects the provided target object (or class) and applies the following logic:- If the target is annotated with
Stateful
, aStatefulHandler
is created - If the target is annotated with
SocketEndpoint
, aSocketEndpointHandler
is created - If the target is annotated with
TrackSelf
, a handler is created with a filter ensuring messages are routed to matching payload types - Otherwise, a default handler is created using
DefaultHandler
Decorator Chaining
Any additionalHandlerInterceptor
s passed at creation are composed with the default decorator
and applied to the resulting handler.
Search-Specific Filtering
ForMessageType.DOCUMENT
and MessageType.CUSTOM
, additional filters like
HandleDocumentFilter
and HandleCustomFilter
are applied automatically.
This class is the main entry point for reflective handler generation in Flux Capacitor. It is used by both local and tracking-based handler registries to resolve method targets dynamically.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultHandlerFactory
(MessageType messageType, HandlerDecorator defaultDecorator, List<ParameterResolver<? super DeserializingMessage>> parameterResolvers, Function<Class<?>, HandlerRepository> handlerRepositorySupplier, RepositoryProvider repositoryProvider) -
Method Summary
Modifier and TypeMethodDescriptionprotected Handler
<DeserializingMessage> buildHandler
(@NonNull Object target, HandlerConfiguration<DeserializingMessage> config) protected MessageFilter
<? super DeserializingMessage> protected Handler
<DeserializingMessage> createDefaultHandler
(Object target, Function<DeserializingMessage, ?> targetSupplier, HandlerConfiguration<DeserializingMessage> config) createHandler
(Object target, HandlerFilter handlerFilter, List<HandlerInterceptor> extraInterceptors) Attempts to create a message handler for the giventarget
object.protected HandlerMatcher
<Object, DeserializingMessage> createHandlerMatcher
(Object target, HandlerConfiguration<DeserializingMessage> config) protected Class
<? extends Annotation> getHandlerAnnotation
(MessageType messageType) protected boolean
isHandler
(Class<?> targetClass, HandlerConfiguration<?> handlerConfiguration)
-
Constructor Details
-
DefaultHandlerFactory
public DefaultHandlerFactory(MessageType messageType, HandlerDecorator defaultDecorator, List<ParameterResolver<? super DeserializingMessage>> parameterResolvers, Function<Class<?>, HandlerRepository> handlerRepositorySupplier, RepositoryProvider repositoryProvider)
-
-
Method Details
-
createHandler
public Optional<Handler<DeserializingMessage>> createHandler(Object target, HandlerFilter handlerFilter, List<HandlerInterceptor> extraInterceptors) Description copied from interface:HandlerFactory
Attempts to create a message handler for the giventarget
object.This method analyzes the given object (or class) to discover message-handling methods (e.g.
@HandleCommand
,@HandleQuery
,@HandleEvent
, etc.) that match the providedHandlerFilter
. If any matching handler methods are found, a newHandler
instance is constructed to wrap them.This is a central mechanism in Flux Capacitor used to support:
- Tracking handlers for stateful components
- Mutable, dynamic, or self-handling types
- In-memory
@LocalHandler
s
- Specified by:
createHandler
in interfaceHandlerFactory
- Parameters:
target
- The handler target object or class. Can be a class (e.g.MyHandler.class
) or an instantiated object.handlerFilter
- A filter to determine which methods are valid handler methods. Only methods that pass this filter are included.extraInterceptors
- A list of additionalHandlerInterceptor
s to apply around message dispatch. These can be used to customize behavior with logging, retry logic, etc.- Returns:
- An
Optional
containing aHandler
if any suitable methods were found; otherwise, an emptyOptional
.
-
isHandler
-
buildHandler
protected Handler<DeserializingMessage> buildHandler(@NonNull @NonNull Object target, HandlerConfiguration<DeserializingMessage> config) -
createDefaultHandler
protected Handler<DeserializingMessage> createDefaultHandler(Object target, Function<DeserializingMessage, ?> targetSupplier, HandlerConfiguration<DeserializingMessage> config) -
getHandlerAnnotation
-
createHandlerMatcher
protected HandlerMatcher<Object,DeserializingMessage> createHandlerMatcher(Object target, HandlerConfiguration<DeserializingMessage> config) -
computeMessageFilter
-