Class InterceptingEventSink
- All Implemented Interfaces:
DescribableComponent,EventSink
EventSink intercepting all events before they are
published with dispatch interceptors.
This InterceptingEventSink is typically registered as a
decorator and automatically kicks in whenever
MessageDispatchInterceptors are present.
- Since:
- 5.0.0
- Author:
- Steven van Beelen
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionInterceptingEventSink(EventSink delegate, List<MessageDispatchInterceptor<? super EventMessage>> interceptors) Constructs aInterceptingEventSink, delegating publishing to the givendelegate. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.publish(ProcessingContext context, List<EventMessage> events) Publishes the giveneventswithin the givencontext, when present.
-
Field Details
-
DECORATION_ORDER
public static final int DECORATION_ORDERThe order in which theInterceptingEventSinkis applied as adecoratorto theEventSink.As such, any decorator with a lower value will be applied to the delegate, and any higher value will be applied to the
InterceptingEventSinkitself. Using the same value can either lead to application of the decorator to the delegate or theInterceptingEventSink, depending on the order of registration.The order of the
InterceptingEventSinkis set toInteger.MIN_VALUE + 100to ensure it is applied very early in the configuration process, but not the earliest to allow for other decorators to be applied.- See Also:
-
-
Constructor Details
-
InterceptingEventSink
public InterceptingEventSink(@Nonnull EventSink delegate, @Nonnull List<MessageDispatchInterceptor<? super EventMessage>> interceptors) Constructs aInterceptingEventSink, delegating publishing to the givendelegate.The given
interceptorsare invoked beforepublishingis done by the givendelegate.- Parameters:
delegate- The delegateEventSinkthat will handle all dispatching and handling logic.interceptors- The interceptors to invoke before publishing an event.
-
-
Method Details
-
publish
public CompletableFuture<Void> publish(@Nullable ProcessingContext context, @Nonnull List<EventMessage> events) Description copied from interface:EventSinkPublishes the giveneventswithin the givencontext, when present.When present, the
post invocationphase is used to publish theevents. As a consequence, the resultingCompletableFuturecompletes when theeventsare staged in that phase.When no
ProcessingContextis provided, implementers of this interface may choose to create aProcessingContextwhen necessary.- Specified by:
publishin interfaceEventSink- Parameters:
context- The processing context, if any, to publish the giveneventsin.events- Theeventsto publish in this sink.- Returns:
- A
CompletableFutureofVoid. When this completes and a non-nullcontextwas given, this means theeventshave been successfully staged. When a nullcontextwas provided, successful completion of this future means theeventswhere published.
-
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.
-