Class SimpleStateManager
- All Implemented Interfaces:
DescribableComponent,StateManager
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 Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.<I,T> CompletableFuture <ManagedEntity<I, T>> loadManagedEntity(Class<T> entityType, I id, ProcessingContext context) static StateManagerCreates a newSimpleStateManagerwith the givenname.<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
-
named
Creates a newSimpleStateManagerwith the givenname.- Parameters:
name- The name of the state manager, used for describing the component.- Returns:
- A new
SimpleStateManagerwith 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: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:
entityType- 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.
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods 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
DescribableComponentimplementation 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 thedescribeTomethod, 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:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-
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.
-