Class InMemoryAuditEventStore
java.lang.Object
com.svenruppert.jsentinel.audit.InMemoryAuditEventStore
- All Implemented Interfaces:
AuditEventStore
@ExperimentalJSentinelApi
public final class InMemoryAuditEventStore
extends Object
implements AuditEventStore
In-memory
AuditEventStore backed by a single tenant-scoped
list. Suitable for tests, demos, and single-tenant single-process
applications.
Thread-safety: a ReentrantReadWriteLock serialises writes
and lets concurrent queries proceed in parallel.
Identifiers are random UUIDs; query results are returned in
insertion order (oldest first); retention is implemented via
purgeOlderThan(Instant).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappend(TenantId tenant, AuditEvent event) Persists an audit event under the given tenant scope and returns the resulting envelope (including the store-assigned identifier).intpurgeOlderThan(Instant cutoff) Drops every persisted envelope whose underlying event predatescutoff, for retention purposes.query(TenantId tenant, AuditQuery query) Returns every persisted envelope undertenantthat matchesquery, in insertion order (oldest first).intsize()Returns the current store size (across every tenant).
-
Constructor Details
-
InMemoryAuditEventStore
public InMemoryAuditEventStore()Creates an empty store.
-
-
Method Details
-
append
Description copied from interface:AuditEventStorePersists an audit event under the given tenant scope and returns the resulting envelope (including the store-assigned identifier).- Specified by:
appendin interfaceAuditEventStore- Parameters:
tenant- tenant scope; must not benullevent- audit event; must not benull- Returns:
- the persisted envelope, never
null
-
query
Description copied from interface:AuditEventStoreReturns every persisted envelope undertenantthat matchesquery, in insertion order (oldest first).- Specified by:
queryin interfaceAuditEventStore- Parameters:
tenant- tenant scope; must not benullquery- match filter; must not benull.AuditQuery.all()returns every event.- Returns:
- immutable list of matching envelopes; empty when none match
-
purgeOlderThan
Description copied from interface:AuditEventStoreDrops every persisted envelope whose underlying event predatescutoff, for retention purposes. Implementations that do not support retention may treat this as a no-op (and document it).- Specified by:
purgeOlderThanin interfaceAuditEventStore- Parameters:
cutoff- retention boundary; events withevent.timestamp().isBefore(cutoff)are removed- Returns:
- number of envelopes purged
-
size
public int size()Returns the current store size (across every tenant). Test seam.- Returns:
- number of envelopes
-