Class SequenceCachingEventHandlingComponent

java.lang.Object
org.axonframework.messaging.eventhandling.DelegatingEventHandlingComponent
org.axonframework.messaging.eventhandling.processing.streaming.segmenting.SequenceCachingEventHandlingComponent
All Implemented Interfaces:
DescribableComponent, MessageHandler, EventHandler, EventHandlingComponent

@Internal public class SequenceCachingEventHandlingComponent extends DelegatingEventHandlingComponent
Decorator for EventHandlingComponent. This implementation acts as a performance optimization layer by caching the results of sequence identifier calculations. Since sequence identifier computation can be expensive, this caching component reduces redundant calculations for events which sequence identifier has already been calculated within the same ProcessingContext.

The cache is stored as a resource in the ProcessingContext, ensuring that the cache is scoped to the current processing unit of work. This means the cache is automatically cleaned up when the processing context is completed.

Example usage within framework configuration:


 EventHandlingComponent component = // ... create base component
 EventHandlingComponent cachingComponent = new SequenceCachingEventHandlingComponent(component);
 
Since:
5.0.0
Author:
Mateusz Nowak
  • Constructor Details

    • SequenceCachingEventHandlingComponent

      @Internal public SequenceCachingEventHandlingComponent(@Nonnull EventHandlingComponent delegate)
      Constructs the component with given delegate to receive calls.
      Parameters:
      delegate - The EventHandlingComponent instance to delegate calls to.
  • Method Details

    • sequenceIdentifierFor

      @Nonnull public Object sequenceIdentifierFor(@Nonnull EventMessage event, @Nonnull ProcessingContext context)
      Description copied from interface: EventHandlingComponent
      Returns the sequence identifier for the given event. When two events have the same sequence identifier (as defined by their equals method), they will be executed sequentially. Important: All EventHandlers for the same QualifiedName within a single EventHandlingComponent must return the same sequence identifier for a given event. Mixing different sequence identifiers within the scope of a single EventHandlingComponent is not supported and may lead to undefined behavior.
      Specified by:
      sequenceIdentifierFor in interface EventHandlingComponent
      Overrides:
      sequenceIdentifierFor in class DelegatingEventHandlingComponent
      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.