org.axonframework.saga.repository
Class AbstractSagaRepository

java.lang.Object
  extended by org.axonframework.saga.repository.AbstractSagaRepository
All Implemented Interfaces:
SagaRepository
Direct Known Subclasses:
JpaSagaRepository

public abstract class AbstractSagaRepository
extends Object
implements SagaRepository

Abstract implementation for saga repositories. This (partial) implementation will take care of the uniqueness of saga instances in the JVM. That means it will prevent multiple instances of the same conceptual Saga (i.e. with same identifier) to exist within the JVM.

Since:
0.7
Author:
Allard Buijze

Constructor Summary
AbstractSagaRepository()
           
 
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.
<T extends Saga>
Set<T>
find(Class<T> type, Set<AssociationValue> associationValues)
          Find saga instances of the given type that have been associated with the given associationValue.
protected  AssociationValueMap getAssociationValueMap()
          Returns the AssociationValueMap containing the mappings of AssociationValue to Saga.
protected  SagaCache getSagaCache()
          Returns the SagaCache used to prevent multiple instances of the same conceptual Saga (i.e. with same identifier) from being active in the JVM.
<T extends Saga>
T
load(Class<T> type, String sagaIdentifier)
          Loads a known Saga instance by its unique identifier.
protected abstract
<T extends Saga>
T
loadSaga(Class<T> type, String sagaIdentifier)
          Loads a known Saga instance by its unique identifier.
 void purgeCache()
          Remove all elements from the cache pointing to Saga instances that have been garbage collected.
protected abstract  void removeAssociationValue(AssociationValue associationValue, String sagaIdentifier)
          Removes the association value that has been associated with Saga, identified with the given sagaIdentifier.
protected abstract  void storeAssociationValue(AssociationValue associationValue, String sagaIdentifier)
          Store the given associationValue, which has been associated with given sagaIdentifier.
protected abstract  void storeSaga(Saga saga)
          Stores a newly created Saga instance.
protected abstract  void updateSaga(Saga saga)
          Update a stored Saga, by replacing it with the given saga instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSagaRepository

public AbstractSagaRepository()
Method Detail

find

public <T extends Saga> Set<T> find(Class<T> type,
                                    Set<AssociationValue> associationValues)
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
Type Parameters:
T - The type of Saga to return
Parameters:
type - The type of Saga to return
associationValues - 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 <T extends Saga> T load(Class<T> type,
                               String sagaIdentifier)
Description copied from interface: SagaRepository
Loads a known Saga instance by its unique identifier. Returned Sagas must be committed after processing.

Specified by:
load in interface SagaRepository
Type Parameters:
T - The expected type of Saga
Parameters:
type - The expected type of Saga
sagaIdentifier - The unique identifier of the Saga to load
Returns:
The Saga instance

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.

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

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.

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

loadSaga

protected abstract <T extends Saga> T loadSaga(Class<T> type,
                                               String sagaIdentifier)
Loads a known Saga instance by its unique identifier. Implementations are encouraged, but not required to return the same instance when two Sagas with equal identifiers are loaded.

Type Parameters:
T - The expected type of Saga
Parameters:
type - The expected type of Saga
sagaIdentifier - The unique identifier of the Saga to load
Returns:
The Saga instance
Throws:
NoSuchSagaException - if no Saga with given identifier can be found

updateSaga

protected abstract void updateSaga(Saga saga)
Update a stored Saga, by replacing it with the given saga instance.

Parameters:
saga - The saga that has been modified and needs to be updated in the storage

storeSaga

protected abstract void storeSaga(Saga saga)
Stores a newly created Saga instance.

Parameters:
saga - The newly created Saga instance to store.

storeAssociationValue

protected abstract void storeAssociationValue(AssociationValue associationValue,
                                              String sagaIdentifier)
Store the given associationValue, which has been associated with given sagaIdentifier.

Parameters:
associationValue - The association value to store
sagaIdentifier - The saga related to the association value

removeAssociationValue

protected abstract void removeAssociationValue(AssociationValue associationValue,
                                               String sagaIdentifier)
Removes the association value that has been associated with Saga, identified with the given sagaIdentifier.

Parameters:
associationValue - The value to remove as association value for the given saga
sagaIdentifier - The identifier of the Saga to remove the association from

getAssociationValueMap

protected AssociationValueMap getAssociationValueMap()
Returns the AssociationValueMap containing the mappings of AssociationValue to Saga.

Returns:
the AssociationValueMap containing the mappings of AssociationValue to Saga

getSagaCache

protected SagaCache getSagaCache()
Returns the SagaCache used to prevent multiple instances of the same conceptual Saga (i.e. with same identifier) from being active in the JVM.

Returns:
the saga cache

purgeCache

public void purgeCache()
Remove all elements from the cache pointing to Saga instances that have been garbage collected.



Copyright © 2011. All Rights Reserved.