Class SimpleStateManager

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

public class SimpleStateManager extends Object implements StateManager
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). Completes the returned CompletableFuture exceptionally with 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(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

      public <I, T> CompletableFuture<ManagedEntity<I,T>> loadManagedEntity(Class<T> entityType, I id, 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, or completes exceptionally with a MissingRepositoryException when this StateManager does not control the Repository to load the ManagedEntity from
    • 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(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> @Nullable Repository<I,T> repository(Class<T> entityType, 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.

      Unlike StateManager.loadManagedEntity(Class, Object, ProcessingContext), which resolves a Repository registered for a supertype when asked for a subtype, this method only matches an exactly registered (entityType, idType) pair. Hence, there is no supertype or subtype resolution.

      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(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(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