Class DefaultHandlerFactory
java.lang.Object
io.fluxzero.sdk.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.) Statefulhandlers — persisted and associated viaAssociationSocketEndpointhandlers — WebSocket-based interaction handlersTrackSelfannotated classes — handlers for self-tracking message types
Customization
The factory is configured with the following pluggable components:- A
MessageTypeindicating the type of messages it supports (e.g., COMMAND, QUERY) - A
HandlerDecoratorused to wrap all created handlers with additional behavior - A list of
ParameterResolvers to inject method parameters during handler invocation - A
MessageFilterthat determines whether a message is applicable to a handler method - A
HandlerRepositorysupplier for managing persisted state in@Statefulhandlers - A
RepositoryProviderfor 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, aStatefulHandleris created - If the target is annotated with
SocketEndpoint, aSocketEndpointHandleris 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 additionalHandlerInterceptors 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 Fluxzero. 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 giventargetobject.protected HandlerMatcher<Object, DeserializingMessage> createHandlerMatcher(Object target, HandlerConfiguration<DeserializingMessage> config) protected Class<? extends Annotation> getHandlerAnnotation(MessageType messageType) protected booleanisHandler(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:HandlerFactoryAttempts to create a message handler for the giventargetobject.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 newHandlerinstance is constructed to wrap them.This is a central mechanism in Fluxzero used to support:
- Tracking handlers for stateful components
- Mutable, dynamic, or self-handling types
- In-memory
@LocalHandlers
- Specified by:
createHandlerin 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 additionalHandlerInterceptors to apply around message dispatch. These can be used to customize behavior with logging, retry logic, etc.- Returns:
- An
Optionalcontaining aHandlerif 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
-