Class ChunkedDeserializingMessage
java.lang.Object
io.fluxzero.sdk.common.serialization.DeserializingMessage
io.fluxzero.sdk.common.serialization.ChunkedDeserializingMessage
- All Implemented Interfaces:
HasMetadata, HasMessage
Deserializing view for a message whose payload is split across multiple indexed messages.
The first chunk can be handled immediately as an InputStream. Typed payload access waits until the final
chunk has been observed in the normal tracking stream.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final recordstatic interfaceReads serialized messages from a bounded index range while recovering chunked messages.protected classNested classes/interfaces inherited from class DeserializingMessage
DeserializingMessage.MessageSpliterator -
Field Summary
Fields inherited from class DeserializingMessage
messageFormatterFields inherited from interface HasMessage
warnedAboutMissingPropertyFields inherited from interface HasMetadata
CHUNK_INDEX, FINAL_CHUNK, FIRST_CHUNK -
Constructor Summary
ConstructorsConstructorDescriptionChunkedDeserializingMessage(SerializedMessage firstChunk, MessageType messageType, String topic, Serializer serializer) Creates a chunked message view starting at the first observed chunk. -
Method Summary
Modifier and TypeMethodDescriptionprotected DeserializingMessageprotected SerializedMessagevoidappendChunk(SerializedMessage chunk) Appends an additional chunk to this message.voidAppends a continuation chunk that was already present in the current tracker batch.Returns a future that completes when the final chunk has been observed.voidSwitches this message to streaming-only mode.voidFails the stream and any pending aggregated deserialization with the given error.byte[]Returns the fully aggregated payload bytes, waiting for the final chunk when necessary.Returns theMetadataassociated with this object.<V> VRetrieves the message payload, deserializing if necessary, cast to the expected type.<R> RgetPayloadAs(Type type) Retrieves the message payload, deserializing if necessary and optionally converted to the given type.Class<?> Returns the runtime class of the payload object, orVoid.classif the payload isnull.static Optional<ChunkedDeserializingMessage> recoverFromContinuation(SerializedMessage continuation, MessageType messageType, String topic, Serializer serializer, long minIndexInclusive, int pageSize, ChunkedDeserializingMessage.ChunkReader chunkReader) Reconstructs a chunked message when tracking observes a continuation after the original first chunk was already read by an earlier tracker run.Returns the underlyingMessagerepresentation of this object.Methods inherited from class DeserializingMessage
apply, computeContextIfAbsent, computeForBatch, computeForBatchIfAbsent, forEachInBatch, getBatchResource, getBatchResourceOrDefault, getContext, getCurrent, getIndex, getMessageId, getOptionally, getTimestamp, getType, handleBatch, isDeserialized, putContext, run, toString, whenBatchCompletes, withData, withMetadata, withPayloadMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface HasMessage
computeRoutingKey, getRoutingKey, getRoutingKeyMethods inherited from interface HasMetadata
chunked, firstChunk, lastChunk
-
Constructor Details
-
ChunkedDeserializingMessage
public ChunkedDeserializingMessage(SerializedMessage firstChunk, MessageType messageType, String topic, Serializer serializer) Creates a chunked message view starting at the first observed chunk.- Parameters:
firstChunk- the first chunk of the messagemessageType- the type of message being reconstructedtopic- the topic associated with the message, if anyserializer- the serializer used for typed payload access
-
-
Method Details
-
recoverFromContinuation
public static Optional<ChunkedDeserializingMessage> recoverFromContinuation(SerializedMessage continuation, MessageType messageType, String topic, Serializer serializer, long minIndexInclusive, int pageSize, ChunkedDeserializingMessage.ChunkReader chunkReader) Reconstructs a chunked message when tracking observes a continuation after the original first chunk was already read by an earlier tracker run.- Parameters:
continuation- the observed continuation chunkmessageType- the type of message being reconstructedtopic- the topic associated with the message, if anyserializer- the serializer used for typed payload accessminIndexInclusive- the first index to inspect while looking for earlier chunkspageSize- the maximum number of messages to request per range readchunkReader- callback used to read earlier messages from the tracking stream- Returns:
- a reconstructed chunked message when the first chunk and required previous continuations were found
-
getPayloadAs
Description copied from interface:HasMessageRetrieves the message payload, deserializing if necessary and optionally converted to the given type.By default, this performs a conversion of the payload using
JsonUtils.- Specified by:
getPayloadAsin interfaceHasMessage- Overrides:
getPayloadAsin classDeserializingMessage- Type Parameters:
R- the expected payload type- Returns:
- the payload converted to the given type
-
getPayload
public <V> V getPayload()Description copied from interface:HasMessageRetrieves the message payload, deserializing if necessary, cast to the expected type.By default, this delegates to
toMessage().getPayload().- Specified by:
getPayloadin interfaceHasMessage- Overrides:
getPayloadin classDeserializingMessage- Type Parameters:
V- the expected payload type- Returns:
- the deserialized payload
-
toMessage
Description copied from interface:HasMessageReturns the underlyingMessagerepresentation of this object.- Specified by:
toMessagein interfaceHasMessage- Overrides:
toMessagein classDeserializingMessage- Returns:
- the
Messagebacking this instance
-
getMetadata
Description copied from interface:HasMetadataReturns theMetadataassociated with this object.- Specified by:
getMetadatain interfaceHasMetadata- Overrides:
getMetadatain classDeserializingMessage- Returns:
- metadata attached to this instance; never
null
-
getPayloadClass
Description copied from interface:HasMessageReturns the runtime class of the payload object, orVoid.classif the payload isnull.- Specified by:
getPayloadClassin interfaceHasMessage- Overrides:
getPayloadClassin classDeserializingMessage- Returns:
- the payload's class
-
getSerializedObject
- Overrides:
getSerializedObjectin classDeserializingMessage
-
completion
Returns a future that completes when the final chunk has been observed. -
getAggregatedPayloadBytes
public byte[] getAggregatedPayloadBytes()Returns the fully aggregated payload bytes, waiting for the final chunk when necessary. -
enableStreamingOnlyMode
public void enableStreamingOnlyMode()Switches this message to streaming-only mode. Subsequent chunks are exposed through the input stream but are no longer retained in heap for full-payload aggregation. -
appendChunk
Appends an additional chunk to this message. -
appendObservedContinuation
Appends a continuation chunk that was already present in the current tracker batch. -
fail
Fails the stream and any pending aggregated deserialization with the given error. -
aggregatedMessage
-
aggregatedSerializedMessage
-