Class HierarchicalStateManager

java.lang.Object
org.axonframework.modelling.HierarchicalStateManager
All Implemented Interfaces:
StateManager

public class HierarchicalStateManager extends Object implements 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 Details

    • create

      public static HierarchicalStateManager create(@Nonnull StateManager parent, @Nonnull StateManager child)
      Creates a new hierarchical StateManager that delegates to the given parent and child managers, giving preference to the child manager.
      Parameters:
      parent - The parent StateManager to delegate if the child StateManager cannot load the entity.
      child - The child StateManager to try first.
      Returns:
      A new hierarchical StateManager that delegates to the given managers.
    • register

      public <I, T> StateManager register(@Nonnull Repository<I,T> repository)
      Description copied from interface: StateManager
      Registers an Repository for use with this StateManager. The combination of Repository.entityType() and Repository.idType() must be unique for all registered repositories.
      Specified by:
      register in interface StateManager
      Type Parameters:
      I - The type of id.
      T - The type of the entity.
      Parameters:
      repository - The Repository to use for loading state.
      Returns:
      This StateManager for 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: StateManager
      Retrieves a ManagedEntity of the given type and id. The CompletableFuture will resolve to a ManagedEntity, or complete exceptionally if it could not be resolved.
      Specified by:
      loadManagedEntity in interface StateManager
      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 - The context to load the entity in.
      Returns:
      a CompletableFuture which resolves to the entity instance.
    • registeredEntities

      public Set<Class<?>> registeredEntities()
      Description copied from interface: StateManager
      The types of entities that are registered with this StateManager.
      Specified by:
      registeredEntities in interface StateManager
      Returns:
      the types of entities that are registered with this StateManager.
    • registeredIdsFor

      public Set<Class<?>> registeredIdsFor(@Nonnull Class<?> entityType)
      Description copied from interface: StateManager
      The types of identifiers that are registered with this StateManager for the given entityType.
      Specified by:
      registeredIdsFor in interface StateManager
      Parameters:
      entityType - The type of the entity.
      Returns:
      the types of identifiers that are registered with this StateManager for the given entityType.
    • repository

      public <I, T> Repository<I,T> repository(@Nonnull Class<T> entityType, @Nonnull Class<I> idType)
      Description copied from interface: StateManager
      Returns the Repository for the given type. Returns null if no repository is registered for the given type and id.
      Specified by:
      repository in interface StateManager
      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 Repository for the given idType and entityType.
    • getParent

      public StateManager getParent()
      Returns the parent StateManager of this HierarchicalStateManager.
      Returns:
      The parent StateManager of this HierarchicalStateManager.
    • getChild

      public StateManager getChild()
      Returns the child StateManager of this HierarchicalStateManager.
      Returns:
      The child StateManager of this HierarchicalStateManager.