Class InfinispanStateBackend
- All Implemented Interfaces:
Closeable,AutoCloseable,StateBackend
StateBackend supporting both LOCAL (non-clustered)
and CLUSTERED (JGroups transport, REPL_SYNC) modes.
LOCAL mode (default, clusterEnabled=false): single-node,
no JGroups network transport, identical behaviour to Phase 2b. The Java
serialization allow-list remains permissive (".*") because caches
are heap-only with no network marshalling exposure.
CLUSTERED mode (clusterEnabled=true): starts a JGroups
transport for multi-node state replication. Caches use REPL_SYNC so all
writes are synchronously replicated to all cluster members. The Java
serialization allow-list is tightened to an explicit set of
packages covering exactly the types that cross the wire:
org.mockserver.state.infinispan.*(VersionedWrapper)org.mockserver.state.*(ExpectationEntry)org.mockserver.mock.*(Expectation, domain model)org.mockserver.model.*(HttpRequest, HttpResponse, etc.)org.mockserver.matchers.*(TimeToLive, Times)com.fasterxml.jackson.*(ObjectNode for CRUD entities)java.lang.*,java.util.*,java.time.*(primitives/wrappers, collections, time types)
Cluster invalidation: in CLUSTERED mode, Infinispan @Listener
annotated listeners are attached to each cache. When a remote write
arrives (replication from another node), the listener fires
InvalidationListener.onChanged(String) or
InvalidationListener.onCleared(), which triggers the node-local
view rebuild in RequestMatchers.reconcileFromBackend().
-
Constructor Summary
ConstructorsConstructorDescriptionInfinispanStateBackend(int maxExpectations) Backward-compatible constructor for tests and single-node usage.InfinispanStateBackend(Configuration configuration) Creates an Infinispan state backend in the appropriate mode based on configuration. -
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.booleanReturns whether this backend is in clustered mode.nodeId()Returns a unique identifier for this node/instance.Returns the scenario-state key-value store.
-
Constructor Details
-
InfinispanStateBackend
Creates an Infinispan state backend in the appropriate mode based on configuration. Whenconfiguration.clusterEnabled()istrue, a JGroups-transported clustered cache manager is created; otherwise a LOCAL (non-clustered) manager is used.- Parameters:
configuration- the MockServer configuration
-
InfinispanStateBackend
public InfinispanStateBackend(int maxExpectations) Backward-compatible constructor for tests and single-node usage. Creates a LOCAL (non-clustered) backend.- Parameters:
maxExpectations- the maximum number of expectations
-
-
Method Details
-
expectations
Description copied from interface:StateBackendReturns the expectation key-value store. The in-memory implementation internally wraps aCircularPriorityQueuefor identical ordering and eviction behaviour.- Specified by:
expectationsin interfaceStateBackend
-
scenarioStates
Description copied from interface:StateBackendReturns the scenario-state key-value store. Keys are composite scenario-name + isolation strings; values are state strings.- Specified by:
scenarioStatesin interfaceStateBackend
-
crudEntities
Description copied from interface:StateBackendReturns a CRUD entity key-value store for the given namespace. Each namespace corresponds to a distinct CRUD resource path.- Specified by:
crudEntitiesin interfaceStateBackend
-
blobs
Description copied from interface:StateBackendReturns the blob store for persisted expectations, recorded cassettes, fixtures, and snapshots.- Specified by:
blobsin interfaceStateBackend
-
addInvalidationListener
Description copied from interface:StateBackendAdds an invalidation listener that receives change notifications from ALL stores managed by this backend.- Specified by:
addInvalidationListenerin interfaceStateBackend
-
nodeId
Description copied from interface:StateBackendReturns a unique identifier for this node/instance. Used to distinguish local vs. remote writes in a clustered backend.- Specified by:
nodeIdin interfaceStateBackend
-
isClustered
public boolean isClustered()Returns whether this backend is in clustered mode. Overrides theStateBackenddefault (false) to return the actual clustering state from the configuration. Whentrue,RequestMatcherswill use backend CAS for Times consumption.- Specified by:
isClusteredin interfaceStateBackend
-
close
public void close()Description copied from interface:StateBackendCloses the backend and releases any resources. No-op for the in-memory backend.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceStateBackend
-