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 Details

  • 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, then NotificationHandler.afterSuccessfulAcknowledgement(Object, NotificationStateAware, NotificationStateRepository) will be called.

      Specified by:
      handle in interface NotificationHandler
      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

      public String getChannelModifier()
      Description copied from interface: NotificationHandler
      Retrieve any modifier for the channel associated with this handler. Detection of the modifier is based on any BindingModificationAware beans registered with the Spring. Will return an empty string if a modifier is not detected.
      Specified by:
      getChannelModifier in interface NotificationHandler
      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 the NotificationState.getAttempts() value for the attempt. Update the NotificationState.getChangeTimestampAck() if the send is successful.
      Parameters:
      notifiable - The entity with the state change requiring Persistence channel notification
      state - The status of the Persistence channel message send
      repository - 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 broker
      timeout - 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)