Class InMemoryMessageStore
java.lang.Object
io.fluxzero.sdk.tracking.client.InMemoryMessageStore
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
InMemoryEventStore, InMemoryScheduleStore
An in-memory implementation of the
MessageStore interface for storing SerializedMessages without
external persistence.
This store underpins both local tracking (via LocalTrackingClient) and local publishing (via in-memory
GatewayClient) in test and development environments.
Behavior
- Messages are assigned a unique, incrementing index upon append if none is present.
- Stored messages are retained in memory using a
ConcurrentSkipListMapkeyed by index. - Supports expiration via
retentionTime, with periodic purging during appends. - Supports message monitors that are notified after every append.
Thread Safety
- Append and monitor notifications are synchronized to preserve consistency across batch inserts.
- Message storage is based on concurrent data structures, safe for multi-threaded access.
- Monitors use a
CopyOnWriteArraySetfor thread-safe iteration and updates.
Use Cases
- Unit and integration tests for consumers, handlers, and gateways
- Simulating message flow in local environments without a Fluxzero backend
- Standalone tools that mock message streams
Message Expiration
- Expired messages are purged based on wall-clock time via
Fluxzero.currentTime(). - The purge logic is triggered during each call to
append(List)when a retention policy is set.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondefault CompletableFuture<Void> append(io.fluxzero.common.api.SerializedMessage... arg0) protected voidappendMessages(List<io.fluxzero.common.api.SerializedMessage> messages) Stores messages while the caller owns this store's monitor.voidclose()protected Collection<io.fluxzero.common.api.SerializedMessage> filterMessages(Collection<io.fluxzero.common.api.SerializedMessage> messages) default List<io.fluxzero.common.api.SerializedMessage> List<io.fluxzero.common.api.SerializedMessage> List<io.fluxzero.common.api.SerializedMessage> default List<io.fluxzero.common.api.SerializedMessage> protected io.fluxzero.common.api.SerializedMessagegetMessage(long index) default io.fluxzero.common.tracking.MessageStoreprotected Collection<io.fluxzero.common.api.SerializedMessage> messagesFrom(Long minIndex, boolean inclusive) protected final ObjectSerializes a store mutation with its subsequent monitor notification while allowing callbacks to re-enter the store itself.voidprotected voidnotifyMonitors(List<io.fluxzero.common.api.SerializedMessage> messages) protected voidpurgeExpiredMessages(Duration messageExpiration) io.fluxzero.common.RegistrationregisterMonitor(Consumer<List<io.fluxzero.common.api.SerializedMessage>> monitor) io.fluxzero.common.tracking.MessageStoreBatchscanBatch(Long minIndex, int maxSize, boolean inclusive, long maxBytes, Predicate<? super io.fluxzero.common.api.SerializedMessage> filter) default io.fluxzero.common.tracking.MessageStoreBatchscanBatch(Long arg0, int arg1, boolean arg2, long arg3, Predicate<? super io.fluxzero.common.api.SerializedMessage> arg4, boolean arg5) voidsetRetentionTime(Duration arg0) toString()voidtruncate()protected voidClears the message log while the caller owns this store's monitor.default <T extends io.fluxzero.common.tracking.MessageStore>
T
-
Constructor Details
-
InMemoryMessageStore
public InMemoryMessageStore(io.fluxzero.common.MessageType messageType)
-
-
Method Details
-
append
-
appendMessages
Stores messages while the caller owns this store's monitor. Subclasses can use this to update their secondary indexes and the message log atomically without invoking external monitors under the store lock. -
getBatch
-
getBatch
-
scanBatch
-
notifyMonitors
public void notifyMonitors() -
notifyMonitors
-
purgeExpiredMessages
-
filterMessages
protected Collection<io.fluxzero.common.api.SerializedMessage> filterMessages(Collection<io.fluxzero.common.api.SerializedMessage> messages) -
messagesFrom
protected Collection<io.fluxzero.common.api.SerializedMessage> messagesFrom(Long minIndex, boolean inclusive) -
getMessage
protected io.fluxzero.common.api.SerializedMessage getMessage(long index) -
truncate
public void truncate() -
truncateMessages
protected void truncateMessages()Clears the message log while the caller owns this store's monitor. -
monitorNotificationLock
Serializes a store mutation with its subsequent monitor notification while allowing callbacks to re-enter the store itself. Subclasses must acquire this lock before the store monitor whenever both are needed. -
registerMonitor
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
toString
-
append
-
getBatch
-
getBatch
-
scanBatch
-
setRetentionTime
-
unwrap
-
getMessageStore
default io.fluxzero.common.tracking.MessageStore getMessageStore()
-