Class DefaultNotificationManager
- All Implemented Interfaces:
NotificationManager
- Author:
- Jeff Fischer
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacePerform a task without response or exception notification -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidDo a unit of work upon successful completion of the current transaction, or, execute the work immediately if transaction synchronization is not currently active.voidhandle(NotificationStateRepository repo, NotificationStateAware notifiable, String messageType) Notify the system in some way about the state change for the notifiable param.voidhandleAsync(NotificationStateRepository repo, NotificationStateAware notifiable, String messageType) Notify the system in some way about the state change for the notifiable param.voidhandleAsync(NotificationStateRepository repo, NotificationStateAware notifiable, String messageType, Runnable callback) Notify the system in some way about the state change for the notifiable param.protected voidpublishInternalPersistenceEvent(NotificationStateAware notifiable, String messageType) Publish anInternalPersistenceEventto listeners within this JVM, if the message type warrants it.voidsetEventPublisher(org.springframework.context.ApplicationEventPublisher eventPublisher) voidsetNotificationMessageAsyncExecutor(Executor notificationMessageAsyncExecutor) voidsetProperties(NotificationManagerProperties properties)
-
Constructor Details
-
DefaultNotificationManager
-
-
Method Details
-
handle
public void handle(@NonNull NotificationStateRepository repo, @NonNull NotificationStateAware notifiable, @NonNull String messageType) Description copied from interface:NotificationManagerNotify the system in some way about the state change for the notifiable param. Processing is handled through one or moreNotificationHandlerinstances. This will update the given notifiable using repo. Subsequent checks of the latest notification state will require a re-read.- Specified by:
handlein interfaceNotificationManager- Parameters:
repo- The service responsible for making the state change. Usually aRepositoryinstance.notifiable- The object that experienced the state change. Usually a Spring Data entity instance.messageType- The type of message correlating toDefaultNotificationHandler#messageType.
-
handleAsync
public void handleAsync(@NonNull NotificationStateRepository repo, @NonNull NotificationStateAware notifiable, @NonNull String messageType, @Nullable Runnable callback) Description copied from interface:NotificationManagerNotify the system in some way about the state change for the notifiable param. Processing is handled through one or moreNotificationHandlerinstances. This will update the given notifiable using repo. Subsequent checks of the latest notification state will require a re-read. Notably, this version will perform handling using a thread pool.Any
InternalPersistenceEventremains synchronous - it is published on the calling thread once the current transaction commits, before handling is dispatched to the pool.- Specified by:
handleAsyncin interfaceNotificationManager- Parameters:
repo- The service responsible for making the state change. Usually aRepositoryinstance.notifiable- The object that experienced the state change. Usually a Spring Data entity instance.messageType- The type of message correlating toDefaultNotificationHandler#messageType.callback- Code snippet to execute after all notification handling operations are complete- See Also:
-
handleAsync
public void handleAsync(@NonNull NotificationStateRepository repo, @NonNull NotificationStateAware notifiable, @NonNull String messageType) Description copied from interface:NotificationManagerNotify the system in some way about the state change for the notifiable param. Processing is handled through one or moreNotificationHandlerinstances. This will update the given notifiable using repo. Subsequent checks of the latest notification state will require a re-read. Notably, this version will perform handling using a thread pool.Any
InternalPersistenceEventremains synchronous - it is published on the calling thread once the current transaction commits, before handling is dispatched to the pool.- Specified by:
handleAsyncin interfaceNotificationManager- Parameters:
repo- The service responsible for making the state change. Usually aRepositoryinstance.notifiable- The object that experienced the state change. Usually a Spring Data entity instance.messageType- The type of message correlating toDefaultNotificationHandler#messageType.- See Also:
-
executePostTransactionCommitOrNow
Do a unit of work upon successful completion of the current transaction, or, execute the work immediately if transaction synchronization is not currently active.- Parameters:
work- The work to perform
-
publishInternalPersistenceEvent
protected void publishInternalPersistenceEvent(NotificationStateAware notifiable, String messageType) Publish anInternalPersistenceEventto listeners within this JVM, if the message type warrants it.This is always performed on the thread that committed the originating transaction, even when the remainder of the notification handling is dispatched to the
notificationMessageAsyncExecutorbyhandleAsync(NotificationStateRepository, NotificationStateAware, String, Runnable). Listeners of this event form part of the call flow that persisted the entity, and that flow expects their work to be done by the time the persistence operation returns. Catalog propagation suppresses its own deletion and update events where this one is expected to cover the same ground, and basic audit "touch" handling is driven from a listener. Delivering the event on a pool thread lets the persisting flow run on before any of that has happened.A misbehaving listener is logged rather than propagated, so that it neither disturbs the flow that just committed nor suppresses the notification itself.
- Parameters:
notifiable- The object that experienced the state changemessageType- The type of message being handled. OnlyPersistenceProducer.TYPEresults in an event
-
setEventPublisher
@Autowired public void setEventPublisher(@Nullable org.springframework.context.ApplicationEventPublisher eventPublisher) -
setProperties
-
setNotificationMessageAsyncExecutor
@Autowired public void setNotificationMessageAsyncExecutor(@Qualifier("notificationMessageAsyncExecutor") Executor notificationMessageAsyncExecutor)
-