Class CachingSagaStore<T>
- Type Parameters:
T- The saga type
- All Implemented Interfaces:
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.
This decorator is not transaction aware, exactly as it was in Axon Framework 4, and two consequences follow that a
caller has to account for. A unit of work that rolls back leaves behind whatever it wrote to these caches, since
nothing compensates for it, so the caches keep serving state the delegate SagaStore discarded until the
entries are evicted for other reasons. And because every change lands immediately, a concurrently running unit of
work can read state out of these shared caches that the delegate has not committed yet.
Applications that cannot accept either exposure should size the caches for their tolerance, or run without this decorator.
- Since:
- 2.0
- Author:
- Allard Buijze
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.axonframework.modelling.saga.repository.SagaStore
SagaStore.Entry<T> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCachingSagaStore(CachingSagaStore.Builder<T> builder) Instantiate aCachingSagaStorebased on the fields contained in theCachingSagaStore.Builder. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddCachedAssociations(Iterable<AssociationValue> associationValues, String sagaIdentifier, Class<?> sagaType) Registers the associations of a saga with givensagaIdentifierand givensagaTypewith the associations cache.static <T> CachingSagaStore.Builder<T> builder()Instantiate a Builder to be able to create aCachingSagaStore.voiddeleteSaga(Class<? extends T> sagaType, String sagaIdentifier, Set<AssociationValue> associationValues) Deletes a Saga with givensagaTypeandsagaIdentifierand all its associations.findSagas(Class<? extends T> sagaType, AssociationValue associationValue) Returns identifiers of saga instances of the givensagaTypethat have been associated with the givenassociationValue.voidinsertSaga(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>
@Nullable SagaStore.Entry<S> voidupdateSaga(Class<? extends T> sagaType, String sagaIdentifier, T saga, AssociationValues associationValues) Updates a given Saga after its state was modified, applying the association values added and removed since it was last stored.
-
Constructor Details
-
CachingSagaStore
Instantiate aCachingSagaStorebased on the fields contained in theCachingSagaStore.Builder.Will assert that the
delegateSagaStore, SagaassociationsCacheandsagaCacheare notnull, and will throw anAxonConfigurationExceptionif any of them isnull.- Parameters:
builder- theCachingSagaStore.Builderused to instantiate aCachingSagaStoreinstance
-
-
Method Details
-
builder
Instantiate a Builder to be able to create aCachingSagaStore.The
delegateSagaStoreof typeSagaStore, theassociationsCacheandsagaCache(both of typeCache) are hard requirements and as such should be provided.- Type Parameters:
T- a generic specifying the Saga type contained in thisSagaStoreimplementation- Returns:
- a Builder to be able to create a
CachingSagaStore
-
findSagas
Description copied from interface:SagaStoreReturns identifiers of saga instances of the givensagaTypethat have been associated with the givenassociationValue. -
loadSaga
public <S extends T> @Nullable SagaStore.Entry<S> loadSaga(Class<S> sagaType, String sagaIdentifier) Description copied from interface:SagaStoreLoads a known sagaSagaStore.Entryinstance with givensagaTypeand uniquesagaIdentifier.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
nullin case a Saga doesn't exists, as opposed to throwing an exception. -
insertSaga
public void insertSaga(Class<? extends T> sagaType, String sagaIdentifier, T saga, Set<AssociationValue> associationValues) Description copied from interface:SagaStoreAdds a new Saga and its initial association values to the store.- Specified by:
insertSagain interfaceSagaStore<T>- Parameters:
sagaType- The type of the SagasagaIdentifier- The identifier of the Sagasaga- The Saga instanceassociationValues- The initial association values of the Saga
-
deleteSaga
public void deleteSaga(Class<? extends T> sagaType, String sagaIdentifier, Set<AssociationValue> associationValues) Description copied from interface:SagaStoreDeletes a Saga with givensagaTypeandsagaIdentifierand 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.- Specified by:
deleteSagain interfaceSagaStore<T>- Parameters:
sagaType- The type of saga to deletesagaIdentifier- The identifier of the saga to deleteassociationValues- The known associations of the saga
-
addCachedAssociations
protected void addCachedAssociations(Iterable<AssociationValue> associationValues, String sagaIdentifier, Class<?> sagaType) Registers the associations of a saga with givensagaIdentifierand givensagaTypewith the associations cache.- Parameters:
associationValues- the association values of the sagasagaIdentifier- the identifier of the sagasagaType- the type of the saga
-
updateSaga
public void updateSaga(Class<? extends T> sagaType, String sagaIdentifier, T saga, AssociationValues associationValues) Description copied from interface:SagaStoreUpdates a given Saga after its state was modified, applying the association values added and removed since it was last stored.- Specified by:
updateSagain interfaceSagaStore<T>- Parameters:
sagaType- The type of the SagasagaIdentifier- The identifier of the Sagasaga- The Saga instanceassociationValues- The association values of the Saga, carrying the additions and removals to apply
-