Interface MessageStore
- All Superinterfaces:
AutoCloseable, HasMessageStore, Monitored<List<SerializedMessage>>
- All Known Implementing Classes:
CollectionMessageStore, InMemoryEventStore, InMemoryMessageStore, InMemoryScheduleStore, TestServerScheduleStore
This interface defines an append-only log used to store SerializedMessage instances, typically representing
commands, events, queries, or other domain messages. It supports batched retrieval and allows integration with
in-memory or persistent message tracking implementations.
The MessageStore plays a central role in Fluxzero's tracking and message handling infrastructure.
In testing, in-memory implementations of MessageStore are used to simulate Fluxzero Runtime behavior.
This interface is also Monitored, allowing hooks to observe message publication, and extends
HasMessageStore so it can expose itself as a reusable component.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault CompletableFuture<Void> append(SerializedMessage... messages) Appends the given messages to the store.append(List<SerializedMessage> messages) Appends a list of messages to the store.default voidclose()Default no-op close method.default List<SerializedMessage> Retrieves a batch of messages starting from the givenlastIndex(exclusive).Retrieves a batch of messages starting from the givenminIndex.default List<SerializedMessage> Retrieves a batch of messages starting from the givenminIndex, limiting both message count and serialized payload bytes.default List<SerializedMessage> Retrieves a batch of messages starting from the givenlastIndex(exclusive), limiting both message count and serialized payload bytes.default MessageStoreReturns the current instance as theMessageStore.default MessageStoreBatchscanBatch(Long minIndex, int maxSize, boolean inclusive, long maxBytes, Predicate<? super SerializedMessage> filter) Scans messages starting from the givenminIndex, returning messages accepted byfilterand metadata about the unfiltered source scan.voidsetRetentionTime(Duration retentionPeriod) Sets the retention period for messages.voidtruncate()Removes all messages from this store while keeping the logical log available for future appends.default <T extends MessageStore>
TAttempts to unwrap the current instance to a concrete implementation or extension ofMessageStore.Methods inherited from interface Monitored
registerMonitor
-
Method Details
-
append
Appends the given messages to the store.- Parameters:
messages- messages to append- Returns:
- a
CompletableFuturethat completes when the messages have been successfully appended
-
append
Appends a list of messages to the store.- Parameters:
messages- messages to append- Returns:
- a
CompletableFuturethat completes when the messages have been successfully appended
-
getBatch
Retrieves a batch of messages starting from the givenlastIndex(exclusive).- Parameters:
lastIndex- minimum message index to start from (exclusive)maxSize- maximum number of messages to retrieve- Returns:
- a list of
SerializedMessageinstances
-
getBatch
Retrieves a batch of messages starting from the givenlastIndex(exclusive), limiting both message count and serialized payload bytes.- Parameters:
lastIndex- minimum message index to start from (exclusive)maxSize- maximum number of messages to retrievemaxBytes- maximum number of serialized payload bytes to retrieve, or0for no byte limit- Returns:
- a list of
SerializedMessageinstances
-
getBatch
Retrieves a batch of messages starting from the givenminIndex.- Parameters:
minIndex- minimum message index to start frommaxSize- maximum number of messages to retrieveinclusive- whether to include the message atminIndex- Returns:
- a list of
SerializedMessageinstances
-
getBatch
default List<SerializedMessage> getBatch(Long minIndex, int maxSize, boolean inclusive, long maxBytes) Retrieves a batch of messages starting from the givenminIndex, limiting both message count and serialized payload bytes.If the first available message is larger than
maxBytes, it is still returned so consumers can make progress.- Parameters:
minIndex- minimum message index to start frommaxSize- maximum number of messages to retrieveinclusive- whether to include the message atminIndexmaxBytes- maximum number of serialized payload bytes to retrieve, or0for no byte limit- Returns:
- a list of
SerializedMessageinstances
-
scanBatch
default MessageStoreBatch scanBatch(Long minIndex, int maxSize, boolean inclusive, long maxBytes, Predicate<? super SerializedMessage> filter) Scans messages starting from the givenminIndex, returning messages accepted byfilterand metadata about the unfiltered source scan.maxSizelimits the number of source messages scanned.maxByteslimits the cumulative serialized payload bytes of accepted messages. If the first accepted message is larger thanmaxBytes, it is still returned so consumers can make progress.- Parameters:
minIndex- minimum message index to start frommaxSize- maximum number of source messages to scaninclusive- whether to include the message atminIndexmaxBytes- maximum number of accepted serialized payload bytes, or0for no byte limitfilter- predicate deciding which messages enter the returned batch- Returns:
- accepted messages and source scan metadata
-
setRetentionTime
Sets the retention period for messages. Messages older than this duration may be removed depending on the implementation.- Parameters:
retentionPeriod- duration to retain messages
-
truncate
void truncate()Removes all messages from this store while keeping the logical log available for future appends. -
unwrap
Attempts to unwrap the current instance to a concrete implementation or extension ofMessageStore.- Type Parameters:
T- the target type- Parameters:
type- the desired type to unwrap to- Returns:
- the unwrapped instance
- Throws:
UnsupportedOperationException- if the current instance cannot be unwrapped to the given type
-
close
default void close()Default no-op close method. Override if resources need cleanup.- Specified by:
closein interfaceAutoCloseable
-
getMessageStore
Returns the current instance as theMessageStore.- Specified by:
getMessageStorein interfaceHasMessageStore
-