java.lang.Object
io.fluxzero.sdk.tracking.handling.StatefulHandler
- All Implemented Interfaces:
io.fluxzero.common.handling.Handler<DeserializingMessage>
public class StatefulHandler
extends Object
implements io.fluxzero.common.handling.Handler<DeserializingMessage>
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 ClassesModifier and TypeClassDescriptionprotected static classprotected classNested classes/interfaces inherited from interface io.fluxzero.common.handling.Handler
io.fluxzero.common.handling.Handler.DelegatingHandler<M> -
Constructor Summary
Constructors -
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) protected booleanincludedPayload(Object payload, StatefulHandler.AssociationValue association) toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.fluxzero.common.handling.Handler
getTargetClass, or
-
Constructor Details
-
StatefulHandler
public StatefulHandler()
-
-
Method Details
-
getInvoker
public Optional<io.fluxzero.common.handling.HandlerInvoker> getInvoker(DeserializingMessage message) - Specified by:
getInvokerin interfaceio.fluxzero.common.handling.Handler<DeserializingMessage>
-
alreadyFiltered
protected boolean alreadyFiltered(io.fluxzero.common.handling.HandlerInvoker i) -
canTrackerHandle
-
associations
-
includedPayload
-
toString
-