Class InMemoryStateBackend

java.lang.Object
org.mockserver.state.InMemoryStateBackend
All Implemented Interfaces:
Closeable, AutoCloseable, StateBackend

public class InMemoryStateBackend extends Object implements StateBackend
Default in-memory StateBackend that wraps today's exact data structures for zero behaviour change. Every store is node-local; there is no network I/O or clustering in this implementation.
  • Constructor Details

    • InMemoryStateBackend

      public InMemoryStateBackend(int maxExpectations)
    • InMemoryStateBackend

      public InMemoryStateBackend(int maxExpectations, BlobStore blobStore)
      Creates an in-memory state backend with an externally-supplied BlobStore. This allows the StateBackendFactory to inject a FilesystemBlobStore when blobStoreType=filesystem while keeping the KV stores in-memory.
      Parameters:
      maxExpectations - maximum number of expectations
      blobStore - the blob store implementation to use
  • Method Details

    • expectations

      public KeyValueStore<ExpectationEntry> expectations()
      Description copied from interface: StateBackend
      Returns the expectation key-value store. The in-memory implementation internally wraps a CircularPriorityQueue for identical ordering and eviction behaviour.
      Specified by:
      expectations in interface StateBackend
    • expectationStore

      public InMemoryExpectationKeyValueStore expectationStore()
      Returns the expectation store cast to its concrete type, so callers that need the sorted-list or queue API can access it.
    • scenarioStates

      public KeyValueStore<String> scenarioStates()
      Description copied from interface: StateBackend
      Returns the scenario-state key-value store. Keys are composite scenario-name + isolation strings; values are state strings.
      Specified by:
      scenarioStates in interface StateBackend
    • crudEntities

      public KeyValueStore<com.fasterxml.jackson.databind.node.ObjectNode> crudEntities(String namespace)
      Description copied from interface: StateBackend
      Returns a CRUD entity key-value store for the given namespace. Each namespace corresponds to a distinct CRUD resource path.
      Specified by:
      crudEntities in interface StateBackend
    • blobs

      public BlobStore blobs()
      Description copied from interface: StateBackend
      Returns the blob store for persisted expectations, recorded cassettes, fixtures, and snapshots.
      Specified by:
      blobs in interface StateBackend
    • addInvalidationListener

      public void addInvalidationListener(InvalidationListener listener)
      Description copied from interface: StateBackend
      Adds an invalidation listener that receives change notifications from ALL stores managed by this backend.
      Specified by:
      addInvalidationListener in interface StateBackend
    • nodeId

      public String nodeId()
      Description copied from interface: StateBackend
      Returns a unique identifier for this node/instance. Used to distinguish local vs. remote writes in a clustered backend.
      Specified by:
      nodeId in interface StateBackend
    • close

      public void close()
      Description copied from interface: StateBackend
      Closes the backend and releases any resources. No-op for the in-memory backend.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface StateBackend