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) 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> protected io.fluxzero.common.api.SerializedMessagegetMessage(long index) default io.fluxzero.common.tracking.MessageStorevoidprotected voidnotifyMonitors(List<io.fluxzero.common.api.SerializedMessage> messages) protected voidpurgeExpiredMessages(Duration messageExpiration) io.fluxzero.common.RegistrationregisterMonitor(Consumer<List<io.fluxzero.common.api.SerializedMessage>> monitor) voidsetRetentionTime(Duration arg0) toString()default <T extends io.fluxzero.common.tracking.MessageStore>
T
-
Constructor Details
-
InMemoryMessageStore
public InMemoryMessageStore(io.fluxzero.common.MessageType messageType)
-
-
Method Details
-
append
-
getBatch
-
notifyMonitors
public void notifyMonitors() -
notifyMonitors
-
purgeExpiredMessages
-
filterMessages
protected Collection<io.fluxzero.common.api.SerializedMessage> filterMessages(Collection<io.fluxzero.common.api.SerializedMessage> messages) -
getMessage
protected io.fluxzero.common.api.SerializedMessage getMessage(long index) -
registerMonitor
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
toString
-
append
-
getBatch
-
setRetentionTime
-
unwrap
-
getMessageStore
default io.fluxzero.common.tracking.MessageStore getMessageStore()
-