Class DefaultEventPublicationRegistry
java.lang.Object
org.springframework.modulith.events.core.DefaultEventPublicationRegistry
- All Implemented Interfaces:
DisposableBean,CompletedEventPublications,EventPublicationRegistry
public class DefaultEventPublicationRegistry
extends Object
implements DisposableBean, EventPublicationRegistry, CompletedEventPublications
A registry to capture event publications to
ApplicationListeners. Allows to
register those publications, mark them as completed and lookup incomplete publications.- Author:
- Oliver Drotbohm, Björn Kieling, Dmitry Belyaev
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classAllTargetEventPublications currently processed. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultEventPublicationRegistry(EventPublicationRepository events, Clock clock) Creates a newDefaultEventPublicationRegistryfor the givenEventPublicationRepository. -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteCompletedPublicationsOlderThan(Duration duration) Deletes all completedTargetEventPublications that have been completed before the givenDuration.voiddeletePublications(Predicate<EventPublication> filter) Deletes allEventPublications matching the givenPredicate.voiddeletePublicationsOlderThan(Duration duration) Deletes allEventPublications whose completion date is older than the givenDuration.voiddestroy()Collection<? extends TargetEventPublication>findAll()Returns allEventPublications that have already been completed.Returns allTargetEventPublications that have not been completed yet.findIncompletePublicationsOlderThan(Duration duration) Returns allTargetEventPublications that have not been completed yet and have been published before the given duration in relation to "now".(package private) DefaultEventPublicationRegistry.PublicationsInProgressvoidmarkCompleted(Object event, PublicationTargetIdentifier targetIdentifier) Marks the publication for the given event andPublicationTargetIdentifieras completed.voidmarkFailed(Object event, PublicationTargetIdentifier targetIdentifier) Marks the publication for the given event andPublicationTargetIdentifieras failed.(package private) voidmarkFailed(TargetEventPublication publication) Marks the givenTargetEventPublicationas failed.voidmarkProcessing(Object event, PublicationTargetIdentifier identifier) Marks the publication for the given event andPublicationTargetIdentifieras processing.voidmarkStalePublicationsFailed(Staleness staleness) Marks allEventPublications considered stale as failed.voidprocessFailedPublications(ResubmissionOptions options, Consumer<TargetEventPublication> consumer) Processes all failedEventPublications matching the givenResubmissionOptionswith the givenConsumer.voidprocessIncompletePublications(Predicate<EventPublication> filter, Consumer<TargetEventPublication> consumer, @Nullable Duration duration) Processes all incomplete event publications that have been published before the given duration in relation to "now" by applying the given filter passing all remaining instances to the givenConsumer.store(Object event, Stream<PublicationTargetIdentifier> listeners) StoresTargetEventPublications for the given event andApplicationListeners.
-
Constructor Details
-
DefaultEventPublicationRegistry
Creates a newDefaultEventPublicationRegistryfor the givenEventPublicationRepository.- Parameters:
events- must not be null.clock- must not be null.
-
-
Method Details
-
store
public Collection<TargetEventPublication> store(Object event, Stream<PublicationTargetIdentifier> listeners) Description copied from interface:EventPublicationRegistryStoresTargetEventPublications for the given event andApplicationListeners.- Specified by:
storein interfaceEventPublicationRegistry- Parameters:
event- must not be null.listeners- must not be null.
-
findIncompletePublications
Description copied from interface:EventPublicationRegistryReturns allTargetEventPublications that have not been completed yet.- Specified by:
findIncompletePublicationsin interfaceEventPublicationRegistry- Returns:
- will never be null.
-
findIncompletePublicationsOlderThan
Description copied from interface:EventPublicationRegistryReturns allTargetEventPublications that have not been completed yet and have been published before the given duration in relation to "now".- Specified by:
findIncompletePublicationsOlderThanin interfaceEventPublicationRegistry- Parameters:
duration- must not be null.- Returns:
- will never be null.
-
markProcessing
@Transactional(propagation=REQUIRES_NEW) public void markProcessing(Object event, PublicationTargetIdentifier identifier) Description copied from interface:EventPublicationRegistryMarks the publication for the given event andPublicationTargetIdentifieras processing.- Specified by:
markProcessingin interfaceEventPublicationRegistry- Parameters:
event- must not be null.identifier- must not be null.- See Also:
-
markCompleted
@Transactional(propagation=REQUIRES_NEW) public void markCompleted(Object event, PublicationTargetIdentifier targetIdentifier) Description copied from interface:EventPublicationRegistryMarks the publication for the given event andPublicationTargetIdentifieras completed.- Specified by:
markCompletedin interfaceEventPublicationRegistry- Parameters:
event- must not be null.targetIdentifier- must not be null.- See Also:
-
markFailed
@Transactional(propagation=REQUIRES_NEW) public void markFailed(Object event, PublicationTargetIdentifier targetIdentifier) Description copied from interface:EventPublicationRegistryMarks the publication for the given event andPublicationTargetIdentifieras failed.- Specified by:
markFailedin interfaceEventPublicationRegistry- Parameters:
event- must not be null.targetIdentifier- must not be null.- See Also:
-
deleteCompletedPublicationsOlderThan
Description copied from interface:EventPublicationRegistryDeletes all completedTargetEventPublications that have been completed before the givenDuration.- Specified by:
deleteCompletedPublicationsOlderThanin interfaceEventPublicationRegistry- Parameters:
duration- must not be null.
-
findAll
Description copied from interface:CompletedEventPublicationsReturns allEventPublications that have already been completed.- Specified by:
findAllin interfaceCompletedEventPublications- Returns:
- will never be null.
-
deletePublications
Description copied from interface:CompletedEventPublicationsDeletes allEventPublications matching the givenPredicate. Note that implementations will iterate all completedEventPublications and apply the predicate in memory.- Specified by:
deletePublicationsin interfaceCompletedEventPublications- Parameters:
filter- must not be null.
-
deletePublicationsOlderThan
Description copied from interface:CompletedEventPublicationsDeletes allEventPublications whose completion date is older than the givenDuration.- Specified by:
deletePublicationsOlderThanin interfaceCompletedEventPublications- Parameters:
duration- must not be null.
-
processIncompletePublications
public void processIncompletePublications(Predicate<EventPublication> filter, Consumer<TargetEventPublication> consumer, @Nullable Duration duration) Description copied from interface:EventPublicationRegistryProcesses all incomplete event publications that have been published before the given duration in relation to "now" by applying the given filter passing all remaining instances to the givenConsumer.- Specified by:
processIncompletePublicationsin interfaceEventPublicationRegistry- Parameters:
filter- must not be null.consumer- must not be null.duration- can be null.
-
processFailedPublications
public void processFailedPublications(ResubmissionOptions options, Consumer<TargetEventPublication> consumer) Description copied from interface:EventPublicationRegistryProcesses all failedEventPublications matching the givenResubmissionOptionswith the givenConsumer.- Specified by:
processFailedPublicationsin interfaceEventPublicationRegistry- Parameters:
options- must not be null.consumer- must not be null.
-
markStalePublicationsFailed
Description copied from interface:EventPublicationRegistryMarks allEventPublications considered stale as failed. WhichEventPublications will be affected can differ from implementation to implementation.- Specified by:
markStalePublicationsFailedin interfaceEventPublicationRegistry- Parameters:
staleness- must not be null.
-
destroy
public void destroy()- Specified by:
destroyin interfaceDisposableBean
-
getPublicationsInProgress
DefaultEventPublicationRegistry.PublicationsInProgress getPublicationsInProgress()- Returns:
- will never be null.
- Since:
- 1.3
-
markFailed
Marks the givenTargetEventPublicationas failed.- Parameters:
publication- must not be null.- Since:
- 1.3
- See Also:
-