Class SequenceOverridingEventHandlingComponent
- All Implemented Interfaces:
DescribableComponent,MessageHandler,EventHandler,EventHandlingComponent
EventHandlingComponent that uses a configurable SequencingPolicy to
determine the sequence identifier for events, while delegating all other operations to an underlying
EventHandlingComponent.
This component first attempts to determine sequence identification using the configured sequencing policy. If the
policy returns Optional.empty(), only then it falls back to the delegate component's sequence identifier.
This allows for overriding the sequencing behavior of the underlying component.
- Since:
- 5.0.0
- Author:
- Mateusz Nowak
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSequenceOverridingEventHandlingComponent(SequencingPolicy sequencingPolicy, EventHandlingComponent delegate) Creates a newSequenceOverridingEventHandlingComponentthat uses the givensequencingPolicyto override sequence identification while delegating all other operations to thedelegatecomponent. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.handle(EventMessage event, ProcessingContext context) Handles the giveneventwithin the givencontext.sequenceIdentifierFor(EventMessage event, ProcessingContext context) Returns the sequence identifier for the givenevent.All supportedevents, referenced through aQualifiedName.booleansupports(QualifiedName eventName) Checks whether the giveneventNameis supported by this component.
-
Constructor Details
-
SequenceOverridingEventHandlingComponent
public SequenceOverridingEventHandlingComponent(@Nonnull SequencingPolicy sequencingPolicy, @Nonnull EventHandlingComponent delegate) Creates a newSequenceOverridingEventHandlingComponentthat uses the givensequencingPolicyto override sequence identification while delegating all other operations to thedelegatecomponent.- Parameters:
sequencingPolicy- The policy to use for determining sequence identifiers for events.delegate- The underlying event handling component to delegate operations to.
-
-
Method Details
-
sequenceIdentifierFor
@Nonnull public Object sequenceIdentifierFor(@Nonnull EventMessage event, @Nonnull ProcessingContext context) Description copied from interface:EventHandlingComponentReturns 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.- 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.
-
supportedEvents
Description copied from interface:EventHandlingComponentAll supportedevents, referenced through aQualifiedName.- Specified by:
supportedEventsin interfaceEventHandlingComponent- Returns:
- All supported
events, referenced through aQualifiedName.
-
supports
Description copied from interface:EventHandlingComponentChecks whether the giveneventNameis supported by this component.- Specified by:
supportsin interfaceEventHandlingComponent- Parameters:
eventName- The name of the event to check for support.- Returns:
trueif the giveneventNameis supported,falseotherwise.
-
handle
@Nonnull public MessageStream.Empty<Message> handle(@Nonnull EventMessage event, @Nonnull ProcessingContext context) 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.
-
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.
-