Class StateBackendFactory

java.lang.Object
org.mockserver.state.StateBackendFactory

public final class StateBackendFactory extends Object
Pluggable factory for the StateBackend.

Mirrors the ExpectationStoreFactory pattern: a volatile-registry with a default in-memory implementation. An optional clustered backend (phase 2b, in a separate module) can register a StateBackendFactory.Factory that returns a clustering-aware StateBackend without mockserver-core depending on the data grid.

Auto-discovery: when stateBackend=infinispan is configured and no custom factory has been registered, the factory attempts to load InfinispanStateBackendRegistrar via reflection from the classpath. If the class is found, its register() method is called, which registers the Infinispan factory. This keeps mockserver-core free of any compile-time dependency on the Infinispan module.

Cloud blob store discovery: when blobStoreType is set to a cloud backend name (s3, gcs, azure) and no matching BlobStoreFactory has been registered, the factory attempts to load the corresponding registrar class via reflection. Each cloud module provides a registrar that calls registerBlobStoreFactory(String, BlobStoreFactory).

Thread-safety: the factory reference is volatile; register/reset are expected at startup. The blob store factory registry is a ConcurrentHashMap.

  • Method Details

    • register

      public static void register(StateBackendFactory.Factory customFactory)
      Register a custom factory (e.g. a clustered backend). Passing null resets to the default in-memory factory.
    • registerBlobStoreFactory

      public static void registerBlobStoreFactory(String typeName, BlobStoreFactory blobStoreFactory)
      Register a pluggable BlobStoreFactory for a given type name. Cloud blob store modules call this from their registrar classes to make themselves available when blobStoreType is configured.
      Parameters:
      typeName - the blob store type name (e.g. "s3", "gcs", "azure")
      blobStoreFactory - the factory that creates the blob store
    • resetToDefault

      public static void resetToDefault()
      Reset to the default in-memory factory (primarily for tests).
    • isCustomFactoryRegistered

      public static boolean isCustomFactoryRegistered()
      Returns:
      true if a non-default factory is registered.
    • isBlobStoreFactoryRegistered

      public static boolean isBlobStoreFactoryRegistered(String typeName)
      Returns:
      true if a blob store factory is registered for the given type name.
    • create

      public static StateBackend create(Configuration configuration)
      Create the state backend via the registered factory. If stateBackend=infinispan is configured and no custom factory has been registered yet, attempts auto-discovery of the Infinispan module from the classpath via reflection.