Class RedisStateMachineContextRepository<S,E>
java.lang.Object
org.springframework.statemachine.data.redis.RedisStateMachineContextRepository<S,E>
- Type Parameters:
S- the type of stateE- 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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault key namespace prefix used when none is supplied. -
Constructor Summary
ConstructorsConstructorDescriptionRedisStateMachineContextRepository(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.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.RedisStateMachineContextRepository(org.springframework.data.redis.connection.RedisConnectionFactory redisConnectionFactory, String keyNamespace, Consumer<com.esotericsoftware.kryo.Kryo> kryoCustomizer) Instantiates a new redis state machine context repository. -
Method Summary
Modifier and TypeMethodDescriptiongetContext(String id) Gets the context.voidsave(StateMachineContext<S, E> context, String id) Save a context.
-
Field Details
-
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 factorykeyNamespace- 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 factorykeyNamespace- the prefix prepended to every Redis key. Must not benull; 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 benull.- Since:
- 4.0.2
-
-
Method Details
-
save
Description copied from interface:StateMachineContextRepositorySave a context.- Specified by:
savein interfaceStateMachineContextRepository<S,E, StateMachineContext<S, E>> - Parameters:
context- the contextid- the id
-
getContext
Description copied from interface:StateMachineContextRepositoryGets the context.- Specified by:
getContextin interfaceStateMachineContextRepository<S,E, StateMachineContext<S, E>> - Parameters:
id- the id- Returns:
- the context
-