Class DocumentHandlerDecorator
java.lang.Object
io.fluxzero.sdk.tracking.handling.DocumentHandlerDecorator
- All Implemented Interfaces:
HandlerDecorator
A
HandlerDecorator that intercepts handler methods annotated with HandleDocument and synchronizes
their return values with a DocumentStore.
This decorator ensures that searchable document views (e.g. projections or read models) are automatically updated when a message is handled. If the handler method returns an object of the same type as the incoming message payload (and is non-passive), the decorator will:
- Index the return value into the configured document store, if non-null and its
Revisionis newer than the original version (before upcasting). - Delete the corresponding document if the return value is
null.
Graph
may migrate only the derived graph document and never invokes this ordinary document update path.
The collection name is derived from the message topic. Timestamps for indexing can be determined in two ways:
- If
SearchParametersare available, they are used to extract timestamps. - Otherwise, the message metadata keys
"$start"and"$end"are used (if present).
Example Usage
@HandleDocument
UserProfile update(UserProfile document) {
return document.toBuilder().status(active).build(); //gives every existing user a status of active
}
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classstatic interfaceNested classes/interfaces inherited from interface HandlerDecorator
HandlerDecorator.MergedDecorator -
Field Summary
Fields inherited from interface HandlerDecorator
noOp -
Constructor Summary
ConstructorsConstructorDescriptionDocumentHandlerDecorator(Supplier<DocumentStore> documentStoreSupplier) DocumentHandlerDecorator(Supplier<DocumentStore> documentStoreSupplier, DocumentHandlerDecorator.GraphDocumentWriter graphDocumentWriter) -
Method Summary
Modifier and TypeMethodDescriptionio.fluxzero.common.handling.Handler<DeserializingMessage> wrap(io.fluxzero.common.handling.Handler<DeserializingMessage> handler) Wraps the given handler with additional behavior.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HandlerDecorator
andThen
-
Constructor Details
-
DocumentHandlerDecorator
-
DocumentHandlerDecorator
public DocumentHandlerDecorator(Supplier<DocumentStore> documentStoreSupplier, DocumentHandlerDecorator.GraphDocumentWriter graphDocumentWriter)
-
-
Method Details
-
wrap
public io.fluxzero.common.handling.Handler<DeserializingMessage> wrap(io.fluxzero.common.handling.Handler<DeserializingMessage> handler) Description copied from interface:HandlerDecoratorWraps the given handler with additional behavior.- Specified by:
wrapin interfaceHandlerDecorator- Parameters:
handler- the original handler to be wrapped- Returns:
- a decorated handler
-