Class DocumentMessageReader

java.lang.Object
io.fluxzero.sdk.persisting.search.DocumentMessageReader

public final class DocumentMessageReader extends Object
Internal, registration-scoped document reader. Retains the original composition for typed Graph handlers while preserving the ordinary logical message, handler selection, payload parameters and interceptor input. The root's upcast payload is reused; descendant paths and revisions always refer to the original composition. Explicit internal Model-source handlers also require exactly one upcast state; ordinary document streams retain split/drop semantics. Registrations are reference-counted and removed with their handlers.
  • Constructor Details

    • DocumentMessageReader

      public DocumentMessageReader()
    • DocumentMessageReader

      public DocumentMessageReader(Supplier<SearchClient> searchClient)
      Binds live Graph hydration to the owning client and consumer namespace.
  • Method Details

    • register

      public Registration register(Object target, HandlerFilter filter)
      Records accepted typed Graph and Model-source methods until the returned registration is cancelled.
    • register

      public Registration register(Object target, HandlerFilter filter, ModelRepository repository)
      Registers durable notifications in the same namespace as the document consumer.
    • readsGraphs

      public boolean readsGraphs(String topic)
      Whether this collection needs the original composition alongside its logical document payload.
    • readsModelDocuments

      public boolean readsModelDocuments(String topic)
      Whether this topic requires a single canonical Model state or the original Graph representation.
    • read

      public Stream<DeserializingMessage> read(List<SerializedMessage> messages, String topic, Serializer serializer)
      Reads a batch; topics without typed Graph handlers retain the original serializer stream.
    • read

      public Stream<DeserializingMessage> read(List<SerializedMessage> messages, String topic, Serializer serializer, SearchClient client)
      Reads using the explicit consumer namespace while retaining this reader's registration-scoped definitions.
    • retainSource

      public static DeserializingMessage retainSource(DeserializingMessage message, SerializedMessage source)
      Retains the original stored document bytes for metadata preservation after custom deserialization. Use this when a custom Serializer.deserializeMessages(Stream, MessageType, String) implementation constructs entirely new envelopes or DeserializingMessage instances. Normal input-envelope withData, withMetadata and withSegment transformations already retain the source when invoked through this reader.

      Keep the original input before any transformation and attach it to each corresponding decoded output:

      DocumentMessageReader.retainSource(decodedOutput, originalInput);
      
      Keep this association explicitly when buffering, reordering or splitting a batch; message IDs alone are insufficient because multiple versions can share an ID. This method does not require changing the batch boundary. Later DeserializingMessage.withPayload(Object) replacements retain the attached context.

      The source must contain the exact stored version's original Data.DOCUMENT_FORMAT data. Tracking envelope metadata and the upcast/replacement payload are not substitutes for those bytes. Metadata is read lazily only when needed; there is no storage fetch or lookup of a newer version. Arbitrary custom formats are not decoded by this helper.

      This attaches metadata provenance only: it does not copy the source message's ID, timestamps, revision or transport metadata into the output. A custom serializer remains responsible for preserving those ordinary message-envelope contracts.

      Parameters:
      message - the corresponding custom-decoded output
      source - the unchanged original input document envelope
      Returns:
      the supplied output with its source attached to the handling context
      See Also:
    • sourceMetadata

      public static Metadata sourceMetadata(DeserializingMessage message)
      Returns metadata embedded in the handled document version, excluding the tracking envelope's time fields. Derived search exclusions and Model search summaries are regenerated by the replacement serializer. Decoding is deferred until a replacement is actually needed. Non-document inputs have no stored metadata.
    • isLiveGraph

      public static boolean isLiveGraph(DeserializingMessage message)
      Live compositions are observational and must never be persisted as a handler return side effect.