StatefulJ Persistence

StatefulJ provides different Persisters which persists State changes in an atomic, thread-safe manner. The Persisters are invoked by the StatefulJ FSM library on every State Transition prior to the invocation of the associated Action. If the Persister is unable to update the State due to staleness - it will reload a new copy of the State and retry the event.

StatefulJ provides the following Persisters:

In-Memory Persister

By default, the StatefulJ FSM library provides an in-memory Persister. This Persister updates the State field of the Entity only in the in-process memory. The updates are thread-safe; however, multiple process in different application spaces will not be aware of the State changes. Additionally, if the Entities are then being persisted to the database - this will cause problems as updates are now non-atomic.

If you need to support multiple processes or are persisting the Entities to a database, you will need to choose one of the database Persisters

JPA Persister

The JPA Persister will atomically update the State of the Entity in a SQL Database. The JPA Persister is dependent upon a correctly configured Entity Manager and will automatically assume the scope of an existing Transaction (it doesn’t start a new Transaction).

Maven

	<dependency>
		<groupId>org.statefulj.persistence</groupId>
		<artifactId>statefulj-persistence-jpa</artifactId>
		<version>3.0</version>
	</dependency>	

Setup

Note

If you are utilizing the StatefulJ Framework Persisters, then you will not need to explicitly include the JPA library - it’s included as a dependency of the Framework.

Mongo Persister

The Mongo Persister will atomically update the State of the Entity in a Mongo Database. The Mongo Persister is dependent upon a Spring Data MongoDB. The Persiter requires that Entity have a MongoRepository defined for the Entity. The MongoRepository.

Maven

	<dependency>
		<groupId>org.statefulj.persistence</groupId>
		<artifactId>statefulj-persistence-mongo</artifactId>
		<version>3.0</version>
	</dependency>	

Note

If you are utilizing the StatefulJ Framework Persisters, then you will not need to explicitly include the Mongo library - it’s included as a dependency of the Framework.