Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here you go:</p> <pre><code>import java.util.concurrent.atomic.AtomicLong; import javax.management.Notification; import org.springframework.jmx.export.annotation.ManagedOperation; import org.springframework.jmx.export.annotation.ManagedResource; import org.springframework.jmx.export.notification.NotificationPublisher; import org.springframework.jmx.export.notification.NotificationPublisherAware; @ManagedResource public class JMXDemo implements NotificationPublisherAware { private final AtomicLong notificationSequence = new AtomicLong(); private NotificationPublisher notificationPublisher; @Override public void setNotificationPublisher( final NotificationPublisher notificationPublisher) { this.notificationPublisher = notificationPublisher; } @ManagedOperation public void trigger() { if (notificationPublisher != null) { final Notification notification = new Notification("type", getClass().getName(), notificationSequence.getAndIncrement(), "The message"); notificationPublisher.sendNotification(notification); } } } </code></pre> <p>And in your Spring configuration file you must use something like this:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "&gt; &lt;context:mbean-server id="mbeanServer" /&gt; &lt;context:mbean-export server="mbeanServer" /&gt; &lt;bean class="org.springframework.jmx.export.MBeanExporter"&gt; &lt;property name="server" ref="mbeanServer" /&gt; &lt;property name="namingStrategy"&gt; &lt;bean id="namingStrategy" class="org.springframework.jmx.export.naming.MetadataNamingStrategy"&gt; &lt;property name="attributeSource"&gt; &lt;bean class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/beans&gt; </code></pre> <p>You can then access above bean with JConsole and trigger notifications with the operation <code>trigger()</code>. Be sure to subscribe to the notifications. :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload