Class InMemorySessionEventStore
java.lang.Object
dev.tachyonmcp.core.server.session.InMemorySessionEventStore
- All Implemented Interfaces:
SessionEventStore,Closeable,AutoCloseable
@InternalApi
public final class InMemorySessionEventStore
extends Object
implements SessionEventStore
In-memory event log bounded to
maxEvents: appends past the cap drop the oldest entry
(they remain unrecoverable — an SSE client reconnecting with a Last-Event-ID older than
the window simply misses those events, matching typical broker retention semantics).
Cursors handed out by drain(java.lang.String, long, java.util.function.Predicate<dev.tachyonmcp.core.server.session.SessionEvent>) are global append indices, stable across trims
via the firstIndex offset. Reads snapshot the window under the lock and process outside
it, so a slow consumer never blocks appends.
Guarded by a ReentrantLock, not synchronized: appends run on virtual threads,
and on Java 21 a VT contending on a monitor pins its carrier thread (fixed only in JEP 491 /
Java 24). A j.u.c lock parks the virtual thread instead and frees the carrier.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(SessionEvent event) Appends an event to the log.voidclose()longdrain(String sessionId, long cursor, Predicate<SessionEvent> processor) Drains events to the processor one at a time until exhausted or backpressured; returns the last cursor.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.tachyonmcp.core.server.session.SessionEventStore
replay
-
Constructor Details
-
InMemorySessionEventStore
public InMemorySessionEventStore() -
InMemorySessionEventStore
public InMemorySessionEventStore(long firstIndex, int maxEvents)
-
-
Method Details
-
append
Description copied from interface:SessionEventStoreAppends an event to the log.- Specified by:
appendin interfaceSessionEventStore
-
drain
Description copied from interface:SessionEventStoreDrains events to the processor one at a time until exhausted or backpressured; returns the last cursor.- Specified by:
drainin interfaceSessionEventStore
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-