Class NotificationListeningMessageProducer

All Implemented Interfaces:
EventListener, NotificationListener, Aware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, SmartInitializingSingleton, ApplicationContextAware, ApplicationListener<ContextRefreshedEvent>, Lifecycle, Phased, SmartLifecycle, ExpressionCapable, MessageProducer, IntegrationPattern, NamedComponent, IntegrationInboundManagement, IntegrationManagement, ManageableLifecycle, ManageableSmartLifecycle, TrackableComponent

public class NotificationListeningMessageProducer extends MessageProducerSupport implements NotificationListener, ApplicationListener<ContextRefreshedEvent>
A JMX NotificationListener implementation that will send Messages containing the JMX Notification instances as their payloads.
Since:
2.0
Author:
Mark Fisher, Gary Russell, Artem Bilan
  • Constructor Details

    • NotificationListeningMessageProducer

      public NotificationListeningMessageProducer()
  • Method Details

    • setServer

      public void setServer(MBeanServerConnection server)
      Provide a reference to the MBeanServer where the notification publishing MBeans are registered.
      Parameters:
      server - the MBean server connection.
    • setObjectName

      public void setObjectName(ObjectName... objectNames)
      Specify the JMX ObjectNames (or patterns) of the notification publisher to which this notification listener should be subscribed.
      Parameters:
      objectNames - The object names.
    • setFilter

      public void setFilter(NotificationFilter filter)
      Specify a NotificationFilter to be passed to the server when registering this listener. The filter may be null.
      Parameters:
      filter - The filter.
    • setHandback

      public void setHandback(Object handback)
      Specify a handback object to provide context to the listener upon notification. This object may be null.
      Parameters:
      handback - The object.
    • handleNotification

      public void handleNotification(Notification notification, Object handback)
      Notification handling method implementation. Creates a Message with the JMX Notification as its payload, and if the handback object is not null, it sets that as a Message header value. The Message is then sent to this producer's output channel.
      Specified by:
      handleNotification in interface NotificationListener
    • getComponentType

      public String getComponentType()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this method to provide component type information.
      Specified by:
      getComponentType in interface NamedComponent
      Overrides:
      getComponentType in class IntegrationObjectSupport
    • onApplicationEvent

      public void onApplicationEvent(ContextRefreshedEvent event)
      The NotificationListener might not be registered on AbstractEndpoint.start() because the MBeanExporter might not been started yet.
      Specified by:
      onApplicationEvent in interface ApplicationListener<ContextRefreshedEvent>
      Parameters:
      event - the ContextRefreshedEvent event
    • doStart

      protected void doStart()
      Registers the notification listener with the specified ObjectNames.
      Overrides:
      doStart in class MessageProducerSupport
    • doStop

      protected void doStop()
      Unregisters the notification listener.
      Overrides:
      doStop in class MessageProducerSupport
    • retrieveMBeanNames

      protected Collection<ObjectName> retrieveMBeanNames()
      Return a collection of ObjectName ofr provided mBeanObjectNames.
      Returns:
      the collection of ObjectName ofr provided mBeanObjectNames.