Class CrossProtocolEventBus
register(org.mockserver.model.CrossProtocolScenario)) associate a
CrossProtocolTrigger + optional match pattern with a scenario
name and target state. When an event is fire(org.mockserver.model.CrossProtocolTrigger, java.lang.String)d, every matching
listener triggers a ScenarioManager.setState(java.lang.String, java.lang.String) call.
Thread-safe: uses ConcurrentHashMap and CopyOnWriteArrayList.
Fleet-awareness (G11 follow-up): when a clustered StateBackend
is wired via setStateBackend(StateBackend), registrations (trigger-to-scenario
mappings) are replicated via the backend's crudEntities("cross-protocol-bus")
store: register/unregister/reset write-through to the backend, and a separate
InvalidationListener rebuilds the node-local bus
from the backend on remote writes. The fire(org.mockserver.model.CrossProtocolTrigger, java.lang.String) path remains purely
node-local for zero-overhead event dispatching. When no backend is set or the
backend is not clustered, behaviour is identical to the pre-clustering
node-local-only bus.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidfire(CrossProtocolTrigger trigger, String identifier) Fire an event.static CrossProtocolEventBusvoidRebuilds the node-local listener map from the backend store.voidregister(CrossProtocolScenario scenario) voidreset()voidsetScenarioManager(ScenarioManager manager) voidsetStateBackend(StateBackend backend) Wires the clustered state backend for fleet-wide registration replication.voidunregister(CrossProtocolScenario scenario)
-
Constructor Details
-
CrossProtocolEventBus
public CrossProtocolEventBus()Creates a fresh, non-singleton instance. Public for testing (e.g. per-test isolation in the clustered 2-node integration test).Singleton-coupling note: the
InvalidationListenerregistered byHttpStatetargetsgetInstance()(the static singleton). A non-singleton bus (as used by tests) must register its own invalidation listener on the backend to receive reconciliation callbacks.
-
-
Method Details
-
getInstance
-
setScenarioManager
-
setStateBackend
Wires the clustered state backend for fleet-wide registration replication. When the backendisClustered(), registrations are replicated via the backend's CRUD entity store, and anInvalidationListeneris registered to rebuild the node-local bus on remote writes. When the backend is not clustered, this method is a no-op -- the bus stays purely node-local. -
register
-
unregister
-
fire
Fire an event. For each matching registered scenario, callsScenarioManager.setState(String, String).This path is purely node-local -- no backend round-trip. In a clustered deployment, each node fires from its own replicated copy of the registration set.
- Parameters:
trigger- the event typeidentifier- the relevant identifier (e.g. DNS query name, gRPC service name, HTTP path, WebSocket URL)
-
reset
public void reset() -
reconcileFromBackend
public void reconcileFromBackend()Rebuilds the node-local listener map from the backend store. Called by theInvalidationListenerwhen a remote write is detected. Thread-safe but weakly-consistent: the removeIf + put loop is NOT atomic, so a concurrentfire(org.mockserver.model.CrossProtocolTrigger, java.lang.String)call may miss a registration for one cycle. This matches the existingConcurrentHashMapweakly-consistent iteration semantics and is acceptable for event-bus registration convergence.
-