Class SimpleEventHandlingComponent
- All Implemented Interfaces:
DescribableComponent,MessageHandler,EventHandler,EventHandlerRegistry<SimpleEventHandlingComponent>,EventHandlingComponent,ReplayStatusChangedHandler,ReplayStatusChangedHandlerRegistry<SimpleEventHandlingComponent>,ResetHandler,ResetHandlerRegistry<SimpleEventHandlingComponent>
EventHandlingComponent, EventHandlerRegistry, and
ResetHandlerRegistry.
As such, it contains a collection of EventHandlers to invoke on
handle, and a set of ResetHandlers to invoke on
reset.
- Since:
- 5.0.0
- Author:
- Steven van Beelen
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSimpleEventHandlingComponent(String name, SequencingPolicy<? super EventMessage> sequencingPolicy) -
Method Summary
Modifier and TypeMethodDescriptionstatic SimpleEventHandlingComponentInstantiates a simpleEventHandlingComponentthat is able to handle events and delegate them to subcomponents.static SimpleEventHandlingComponentcreate(String name, SequencingPolicy<? super EventMessage> sequencingPolicy) Instantiates a simpleEventHandlingComponentthat is able to handle events and delegate them to subcomponents, using the givensequencingPolicyto decide how to sequence incoming events.voiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.handle(EventMessage event, ProcessingContext context) Handles the giveneventwithin the givencontext.handle(ReplayStatusChanged statusChange, ProcessingContext context) Handles the givenReplayStatusChangedmessage, allowing for tasks to be performed when thereplay startsandends.handle(ResetContext resetContext, ProcessingContext context) Handles the givenResetContextmessage, performing any necessary reset operations.sequenceIdentifierFor(EventMessage event, ProcessingContext context) Returns the sequence identifier for the givenevent.subscribe(Set<QualifiedName> names, EventHandler handler) subscribe(QualifiedName name, EventHandler handler) subscribe(ReplayStatusChangedHandler replayStatusChangedHandler) Subscribes a replay status changed handler to this registry.subscribe(ResetHandler resetHandler) Subscribes a reset handler to this registry.All supportedevents, referenced through aQualifiedName.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.eventhandling.EventHandlerRegistry
subscribeMethods inherited from interface org.axonframework.messaging.eventhandling.EventHandlingComponent
supports, supportsReset
-
Constructor Details
-
SimpleEventHandlingComponent
protected SimpleEventHandlingComponent(String name, SequencingPolicy<? super EventMessage> sequencingPolicy)
-
-
Method Details
-
create
Instantiates a simpleEventHandlingComponentthat is able to handle events and delegate them to subcomponents.Uses a default sequencing policy that will first try for the
SequentialPerAggregatePolicy, falling back to theSequentialPolicywhen the former returns no sequence value.- Parameters:
name- The name of the component, used fordescribingthe component.- Returns:
- A simple
EventHandlingComponentinstance with the givenname.
-
create
public static SimpleEventHandlingComponent create(String name, SequencingPolicy<? super EventMessage> sequencingPolicy) Instantiates a simpleEventHandlingComponentthat is able to handle events and delegate them to subcomponents, using the givensequencingPolicyto decide how to sequence incoming events.- Parameters:
name- The name of the component, used fordescribingthe component.sequencingPolicy- TheSequencingPolicyto use for sequencing events through, for example,sequenceIdentifierFor(EventMessage, ProcessingContext).- Returns:
- A simple
EventHandlingComponentinstance with the givenname.
-
handle
Description copied from interface:EventHandler- Specified by:
handlein interfaceEventHandler- Parameters:
event- The event to handle.context- The context to the giveneventis handled in.- Returns:
- An
empty streamcontaining nothing.
-
subscribe
Description copied from interface:EventHandlerRegistrySubscribe the givenhandlerforeventsof the givennames.If a subscription already exists for any
namein the given set, the behavior is undefined. Implementations may throw an exception to refuse duplicate subscription or alternatively decide whether the existing or newhandlergets the subscription.- Specified by:
subscribein interfaceEventHandlerRegistry<SimpleEventHandlingComponent>- Parameters:
names- The names of the givencommandHandlercan handle.handler- The handler instance that handleseventsfor the given names.- Returns:
- This registry for fluent interfacing.
-
subscribe
Description copied from interface:EventHandlerRegistrySubscribe the givenhandlerforeventsof the givenname.If a subscription already exists for the
name, the behavior is undefined. Implementations may throw an exception to refuse duplicate subscription or alternatively decide whether the existing or newhandlergets the subscription.- Specified by:
subscribein interfaceEventHandlerRegistry<SimpleEventHandlingComponent>- Parameters:
name- The name the givencommandHandlercan handle.handler- The handler instance that handleseventsfor the given name.- Returns:
- This registry for fluent interfacing.
-
supportedEvents
Description copied from interface:EventHandlingComponentAll supportedevents, referenced through aQualifiedName.- Specified by:
supportedEventsin interfaceEventHandlingComponent- Returns:
- All supported
events, referenced through aQualifiedName.
-
sequenceIdentifierFor
Returns the sequence identifier for the givenevent. When two events have the same sequence identifier (as defined by their equals method), they will be executed sequentially. Important: AllEventHandlersfor the sameQualifiedNamewithin a singleEventHandlingComponentmust return the same sequence identifier for a given event. Mixing different sequence identifiers within the scope of a singleEventHandlingComponentis not supported and may lead to undefined behavior.The implementation automatically chooses the appropriate sequencing policy based on the event context:
- If the aggregate identifier is present in the
ProcessingContext(i.e., the event is an aggregate event), it usesSequentialPerAggregatePolicyto ensure events for the same aggregate are processed sequentially while allowing concurrent processing of events from different aggregates. - If no aggregate identifier is present (i.e., the event is not an aggregate event), it uses
SequentialPolicywhich ensures all events are processed sequentially (no concurrency) as the safest default option.
Override this method to provide custom sequencing behavior. Or use a
SequenceOverridingEventHandlingComponentif you cannot inherit from a certainEventHandlingComponentimplementation.- Specified by:
sequenceIdentifierForin interfaceEventHandlingComponent- Parameters:
event- The event for which to get the sequencing identifier.context- The processing context in which the event is being handled.- Returns:
- A sequence identifier for the given event.
- If the aggregate identifier is present in the
-
handle
Description copied from interface:ResetHandlerHandles the givenResetContextmessage, performing any necessary reset operations.This method is invoked before the processor begins replaying events. Handlers typically use this opportunity to clean up state that will be rebuilt during replay.
If this method completes exceptionally, the reset operation will be aborted and no replay will occur.
- Specified by:
handlein interfaceResetHandler- Parameters:
resetContext- The reset context message containing reset information and optional payload.context- The processing context for this operation.- Returns:
- An empty message stream after handling completes successfully.
-
subscribe
Description copied from interface:ResetHandlerRegistrySubscribes a reset handler to this registry. The handler will be invoked when a reset operation is triggered.Multiple handlers can be subscribed, and all will be invoked during reset.
- Specified by:
subscribein interfaceResetHandlerRegistry<SimpleEventHandlingComponent>- Parameters:
resetHandler- the reset handler to subscribe, must not benull- Returns:
- This registry instance for method chaining.
-
handle
public MessageStream.Empty<Message> handle(ReplayStatusChanged statusChange, ProcessingContext context) Description copied from interface:ReplayStatusChangedHandlerHandles the givenReplayStatusChangedmessage, allowing for tasks to be performed when thereplay startsandends.This method is invoked on the moment the
ReplayStatusis about to change as part of the event handlingProcessingContext. In doing so, this handler has two concrete moments when it is invoked:- When the
ReplayStatuschanges fromReplayStatus.REGULARtoReplayStatus.REPLAY, exactly before the first replayed event is processed - When the
ReplayStatuschanges fromReplayStatus.REPLAYtoReplayStatus.REGULAR, exactly after processing the final event of the replay
If this operation returns a
failed MessageStream, event handling that occurs within the givencontextis impacted. The failure will be passed to theErrorHandler, typically resulting in a rollback of the invoked event handling tasks.- Specified by:
handlein interfaceEventHandlingComponent- Specified by:
handlein interfaceReplayStatusChangedHandler- Parameters:
statusChange- the replay status context message containing replay status informationcontext- the processing context for this operation- Returns:
- an empty message stream after handling completes successfully
- When the
-
subscribe
public SimpleEventHandlingComponent subscribe(ReplayStatusChangedHandler replayStatusChangedHandler) Description copied from interface:ReplayStatusChangedHandlerRegistrySubscribes a replay status changed handler to this registry.The handler will be invoked when the
ReplayStatuschanged. Multiple handlers can be subscribed, and all will be invoked when the replay status changes.- Specified by:
subscribein interfaceReplayStatusChangedHandlerRegistry<SimpleEventHandlingComponent>- Parameters:
replayStatusChangedHandler- the replay status changed handler to subscribe, must not benull- Returns:
- this registry instance for method chaining
-
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.
-