T
- The saga typepublic class CachingSagaStore<T> extends Object implements SagaStore<T>
Updating associations involves a read and write, which are performed atomically. Therefore, it is unsafe to add or remove specific associations outside this instance. Obviously, clearing and evictions are safe.
Modifier and Type | Class and Description |
---|---|
static class |
CachingSagaStore.Builder<T>
Builder class to instantiate a
CachingSagaStore . |
SagaStore.Entry<T>
Modifier | Constructor and Description |
---|---|
protected |
CachingSagaStore(CachingSagaStore.Builder<T> builder)
Instantiate a
CachingSagaStore based on the fields contained in the CachingSagaStore.Builder . |
Modifier and Type | Method and Description |
---|---|
protected void |
addCachedAssociations(Iterable<AssociationValue> associationValues,
String sagaIdentifier,
Class<?> sagaType)
Registers the associations of a saga with given
sagaIdentifier and given sagaType with the
associations cache. |
static <T> CachingSagaStore.Builder<T> |
builder()
Instantiate a Builder to be able to create a
CachingSagaStore . |
void |
deleteSaga(Class<? extends T> sagaType,
String sagaIdentifier,
Set<AssociationValue> associationValues)
Deletes a Saga with given
sagaType and sagaIdentifier and all its associations. |
Set<String> |
findSagas(Class<? extends T> sagaType,
AssociationValue associationValue)
Returns identifiers of saga instances of the given
sagaType that have been associated with the given
associationValue . |
void |
insertSaga(Class<? extends T> sagaType,
String sagaIdentifier,
T saga,
Set<AssociationValue> associationValues)
Adds a new Saga and its initial association values to the store.
|
<S extends T> |
loadSaga(Class<S> sagaType,
String sagaIdentifier)
|
void |
updateSaga(Class<? extends T> sagaType,
String sagaIdentifier,
T saga,
AssociationValues associationValues)
Updates a given Saga after its state was modified.
|
protected CachingSagaStore(CachingSagaStore.Builder<T> builder)
CachingSagaStore
based on the fields contained in the CachingSagaStore.Builder
.
Will assert that the delegate
SagaStore
, Saga associationsCache
and sagaCache
are
not null
, and will throw an AxonConfigurationException
if any of them is null
.
builder
- the CachingSagaStore.Builder
used to instantiate a CachingSagaStore
instancepublic static <T> CachingSagaStore.Builder<T> builder()
CachingSagaStore
.
The delegateSagaStore
of type SagaStore
, the associationsCache
and sagaCache
(both of type Cache
) are hard requirements and as such should be provided.
T
- a generic specifying the Saga type contained in this SagaRepository
implementationCachingSagaStore
public Set<String> findSagas(Class<? extends T> sagaType, AssociationValue associationValue)
SagaStore
sagaType
that have been associated with the given
associationValue
.public <S extends T> SagaStore.Entry<S> loadSaga(Class<S> sagaType, String sagaIdentifier)
SagaStore
SagaStore.Entry
instance with given sagaType
and unique sagaIdentifier
.
Due to the concurrent nature of Sagas, it is not unlikely for a Saga to have ceased to exist after it has been
found based on associations. Therefore, a repository should return null
in case a Saga doesn't
exists, as opposed to throwing an exception.
public void insertSaga(Class<? extends T> sagaType, String sagaIdentifier, T saga, Set<AssociationValue> associationValues)
SagaStore
token
may be null
if the Saga is not tracking the event store.insertSaga
in interface SagaStore<T>
sagaType
- The type of the SagasagaIdentifier
- The identifier of the Sagasaga
- The Saga instanceassociationValues
- The initial association values of the Sagapublic void deleteSaga(Class<? extends T> sagaType, String sagaIdentifier, Set<AssociationValue> associationValues)
SagaStore
sagaType
and sagaIdentifier
and all its associations. For convenience
all known association values are passed along as well, which has the advantage that the saga store is not
required to keep an index of association value to saga identifier.deleteSaga
in interface SagaStore<T>
sagaType
- The type of saga to deletesagaIdentifier
- The identifier of the saga to deleteassociationValues
- The known associations of the sagaprotected void addCachedAssociations(Iterable<AssociationValue> associationValues, String sagaIdentifier, Class<?> sagaType)
sagaIdentifier
and given sagaType
with the
associations cache.associationValues
- the association values of the sagasagaIdentifier
- the identifier of the sagasagaType
- the type of the sagapublic void updateSaga(Class<? extends T> sagaType, String sagaIdentifier, T saga, AssociationValues associationValues)
SagaStore
token
may be null
if the Saga is not tracking the
event store.updateSaga
in interface SagaStore<T>
sagaType
- The type of the SagasagaIdentifier
- The identifier of the Sagasaga
- The Saga instanceassociationValues
- The initial association values of the SagaCopyright © 2010–2024. All rights reserved.