org.axonframework.saga.repository
Class CachingSagaRepository

java.lang.Object
  extended by org.axonframework.saga.repository.CachingSagaRepository
All Implemented Interfaces:
SagaRepository

public class CachingSagaRepository
extends Object
implements SagaRepository

Saga Repository implementation that adds caching behavior to the repository it wraps. Both associations and sagas are cached, making loading them faster. Commits and adds are always delegated to the wrapped repository. Loads are only delegated if the cache does not contain the necessary entries.

Updating associations involves a read and a write, which are performed atomically. Therefore, it is unsafe to add or remove specific associations outside of this instance. Obviously, clearing and evictions are safe.

Since:
2.0
Author:
Allard Buijze

Constructor Summary
CachingSagaRepository(SagaRepository delegate, Cache associationsCache, Cache sagaCache)
          Initializes an instance delegating to the given delegate, storing associations in the given associationsCache and Saga instances in the given sagaCache.
 
Method Summary
 void add(Saga saga)
          Registers a newly created Saga with the Repository.
 void commit(Saga saga)
          Commits the changes made to the Saga instance.
 Set<String> find(Class<? extends Saga> type, AssociationValue associationValue)
          Find saga instances of the given type that have been associated with the given associationValue.
 Saga load(String sagaIdentifier)
          Loads a known Saga instance by its unique identifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingSagaRepository

public CachingSagaRepository(SagaRepository delegate,
                             Cache associationsCache,
                             Cache sagaCache)
Initializes an instance delegating to the given delegate, storing associations in the given associationsCache and Saga instances in the given sagaCache.

Parameters:
delegate - The repository instance providing access to (persisted) entries
associationsCache - The cache to store association information is
sagaCache - The cache to store Saga instances in
Method Detail

find

public Set<String> find(Class<? extends Saga> type,
                        AssociationValue associationValue)
Description copied from interface: SagaRepository
Find saga instances of the given type that have been associated with the given associationValue.

Returned Sagas must be committed after processing.

Specified by:
find in interface SagaRepository
Parameters:
type - The type of Saga to return
associationValue - The value that the returned Sagas must be associated with
Returns:
A Set containing the found Saga instances. If none are found, an empty Set is returned. Will never return null.

load

public Saga load(String sagaIdentifier)
Description copied from interface: SagaRepository
Loads a known Saga instance by its unique identifier. Returned Sagas must be committed after processing. 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.

Specified by:
load in interface SagaRepository
Parameters:
sagaIdentifier - The unique identifier of the Saga to load
Returns:
The Saga instance, or null if no such saga exists

commit

public void commit(Saga saga)
Description copied from interface: SagaRepository
Commits the changes made to the Saga instance. At this point, the repository may release any resources kept for this saga. If the committed saga is marked inActive (Saga.isActive() returns false), the repository should delete the saga from underlying storage and remove all stored association values associated with that Saga.

Implementations *may* (temporarily) return a cached version of the Saga, which is marked inactive.

Specified by:
commit in interface SagaRepository
Parameters:
saga - The Saga instance to commit

add

public void add(Saga saga)
Description copied from interface: SagaRepository
Registers a newly created Saga with the Repository. Once a Saga instance has been added, it can be found using its association values or its unique identifier.

Note that if the added Saga is marked inActive (Saga.isActive() returns false), it is not stored.

Specified by:
add in interface SagaRepository
Parameters:
saga - The Saga instances to add.


Copyright © 2010-2016. All Rights Reserved.