Search in sources :

Example 11 with NotificationFilter

use of javax.management.NotificationFilter in project jdk8u_jdk by JetBrains.

the class SnmpMibTable method sendNotification.

// ----------------------------------------------------------------------
// PRIVATE METHODS
// ----------------------------------------------------------------------
/**
     * Enable this <CODE>SnmpMibTable</CODE> to send a notification.
     *
     * <p>
     * @param notification The notification to send.
     */
private synchronized void sendNotification(Notification notification) {
    //
    for (java.util.Enumeration<NotificationListener> k = handbackTable.keys(); k.hasMoreElements(); ) {
        NotificationListener listener = k.nextElement();
        // Get the associated handback list and the associated filter list
        //
        java.util.Vector<?> handbackList = handbackTable.get(listener);
        java.util.Vector<NotificationFilter> filterList = filterTable.get(listener);
        // loop on handback
        //
        java.util.Enumeration<NotificationFilter> f = filterList.elements();
        for (java.util.Enumeration<?> h = handbackList.elements(); h.hasMoreElements(); ) {
            Object handback = h.nextElement();
            NotificationFilter filter = f.nextElement();
            if ((filter == null) || (filter.isNotificationEnabled(notification))) {
                listener.handleNotification(notification, handback);
            }
        }
    }
}
Also used : NotificationFilter(javax.management.NotificationFilter) NotificationListener(javax.management.NotificationListener)

Example 12 with NotificationFilter

use of javax.management.NotificationFilter in project camel by apache.

the class JMXMonitorConsumer method addNotificationListener.

@Override
protected void addNotificationListener() throws Exception {
    JMXEndpoint ep = (JMXEndpoint) getEndpoint();
    // create the monitor bean
    Monitor bean = null;
    if (ep.getMonitorType().equals("counter")) {
        CounterMonitor counter = new CounterMonitor();
        Number initThreshold = convertNumberToAttributeType(ep.getInitThreshold(), ep.getJMXObjectName(), ep.getObservedAttribute());
        Number offset = convertNumberToAttributeType(ep.getOffset(), ep.getJMXObjectName(), ep.getObservedAttribute());
        Number modulus = convertNumberToAttributeType(ep.getModulus(), ep.getJMXObjectName(), ep.getObservedAttribute());
        counter.setInitThreshold(initThreshold);
        counter.setOffset(offset);
        counter.setModulus(modulus);
        counter.setDifferenceMode(ep.isDifferenceMode());
        counter.setNotify(true);
        bean = counter;
    } else if (ep.getMonitorType().equals("gauge")) {
        GaugeMonitor gm = new GaugeMonitor();
        gm.setNotifyHigh(ep.isNotifyHigh());
        gm.setNotifyLow(ep.isNotifyLow());
        gm.setDifferenceMode(ep.isDifferenceMode());
        Number highValue = convertNumberToAttributeType(ep.getThresholdHigh(), ep.getJMXObjectName(), ep.getObservedAttribute());
        Number lowValue = convertNumberToAttributeType(ep.getThresholdLow(), ep.getJMXObjectName(), ep.getObservedAttribute());
        gm.setThresholds(highValue, lowValue);
        bean = gm;
    } else if (ep.getMonitorType().equals("string")) {
        StringMonitor sm = new StringMonitor();
        sm.setNotifyDiffer(ep.isNotifyDiffer());
        sm.setNotifyMatch(ep.isNotifyMatch());
        sm.setStringToCompare(ep.getStringToCompare());
        bean = sm;
    }
    bean.addObservedObject(ep.getJMXObjectName());
    bean.setObservedAttribute(ep.getObservedAttribute());
    bean.setGranularityPeriod(ep.getGranularityPeriod());
    // register the bean
    mMonitorObjectName = new ObjectName(ep.getObjectDomain(), "name", "camel-jmx-monitor-" + UUID.randomUUID());
    ManagementFactory.getPlatformMBeanServer().registerMBean(bean, mMonitorObjectName);
    // add ourselves as a listener to it
    NotificationFilter nf = ep.getNotificationFilter();
    getServerConnection().addNotificationListener(mMonitorObjectName, this, nf, bean);
    bean.start();
}
Also used : StringMonitor(javax.management.monitor.StringMonitor) StringMonitor(javax.management.monitor.StringMonitor) CounterMonitor(javax.management.monitor.CounterMonitor) Monitor(javax.management.monitor.Monitor) GaugeMonitor(javax.management.monitor.GaugeMonitor) GaugeMonitor(javax.management.monitor.GaugeMonitor) CounterMonitor(javax.management.monitor.CounterMonitor) NotificationFilter(javax.management.NotificationFilter) ObjectName(javax.management.ObjectName)

Example 13 with NotificationFilter

use of javax.management.NotificationFilter in project camel by apache.

the class JMXConsumer method addNotificationListener.

/**
     * Adds a notification listener to the target bean.
     * @throws Exception
     */
protected void addNotificationListener() throws Exception {
    JMXEndpoint ep = (JMXEndpoint) getEndpoint();
    NotificationFilter nf = ep.getNotificationFilter();
    ObjectName objectName = ep.getJMXObjectName();
    getServerConnection().addNotificationListener(objectName, this, nf, ep.getHandback());
}
Also used : NotificationFilter(javax.management.NotificationFilter) ObjectName(javax.management.ObjectName)

Example 14 with NotificationFilter

use of javax.management.NotificationFilter in project quasar by puniverse.

the class MonitoringServices method addPerfNotificationListener.

public synchronized void addPerfNotificationListener(NotificationListener listener, Object handback) {
    timer.addNotificationListener(listener, new NotificationFilter() {

        @Override
        public boolean isNotificationEnabled(Notification notification) {
            return "perfTimer".equals(notification.getType());
        }
    }, handback);
    perfTimerListeners++;
    manageTimer();
}
Also used : NotificationFilter(javax.management.NotificationFilter) Notification(javax.management.Notification)

Example 15 with NotificationFilter

use of javax.management.NotificationFilter in project quasar by puniverse.

the class MonitoringServices method addStructuralNotificationListener.

public synchronized void addStructuralNotificationListener(NotificationListener listener, Object handback) {
    timer.addNotificationListener(listener, new NotificationFilter() {

        @Override
        public boolean isNotificationEnabled(Notification notification) {
            return "structTimer".equals(notification.getType());
        }
    }, handback);
    structuralTimerListeners++;
    manageTimer();
}
Also used : NotificationFilter(javax.management.NotificationFilter) Notification(javax.management.Notification)

Aggregations

NotificationFilter (javax.management.NotificationFilter)17 Notification (javax.management.Notification)13 ObjectName (javax.management.ObjectName)7 NotificationListener (javax.management.NotificationListener)6 AttributeChangeNotification (javax.management.AttributeChangeNotification)3 ScanState (com.sun.jmx.examples.scandir.ScanManagerMXBean.ScanState)2 HashMap (java.util.HashMap)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 MBeanServer (javax.management.MBeanServer)2 MBeanServerNotification (javax.management.MBeanServerNotification)2 NotificationEmitter (javax.management.NotificationEmitter)2 ArrayNotificationBuffer (com.sun.jmx.remote.internal.ArrayNotificationBuffer)1 NotificationBuffer (com.sun.jmx.remote.internal.NotificationBuffer)1 NotificationBufferFilter (com.sun.jmx.remote.internal.NotificationBufferFilter)1 IOException (java.io.IOException)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 AccessibleObject (java.lang.reflect.AccessibleObject)1 Date (java.util.Date)1 Attribute (javax.management.Attribute)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1