The persistence layer typeclass for a given state class A
that provides methods to store and retrieve instances of type A
from and to a specific storage backend.
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
Members list
Value members
Abstract methods
Clears/resets the internal data structures used by the storage backend if not already created.
Clears/resets the internal data structures used by the storage backend if not already created.
Attributes
- Returns
-
an
IO[Unit]
Create and initialize the internal data structures used by the storage backend if not already created.
Create and initialize the internal data structures used by the storage backend if not already created.
Note: It is guaranteed that this operation will not truncate/clear the underlying storage, but just create it in case it does not already exist. If you need to clear the storage, use method clear instead.
Attributes
- Returns
-
an
IO[Unit]
Drops the internal data structures used by the storage backend.
Drops the internal data structures used by the storage backend.
Attributes
- Returns
-
an
IO[Unit]
Reads the current encoded (serialized) state for a given persistenceId
from the storage backend.
Reads the current encoded (serialized) state for a given persistenceId
from the storage backend.
Value parameters
- persistenceId
-
The PersistenceId of the encoded state instance to read
Attributes
- Returns
-
Some
EncodedState if the entry exists in the storage backend, elseNone
Writes (creates or replaces) an encoded (serialized) state for a given persistenceId
into the storage backend.
Writes (creates or replaces) an encoded (serialized) state for a given persistenceId
into the storage backend.
The method will fail if the revision of new encoded state is not exactly the successor of the revision of the current encoded state, i.e., newRevision == currentRevision + 1
. This ensures that there is no collision with persistence IDs that have accidentally been used multiple times.
Implementation note: The revision check could have easily been put into the generic write method. This would have eliminated the need to do the logic in each implementation of writeEncodedState, but it would also have eliminated the possibility to do the logic more efficient. This is why the decision was made to do it here for each implementation.
Value parameters
- encodedState
-
The state instance of type EncodedState
- persistenceId
-
The PersistenceId of the encoded state instance to write
Attributes
- Returns
-
IO[Unit]
Concrete methods
Reads the current revision of the DurableState for payload type S
from storage backend.
Reads the current revision of the DurableState for payload type S
from storage backend.
Type parameters
- S
-
The state's payload type
Value parameters
- payloadCodec
-
a given PayloadCodec to convert DurableState instances of payload type
S
to a byte array and vice versa - persistenceId
-
The PersistenceId of the durable state instance to read
Attributes
- Returns
-
Some
DurableState if the entry exists in the storage backend, elseNone
Writes a new revision of the DurableState for payload type S
into the storage backend.
Writes a new revision of the DurableState for payload type S
into the storage backend.
The method will fail if the revision of new encoded state is not exactly the successor of the revision of the current encoded state, i.e., newRevision == currentRevision + 1
. This ensures that there is no collision with persistence IDs that have accidentally been used multiple times.
Type parameters
- S
-
The state's payload type
Value parameters
- payloadCodec
-
a given PayloadCodec to convert DurableState instances of payload type
S
to a byte array and vice versa - persistenceId
-
The PersistenceId of the durable state instance to write
- state
-
The DurableState of payload type
S
Attributes
- Returns
-
An
IO[Unit]