Class StatefulHandler
java.lang.Object
io.fluxzero.sdk.tracking.handling.StatefulHandler
A
Handler implementation for classes annotated with Stateful, responsible for resolving and invoking
stateful handler instances based on Association metadata.
This handler enables long-lived, stateful components to participate in message processing. It ensures that:
- Messages are routed to the correct instance(s) based on matching association keys
- Instances are automatically created, updated, or deleted depending on the result of handler methods
- Static methods may initialize new handler instances (e.g., factory methods on creation events)
- Association routing is supported via property-based or method-level annotations
Routing Logic
The handler uses the following mechanisms to determine message dispatch:Associationannotations on fields and methods define the routing keys used to match incoming messages to stateful instances.EntityIddefines the identity of the handler, used when persisting or retrieving state.- If no matching instances are found, static methods marked with
@Handle...and@Association(always = true)may be invoked to initialize new instances. - Fallback routing via
RoutingKeyannotations or message metadata is also supported.
Persistence and Lifecycle
- The resolved handler instances are loaded and stored via a
HandlerRepository(typically backed by theDocumentStore). - If a handler method returns a new instance, it replaces the current state.
- If a handler method returns
null, the instance is removed from storage.
Batch-Aware Behavior
- Routing decisions may respect the current
Trackercontext, segment ownership, and routing constraints. - Within a batch, state changes may be staged locally before committing (when
commitInBatch = true).
Internal Mechanics
- Associations are lazily resolved and memoized for performance.
- Handler invocation is delegated via
HandlerMatcherandHandlerInvokerabstractions. - Support is provided for multiple matches and combined invocation across entries.
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionStatefulHandler(Class<?> targetClass, io.fluxzero.common.handling.HandlerMatcher<Object, DeserializingMessage> handlerMatcher, HandlerRepository repository) StatefulHandler(Class<?> targetClass, io.fluxzero.common.handling.HandlerMatcher<Object, DeserializingMessage> handlerMatcher, HandlerRepository repository, List<io.fluxzero.common.handling.ParameterResolver<? super DeserializingMessage>> parameterResolvers, Function<Executable, ? extends Annotation> methodAnnotationProvider) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanalreadyFiltered(io.fluxzero.common.handling.HandlerInvoker i) associations(DeserializingMessage message) protected BooleancanTrackerHandle(DeserializingMessage message, String routingKey) Optional<io.fluxzero.common.handling.HandlerInvoker> getInvoker(DeserializingMessage message) Class<?> default io.fluxzero.common.handling.Handler<DeserializingMessage> or(io.fluxzero.common.handling.Handler<DeserializingMessage> arg0) toString()
-
Constructor Details
-
StatefulHandler
public StatefulHandler(Class<?> targetClass, io.fluxzero.common.handling.HandlerMatcher<Object, DeserializingMessage> handlerMatcher, HandlerRepository repository) -
StatefulHandler
public StatefulHandler(Class<?> targetClass, io.fluxzero.common.handling.HandlerMatcher<Object, DeserializingMessage> handlerMatcher, HandlerRepository repository, List<io.fluxzero.common.handling.ParameterResolver<? super DeserializingMessage>> parameterResolvers, Function<Executable, ? extends Annotation> methodAnnotationProvider)
-
-
Method Details
-
getInvoker
public Optional<io.fluxzero.common.handling.HandlerInvoker> getInvoker(DeserializingMessage message) -
alreadyFiltered
protected boolean alreadyFiltered(io.fluxzero.common.handling.HandlerInvoker i) -
canTrackerHandle
-
associations
-
toString
-
getTargetClass
Class<?> getTargetClass() -
or
default io.fluxzero.common.handling.Handler<DeserializingMessage> or(io.fluxzero.common.handling.Handler<DeserializingMessage> arg0)
-