Class AnnotationBasedEntityEvolvingComponent<E>
- Type Parameters:
E- The entity type to evolve.
- All Implemented Interfaces:
EntityEvolver<E>,EntityEvolvingComponent<E>
EntityEvolvingComponent that applies state changes through
EventHandler(-meta)-annotated methods using the
AnnotatedHandlerInspector.
During construction, this component eagerly resolves the event names of all inspected handlers and builds an immutable routing index. This shifts annotation inspection and message type resolution to initialization, increasing startup work and memory usage in proportion to the number of handlers. In return, event evolution performs direct lookups without reflection, message type resolution, cache mutation, or a scan of all handlers. Resolution failures are also reported during initialization instead of on the first matching event.
An overriding method counts as one handler and runs where the handler it overrides runs; call super to run
the overridden one. Separate methods for the same event all run, parent handlers first, each receiving the entity
returned by the previous one. Within one class the order is unspecified. If a handler returns an entity the next
handler cannot run on, evolving fails with a StateEvolvingException. Handlers of the returned type do not run
for the same event.
- Since:
- 5.0.0
- Author:
- Mateusz Nowak
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAnnotationBasedEntityEvolvingComponent(Class<E> entityType, AnnotatedHandlerInspector<E> inspector, EventConverter converter, MessageTypeResolver messageTypeResolver) Initialize a new annotation-basedEntityEvolver.AnnotationBasedEntityEvolvingComponent(Class<E> entityType, EventConverter converter, MessageTypeResolver messageTypeResolver) Deprecated, for removal: This API element is subject to removal in a future version.AnnotationBasedEntityEvolvingComponent(Class<E> entityType, EventConverter converter, MessageTypeResolver messageTypeResolver, ParameterResolverFactory parameterResolverFactory, HandlerDefinition handlerDefinition) Initialize a new annotation-basedEntityEvolver. -
Method Summary
Modifier and TypeMethodDescriptionevolve(E entity, EventMessage event, ProcessingContext context) Evolve the givenentityby applying the giveneventto it.All supportedevents, referenced through aQualifiedName.
-
Constructor Details
-
AnnotationBasedEntityEvolvingComponent
@Deprecated(since="5.3.2", forRemoval=true) public AnnotationBasedEntityEvolvingComponent(Class<E> entityType, EventConverter converter, MessageTypeResolver messageTypeResolver) Deprecated, for removal: This API element is subject to removal in a future version.in favor ofAnnotationBasedEntityEvolvingComponent(Class, EventConverter, MessageTypeResolver, ParameterResolverFactory, HandlerDefinition)since this allows for clean customization of theParameterResolverFactoryandHandlerDefinition, which this constructor does notInitialize a new annotation-basedEntityEvolver.- Parameters:
entityType- The type of entity this instance will handle state changes for.converter- The converter to use for converting event payloads to the handler's expected type.messageTypeResolver- The resolver to use for resolving the event message type.
-
AnnotationBasedEntityEvolvingComponent
public AnnotationBasedEntityEvolvingComponent(Class<E> entityType, EventConverter converter, MessageTypeResolver messageTypeResolver, ParameterResolverFactory parameterResolverFactory, HandlerDefinition handlerDefinition) Initialize a new annotation-basedEntityEvolver.- Parameters:
entityType- the type of entity this instance will handle state changes forconverter- the converter to use for converting event payloads to the handler's expected typemessageTypeResolver- the resolver to use for resolving the event message typeparameterResolverFactory- the resolver factory to use during detection of the annotated modelhandlerDefinition- the handler definition used to create concrete handlers of the annotated model
-
AnnotationBasedEntityEvolvingComponent
public AnnotationBasedEntityEvolvingComponent(Class<E> entityType, AnnotatedHandlerInspector<E> inspector, EventConverter converter, MessageTypeResolver messageTypeResolver) Initialize a new annotation-basedEntityEvolver.- Parameters:
entityType- The type of entity this instance will handle state changes for.inspector- The inspector to use to find the annotated handlers on the entity.converter- The converter to use for converting event payloads to the handler's expected type.messageTypeResolver- The resolver to use for resolving the event message type.
-
-
Method Details
-
evolve
Description copied from interface:EntityEvolverEvolve the givenentityby applying the giveneventto it.- Specified by:
evolvein interfaceEntityEvolver<E>- Parameters:
entity- The current entity to evolve with the givenevent.event- The event that might adjust theentity.context- The context within which to evolve theentityby the givenevent.- Returns:
- The evolved
entitybased on the givenevent, or the sameentitywhen nothing happened.
-
supportedEvents
Description copied from interface:EntityEvolvingComponentAll supportedevents, referenced through aQualifiedName.- Specified by:
supportedEventsin interfaceEntityEvolvingComponent<E>- Returns:
- All supported
events, referenced through aQualifiedName.
-
AnnotationBasedEntityEvolvingComponent(Class, EventConverter, MessageTypeResolver, ParameterResolverFactory, HandlerDefinition)since this allows for clean customization of theParameterResolverFactoryandHandlerDefinition, which this constructor does not