Class DefaultNotificationHandler
java.lang.Object
com.broadleafcommerce.common.messaging.notification.DefaultNotificationHandler
- All Implemented Interfaces:
NotificationHandler
,org.springframework.core.Ordered
- Direct Known Subclasses:
PersistenceMessageNotificationHandler
- Author:
- Jeff Fischer
-
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultNotificationHandler
(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
Modifier and TypeMethodDescriptionprotected org.springframework.messaging.Message<?>
createMessageSafely
(NotificationStateAware notifiable, NotificationState state) protected Supplier<org.springframework.messaging.Message<?>>
createMessageSupplier
(NotificationStateAware notifiable, NotificationState state) org.springframework.beans.factory.ListableBeanFactory
Retrieve any modifier for the channel associated with this handler.org.springframework.core.env.Environment
protected long
getWaitTimeExp
(int attemptCount) Provide an exponential backoff wait period based on the number of attemptshandle
(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) void
setBeanFactory
(org.springframework.beans.factory.ListableBeanFactory beanFactory) void
setChannelModifierProperties
(ChannelModifierProperties channelModifierProperties) void
setEnvironment
(org.springframework.core.env.Environment environment) 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 Details
-
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 Details
-
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
-
getChannelModifier
Description copied from interface:NotificationHandler
Retrieve any modifier for the channel associated with this handler. Detection of the modifier is based on anyBindingModificationAware
beans registered with the Spring. Will return an empty string if a modifier is not detected.- Specified by:
getChannelModifier
in interfaceNotificationHandler
- Returns:
- Any modifier detected in the configuration for the Spring Cloud Stream channel destination
-
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
-
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
-
getBeanFactory
public org.springframework.beans.factory.ListableBeanFactory getBeanFactory() -
setBeanFactory
@Autowired public void setBeanFactory(org.springframework.beans.factory.ListableBeanFactory beanFactory) -
getEnvironment
public org.springframework.core.env.Environment getEnvironment() -
setEnvironment
@Autowired public void setEnvironment(org.springframework.core.env.Environment environment) -
setChannelModifierProperties
@Autowired(required=false) public void setChannelModifierProperties(ChannelModifierProperties channelModifierProperties)
-