Class SimpleStateManager

java.lang.Object
org.axonframework.modelling.SimpleStateManager
All Implemented Interfaces:
DescribableComponent, StateManager

public class SimpleStateManager extends Object implements StateManager, DescribableComponent
Simple implementation of the StateManager. Keeps a list of all registered repositories and delegates the loading of entities to the appropriate repository through the use of Repository.loadOrCreate(Object, ProcessingContext). Throws a MissingRepositoryException if no repository is found for the given entity type and the provided id.
Since:
5.0.0
Author:
Mitchell Herrijgers
See Also:
  • Method Details

    • named

      public static StateManager named(@Nonnull String name)
      Creates a new SimpleStateManager with the given name.
      Parameters:
      name - The name of the state manager, used for describing the component.
      Returns:
      A new SimpleStateManager with the given name.
    • loadManagedEntity

      @Nonnull public <I, T> CompletableFuture<ManagedEntity<I,T>> loadManagedEntity(@Nonnull Class<T> entityType, @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:
      entityType - 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.
    • describeTo

      public void describeTo(@Nonnull ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.

      Best Practices: As a general rule, all relevant fields of a DescribableComponent implementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing the describeTo method, who should focus on providing information that is useful for understanding the component's configuration and state.

      Example implementation:

       public void describeTo(ComponentDescriptor descriptor) {
           descriptor.describeProperty("name", this.name);
           descriptor.describeProperty("enabled", this.enabled);
           descriptor.describeProperty("configuration", this.configuration); // A nested component
           descriptor.describeProperty("handlers", this.eventHandlers);      // A collection
       }
       
      Specified by:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.
    • 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.