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 Details

    • InMemoryAuditEventStore

      public InMemoryAuditEventStore()
      Creates an empty store.
  • Method Details

    • append

      public AuditEnvelope append(TenantId tenant, AuditEvent event)
      Description copied from interface: AuditEventStore
      Persists an audit event under the given tenant scope and returns the resulting envelope (including the store-assigned identifier).
      Specified by:
      append in interface AuditEventStore
      Parameters:
      tenant - tenant scope; must not be null
      event - audit event; must not be null
      Returns:
      the persisted envelope, never null
    • query

      public List<AuditEnvelope> query(TenantId tenant, AuditQuery query)
      Description copied from interface: AuditEventStore
      Returns every persisted envelope under tenant that matches query, in insertion order (oldest first).
      Specified by:
      query in interface AuditEventStore
      Parameters:
      tenant - tenant scope; must not be null
      query - match filter; must not be null. AuditQuery.all() returns every event.
      Returns:
      immutable list of matching envelopes; empty when none match
    • purgeOlderThan

      public int purgeOlderThan(Instant cutoff)
      Description copied from interface: AuditEventStore
      Drops every persisted envelope whose underlying event predates cutoff, for retention purposes. Implementations that do not support retention may treat this as a no-op (and document it).
      Specified by:
      purgeOlderThan in interface AuditEventStore
      Parameters:
      cutoff - retention boundary; events with event.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