Interface StateBackend

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
InfinispanStateBackend, InMemoryStateBackend

public interface StateBackend extends Closeable
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 Type
    Method
    Description
    void
    Adds an invalidation listener that receives change notifications from ALL stores managed by this backend.
    Returns the blob store for persisted expectations, recorded cassettes, fixtures, and snapshots.
    void
    Closes the backend and releases any resources.
    default ClusterInfo
    Returns a snapshot of cluster membership and health for the GET /mockserver/cluster operability endpoint.
    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 boolean
    Returns whether this backend is clustered (multi-node state replication).
    Returns a unique identifier for this node/instance.
    Returns the scenario-state key-value store.
  • Method Details

    • expectations

      Returns the expectation key-value store. The in-memory implementation internally wraps a CircularPriorityQueue for 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

      KeyValueStore<com.fasterxml.jackson.databind.node.ObjectNode> crudEntities(String namespace)
      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

      void addInvalidationListener(InvalidationListener listener)
      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). When true, callers must use CAS on the shared KeyValueStore for correctness-critical mutations such as Times consumption. The default is false (single node, all state node-local).
    • clusterInfo

      default ClusterInfo clusterInfo()
      Returns a snapshot of cluster membership and health for the GET /mockserver/cluster operability endpoint.

      The default implementation returns a degenerate single-node snapshot (clustered=false, one local member equal to nodeId(), which is also the coordinator). A clustered backend overrides this to report the real fleet membership and the elected coordinator.

      Returns:
      a non-null ClusterInfo (always contains at least this node)
    • close

      void close()
      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