Package org.mockserver.state
Interface StateBackend
- All Superinterfaces:
AutoCloseable,Closeable
- All Known Implementing Classes:
InfinispanStateBackend,InMemoryStateBackend
Pluggable backend for all shared MockServer state. A single
StateBackend instance is created per HttpState via
StateBackendFactory.
The default InMemoryStateBackend wraps today's exact in-memory
data structures for zero behaviour change. A clustered implementation
(phase 2b+) can back these stores with a distributed cache.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddInvalidationListener(InvalidationListener listener) Adds an invalidation listener that receives change notifications from ALL stores managed by this backend.blobs()Returns the blob store for persisted expectations, recorded cassettes, fixtures, and snapshots.voidclose()Closes the backend and releases any resources.KeyValueStore<com.fasterxml.jackson.databind.node.ObjectNode>crudEntities(String namespace) Returns a CRUD entity key-value store for the given namespace.Returns the expectation key-value store.default booleanReturns whether this backend is clustered (multi-node state replication).nodeId()Returns a unique identifier for this node/instance.Returns the scenario-state key-value store.
-
Method Details
-
expectations
KeyValueStore<ExpectationEntry> expectations()Returns the expectation key-value store. The in-memory implementation internally wraps aCircularPriorityQueuefor identical ordering and eviction behaviour. -
scenarioStates
KeyValueStore<String> scenarioStates()Returns the scenario-state key-value store. Keys are composite scenario-name + isolation strings; values are state strings. -
crudEntities
Returns a CRUD entity key-value store for the given namespace. Each namespace corresponds to a distinct CRUD resource path. -
blobs
BlobStore blobs()Returns the blob store for persisted expectations, recorded cassettes, fixtures, and snapshots. -
addInvalidationListener
Adds an invalidation listener that receives change notifications from ALL stores managed by this backend. -
nodeId
String nodeId()Returns a unique identifier for this node/instance. Used to distinguish local vs. remote writes in a clustered backend. -
isClustered
default boolean isClustered()Returns whether this backend is clustered (multi-node state replication). Whentrue, callers must use CAS on the sharedKeyValueStorefor correctness-critical mutations such as Times consumption. The default isfalse(single node, all state node-local). -
close
void close()Closes the backend and releases any resources. No-op for the in-memory backend.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-