Class RedisStateMachineContextRepository<S,E>

java.lang.Object
org.springframework.statemachine.data.redis.RedisStateMachineContextRepository<S,E>
Type Parameters:
S - the type of state
E - the type of event
All Implemented Interfaces:
StateMachineContextRepository<S,E,StateMachineContext<S,E>>

public class RedisStateMachineContextRepository<S,E> extends Object implements StateMachineContextRepository<S,E,StateMachineContext<S,E>>
A StateMachineContextRepository backed by a redis and kryo serialization.

Persisted bytes are deserialised through Kryo with the safe-by-default class allowlist applied. Applications that use custom state or event types (typically enums) must register those types via the RedisStateMachineContextRepository(RedisConnectionFactory, String, Consumer) constructor's kryoCustomizer parameter; otherwise Kryo will reject them with IllegalArgumentException ("Class is not registered").

Keys are written with a fixed namespace prefix (default "ssm:context:") so that user-supplied machineId values cannot collide with unrelated keys in the same Redis logical database.

  • Field Details

    • DEFAULT_KEY_NAMESPACE

      public static final String DEFAULT_KEY_NAMESPACE
      Default key namespace prefix used when none is supplied.
      See Also:
  • Constructor Details

    • RedisStateMachineContextRepository

      public RedisStateMachineContextRepository(org.springframework.data.redis.connection.RedisConnectionFactory redisConnectionFactory)
      Instantiates a new redis state machine context repository using the default key namespace and no extra Kryo registrations.
      Parameters:
      redisConnectionFactory - the redis connection factory
    • RedisStateMachineContextRepository

      public RedisStateMachineContextRepository(org.springframework.data.redis.connection.RedisConnectionFactory redisConnectionFactory, String keyNamespace)
      Instantiates a new redis state machine context repository with a custom key namespace prefix and no extra Kryo registrations.
      Parameters:
      redisConnectionFactory - the redis connection factory
      keyNamespace - the prefix prepended to every Redis key
      Since:
      4.0.2
    • RedisStateMachineContextRepository

      public RedisStateMachineContextRepository(org.springframework.data.redis.connection.RedisConnectionFactory redisConnectionFactory, String keyNamespace, Consumer<com.esotericsoftware.kryo.Kryo> kryoCustomizer)
      Instantiates a new redis state machine context repository.
      Parameters:
      redisConnectionFactory - the redis connection factory
      keyNamespace - the prefix prepended to every Redis key. Must not be null; pass an empty string to disable prefixing (not recommended).
      kryoCustomizer - optional callback invoked once per Kryo instance after the framework's default registrations are applied. Use this to register application-specific state and event types (typically enums) so that they are accepted by the allowlist. May be null.
      Since:
      4.0.2
  • Method Details