Class DefaultNotificationHandler
- java.lang.Object
-
- com.broadleafcommerce.common.messaging.notification.DefaultNotificationHandler
-
- All Implemented Interfaces:
NotificationHandler
,org.springframework.core.Ordered
- Direct Known Subclasses:
PersistenceMessageNotificationHandler
public class DefaultNotificationHandler extends Object implements NotificationHandler
- Author:
- Jeff Fischer
-
-
Constructor Summary
Constructors Constructor Description DefaultNotificationHandler(ChannelSupplier producer, DurableNotificationProperties properties, String messageType, List<IgnoredNotificationStateRepository> ignoredRepositories, MessageFactory<?> messageFactory, MessageSerializationHelper helper)
DefaultNotificationHandler(ChannelSupplier producer, DurableNotificationProperties properties, String messageType, List<IgnoredNotificationStateRepository> ignoredRepositories, MessageSerializationHelper helper)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.springframework.messaging.Message<?>
createMessageSafely(NotificationStateAware notifiable, NotificationState state)
protected Supplier<org.springframework.messaging.Message<?>>
createMessageSupplier(NotificationStateAware notifiable, NotificationState state)
protected long
getWaitTimeExp(int attemptCount)
Provide an exponential backoff wait period based on the number of attemptsNotificationHandlerResponse
handle(NotificationStateRepository repo, NotificationStateAware notifiable, String requestedType)
Notify the system in some way about the state change for the notifiable param.protected boolean
notify(NotificationStateAware notifiable, NotificationState state, NotificationStateRepository repository)
Validate the state requires notification, and if so, send the notification.protected boolean
sendRemote(org.springframework.messaging.Message<?> message, long timeout)
Send the message on the remote channel.protected boolean
sendRemoteMessageSafely(org.springframework.messaging.Message<?> message)
protected NotificationStateAware
unwrapNotificationState(NotificationStateAware notifiable)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.broadleafcommerce.common.messaging.notification.NotificationHandler
afterSuccessfulAcknowledgement, getOrder
-
-
-
-
Constructor Detail
-
DefaultNotificationHandler
public DefaultNotificationHandler(ChannelSupplier producer, DurableNotificationProperties properties, String messageType, List<IgnoredNotificationStateRepository> ignoredRepositories, MessageSerializationHelper helper)
-
DefaultNotificationHandler
public DefaultNotificationHandler(ChannelSupplier producer, DurableNotificationProperties properties, String messageType, List<IgnoredNotificationStateRepository> ignoredRepositories, MessageFactory<?> messageFactory, MessageSerializationHelper helper)
-
-
Method Detail
-
handle
@NonNull public NotificationHandlerResponse handle(@NonNull NotificationStateRepository repo, @NonNull NotificationStateAware notifiable, @NonNull String requestedType)
Description copied from interface:NotificationHandler
Notify the system in some way about the state change for the notifiable param.If the message is successfully sent and the
NotificationState
is successfully updated as acked, thenNotificationHandler.afterSuccessfulAcknowledgement(Object, NotificationStateAware, NotificationStateRepository)
will be called.- Specified by:
handle
in interfaceNotificationHandler
- Parameters:
repo
- The repository responsible for making the state change.notifiable
- The Trackable entity that experienced the state change.requestedType
- The type of the message. Generally compared against the message type supported by this handler. For example,DefaultNotificationHandler#messageType
.- Returns:
- Whether or not the call was handled and if the handler processing chain should continue
-
notify
protected boolean notify(NotificationStateAware notifiable, NotificationState state, NotificationStateRepository repository)
Validate the state requires notification, and if so, send the notification. Update theNotificationState.getAttempts()
value for the attempt. Update theNotificationState.getChangeTimestampAck()
if the send is successful.- Parameters:
notifiable
- The entity with the state change requiring Persistence channel notificationstate
- The status of the Persistence channel message sendrepository
- The entity repository- Returns:
- Whether or not the send succeeded
-
unwrapNotificationState
protected NotificationStateAware unwrapNotificationState(NotificationStateAware notifiable)
-
createMessageSafely
@Nullable protected org.springframework.messaging.Message<?> createMessageSafely(NotificationStateAware notifiable, NotificationState state)
-
createMessageSupplier
protected Supplier<org.springframework.messaging.Message<?>> createMessageSupplier(NotificationStateAware notifiable, NotificationState state)
-
sendRemoteMessageSafely
protected boolean sendRemoteMessageSafely(@Nullable org.springframework.messaging.Message<?> message)
-
sendRemote
protected boolean sendRemote(org.springframework.messaging.Message<?> message, long timeout)
Send the message on the remote channel. This call should be isolated as much as possible to the remote call to avoid including unwanted logic in the circuit breaker.- Parameters:
message
- The message instance to send to the remote brokertimeout
- The message send timeout- Returns:
- Whether or not the message was sent
-
getWaitTimeExp
protected long getWaitTimeExp(int attemptCount)
Provide an exponential backoff wait period based on the number of attempts- Parameters:
attemptCount
- The current attempt count- Returns:
- The time to wait, in seconds
-
-