Package org.axonframework.modelling
Class HierarchicalStateManager
java.lang.Object
org.axonframework.modelling.HierarchicalStateManager
- All Implemented Interfaces:
StateManager
StateManager that can load an entity from two delegates, giving preference to the child delegate and then the
parent. This is useful to encapsulate a set of repositories that are only relevant in a specific context, such as a
specific Module.
Any registrations of Repository will be done on the child StateManager.
- Since:
- 5.0.0
- Author:
- Mitchell Herrijgers
-
Method Summary
Modifier and TypeMethodDescriptionstatic HierarchicalStateManagercreate(StateManager parent, StateManager child) Creates a new hierarchicalStateManagerthat delegates to the givenparentandchildmanagers, giving preference to thechildmanager.getChild()Returns the childStateManagerof thisHierarchicalStateManager.Returns the parentStateManagerof thisHierarchicalStateManager.<I,T> CompletableFuture <ManagedEntity<I, T>> loadManagedEntity(Class<T> type, I id, ProcessingContext context) <I,T> StateManager register(Repository<I, T> repository) Registers anRepositoryfor use with thisStateManager.The types of entities that are registered with thisStateManager.registeredIdsFor(Class<?> entityType) The types of identifiers that are registered with thisStateManagerfor the givenentityType.<I,T> Repository <I, T> repository(Class<T> entityType, Class<I> idType) Returns theRepositoryfor the giventype.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.modelling.StateManager
loadEntity, register
-
Method Details
-
create
public static HierarchicalStateManager create(@Nonnull StateManager parent, @Nonnull StateManager child) Creates a new hierarchicalStateManagerthat delegates to the givenparentandchildmanagers, giving preference to thechildmanager.- Parameters:
parent- The parentStateManagerto delegate if the childStateManagercannot load the entity.child- The childStateManagerto try first.- Returns:
- A new hierarchical
StateManagerthat delegates to the given managers.
-
register
Description copied from interface:StateManagerRegisters anRepositoryfor use with thisStateManager. The combination ofRepository.entityType()andRepository.idType()must be unique for all registered repositories.- Specified by:
registerin interfaceStateManager- Type Parameters:
I- The type of id.T- The type of the entity.- Parameters:
repository- TheRepositoryto use for loading state.- Returns:
- This
StateManagerfor fluent interfacing.
-
loadManagedEntity
public <I,T> CompletableFuture<ManagedEntity<I,T>> loadManagedEntity(@Nonnull Class<T> type, @Nonnull I id, @Nonnull ProcessingContext context) Description copied from interface:StateManagerRetrieves aManagedEntityof the giventypeandid. TheCompletableFuturewill resolve to aManagedEntity, or complete exceptionally if it could not be resolved.- Specified by:
loadManagedEntityin interfaceStateManager- Type Parameters:
I- The type of the identifier of the entity.T- The type of the entity.- Parameters:
type- The type of state to retrieve.id- The id of the state to retrieve.context- Thecontextto load the entity in.- Returns:
- a
CompletableFuturewhich resolves to the entity instance.
-
registeredEntities
Description copied from interface:StateManagerThe types of entities that are registered with thisStateManager.- Specified by:
registeredEntitiesin interfaceStateManager- Returns:
- the types of entities that are registered with this
StateManager.
-
registeredIdsFor
Description copied from interface:StateManagerThe types of identifiers that are registered with thisStateManagerfor the givenentityType.- Specified by:
registeredIdsForin interfaceStateManager- Parameters:
entityType- The type of the entity.- Returns:
- the types of identifiers that are registered with this
StateManagerfor the givenentityType.
-
repository
Description copied from interface:StateManagerReturns theRepositoryfor the giventype. Returnsnullif no repository is registered for the given type and id.- Specified by:
repositoryin interfaceStateManager- Type Parameters:
I- The type of the identifier of the entity.T- The type of the entity.- Parameters:
entityType- The type of the entity.idType- The type of the identifier of the entity.- Returns:
- The
Repositoryfor the givenidTypeandentityType.
-
getParent
Returns the parentStateManagerof thisHierarchicalStateManager.- Returns:
- The parent
StateManagerof thisHierarchicalStateManager.
-
getChild
Returns the childStateManagerof thisHierarchicalStateManager.- Returns:
- The child
StateManagerof thisHierarchicalStateManager.
-