Interface MessageStore

All Superinterfaces:
AutoCloseable, HasMessageStore, Monitored<List<SerializedMessage>>
All Known Implementing Classes:
CollectionMessageStore, InMemoryEventStore, InMemoryMessageStore, InMemoryScheduleStore, TestServerScheduleStore

public interface MessageStore extends AutoCloseable, Monitored<List<SerializedMessage>>, HasMessageStore
A low-level store for serialized messages.

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 Details

    • append

      default CompletableFuture<Void> append(SerializedMessage... messages)
      Appends the given messages to the store.
      Parameters:
      messages - messages to append
      Returns:
      a CompletableFuture that completes when the messages have been successfully appended
    • append

      Appends a list of messages to the store.
      Parameters:
      messages - messages to append
      Returns:
      a CompletableFuture that completes when the messages have been successfully appended
    • getBatch

      default List<SerializedMessage> getBatch(Long lastIndex, int maxSize)
      Retrieves a batch of messages starting from the given lastIndex (exclusive).
      Parameters:
      lastIndex - minimum message index to start from (exclusive)
      maxSize - maximum number of messages to retrieve
      Returns:
      a list of SerializedMessage instances
    • getBatch

      default List<SerializedMessage> getBatch(Long lastIndex, int maxSize, long maxBytes)
      Retrieves a batch of messages starting from the given lastIndex (exclusive), limiting both message count and serialized payload bytes.
      Parameters:
      lastIndex - minimum message index to start from (exclusive)
      maxSize - maximum number of messages to retrieve
      maxBytes - maximum number of serialized payload bytes to retrieve, or 0 for no byte limit
      Returns:
      a list of SerializedMessage instances
    • getBatch

      List<SerializedMessage> getBatch(Long minIndex, int maxSize, boolean inclusive)
      Retrieves a batch of messages starting from the given minIndex.
      Parameters:
      minIndex - minimum message index to start from
      maxSize - maximum number of messages to retrieve
      inclusive - whether to include the message at minIndex
      Returns:
      a list of SerializedMessage instances
    • getBatch

      default List<SerializedMessage> getBatch(Long minIndex, int maxSize, boolean inclusive, long maxBytes)
      Retrieves a batch of messages starting from the given minIndex, 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 from
      maxSize - maximum number of messages to retrieve
      inclusive - whether to include the message at minIndex
      maxBytes - maximum number of serialized payload bytes to retrieve, or 0 for no byte limit
      Returns:
      a list of SerializedMessage instances
    • scanBatch

      default MessageStoreBatch scanBatch(Long minIndex, int maxSize, boolean inclusive, long maxBytes, Predicate<? super SerializedMessage> filter)
      Scans messages starting from the given minIndex, returning messages accepted by filter and metadata about the unfiltered source scan.

      maxSize limits the number of source messages scanned. maxBytes limits the cumulative serialized payload bytes of accepted messages. If the first accepted message is larger than maxBytes, it is still returned so consumers can make progress.

      Parameters:
      minIndex - minimum message index to start from
      maxSize - maximum number of source messages to scan
      inclusive - whether to include the message at minIndex
      maxBytes - maximum number of accepted serialized payload bytes, or 0 for no byte limit
      filter - predicate deciding which messages enter the returned batch
      Returns:
      accepted messages and source scan metadata
    • setRetentionTime

      void setRetentionTime(Duration retentionPeriod)
      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

      default <T extends MessageStore> T unwrap(Class<T> type)
      Attempts to unwrap the current instance to a concrete implementation or extension of MessageStore.
      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:
      close in interface AutoCloseable
    • getMessageStore

      default MessageStore getMessageStore()
      Returns the current instance as the MessageStore.
      Specified by:
      getMessageStore in interface HasMessageStore