Class InitializingEntityEvolver<I,E>
- Type Parameters:
I- the type of the identifier of the entity to createE- the type of the entity to create
- All Implemented Interfaces:
DescribableComponent
EventSourcedEntityFactory and an EntityEvolver
to ensure an entity exists and apply state transitions.
If the given entity is null, a new instance is created using the
factory. The resulting entity is then passed to the evolver to apply the
given event (if any).
This effectively provides "initialize or evolve" semantics.
- Since:
- 5.1.0
- Author:
- John Hendrikx
-
Constructor Summary
ConstructorsConstructorDescriptionInitializingEntityEvolver(EventSourcedEntityFactory<I, E> entityFactory, EntityEvolver<E> entityEvolver) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.evolve(I identifier, @Nullable E entity, EventMessage message, ProcessingContext context) Initializes or evolves the given entity using the given message.initialize(I identifier, ProcessingContext context) Creates an empty entityE.
-
Constructor Details
-
InitializingEntityEvolver
public InitializingEntityEvolver(EventSourcedEntityFactory<I, E> entityFactory, EntityEvolver<E> entityEvolver) Creates a new instance.- Parameters:
entityFactory- anEventSourcedEntityFactory, cannot benullentityEvolver- anEntityEvolver, cannot benull
-
-
Method Details
-
initialize
Creates an empty entityE.- Parameters:
identifier- the entity's identifier, cannot benullcontext- aProcessingContext, cannot benull- Returns:
- a new entity of type
E
-
evolve
Initializes or evolves the given entity using the given message. If the entity isnull, creates the entity using the given message, otherwise evolves it.- Parameters:
identifier- the entity's identifier, cannot benullentity- the current state, can benullmessage- an event message to initialize or evolve the entity with, cannot benullcontext- aProcessingContext, cannot benull- Returns:
- an entity in its new state, never
null
-
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.
-