Search in sources :

Example 6 with MonitorNotification

use of javax.management.monitor.MonitorNotification in project jdk8u_jdk by JetBrains.

the class ReflectionExceptionTest method handleNotification.

// Notification handler
public void handleNotification(Notification notification, Object handback) {
    echo(">>> Received notification: " + notification);
    if (notification instanceof MonitorNotification) {
        String type = notification.getType();
        if (type.equals(MonitorNotification.RUNTIME_ERROR)) {
            MonitorNotification mn = (MonitorNotification) notification;
            echo("\tType: " + mn.getType());
            echo("\tTimeStamp: " + mn.getTimeStamp());
            echo("\tObservedObject: " + mn.getObservedObject());
            echo("\tObservedAttribute: " + mn.getObservedAttribute());
            echo("\tDerivedGauge: " + mn.getDerivedGauge());
            echo("\tTrigger: " + mn.getTrigger());
            synchronized (this) {
                messageReceived = true;
                notifyAll();
            }
        }
    }
}
Also used : MonitorNotification(javax.management.monitor.MonitorNotification)

Example 7 with MonitorNotification

use of javax.management.monitor.MonitorNotification in project jdk8u_jdk by JetBrains.

the class RuntimeExceptionTest method handleNotification.

// Notification handler
public void handleNotification(Notification notification, Object handback) {
    echo(">>> Received notification: " + notification);
    if (notification instanceof MonitorNotification) {
        String type = notification.getType();
        if (type.equals(MonitorNotification.RUNTIME_ERROR)) {
            MonitorNotification mn = (MonitorNotification) notification;
            echo("\tType: " + mn.getType());
            echo("\tTimeStamp: " + mn.getTimeStamp());
            echo("\tObservedObject: " + mn.getObservedObject());
            echo("\tObservedAttribute: " + mn.getObservedAttribute());
            echo("\tDerivedGauge: " + mn.getDerivedGauge());
            echo("\tTrigger: " + mn.getTrigger());
            synchronized (this) {
                messageReceived = true;
                notifyAll();
            }
        }
    }
}
Also used : MonitorNotification(javax.management.monitor.MonitorNotification)

Example 8 with MonitorNotification

use of javax.management.monitor.MonitorNotification in project jdk8u_jdk by JetBrains.

the class CounterMonitor method buildAlarmNotification.

@Override
synchronized MonitorNotification buildAlarmNotification(ObjectName object, String attribute, Comparable<?> value) {
    final CounterMonitorObservedObject o = (CounterMonitorObservedObject) getObservedObject(object);
    if (o == null)
        return null;
    // Notify the listeners and update the threshold if
    // the updated derived gauge value is valid.
    //
    final MonitorNotification alarm;
    if (o.getDerivedGaugeValid()) {
        alarm = updateNotifications(o);
        updateThreshold(o);
    } else {
        alarm = null;
    }
    return alarm;
}
Also used : MonitorNotification(javax.management.monitor.MonitorNotification)

Example 9 with MonitorNotification

use of javax.management.monitor.MonitorNotification in project jdk8u_jdk by JetBrains.

the class CounterMonitor method updateNotifications.

/**
     * Updates the notification attribute of the observed object
     * and notifies the listeners only once if the notify flag
     * is set to <CODE>true</CODE>.
     * @param o The observed object.
     */
private synchronized MonitorNotification updateNotifications(CounterMonitorObservedObject o) {
    MonitorNotification n = null;
    //
    if (!o.getEventAlreadyNotified()) {
        if (((Number) o.getDerivedGauge()).longValue() >= o.getThreshold().longValue()) {
            if (notify) {
                n = new MonitorNotification(THRESHOLD_VALUE_EXCEEDED, this, 0, 0, "", null, null, null, o.getThreshold());
            }
            if (!differenceMode) {
                o.setEventAlreadyNotified(true);
            }
        }
    } else {
        if (MONITOR_LOGGER.isLoggable(Level.FINER)) {
            final StringBuilder strb = new StringBuilder().append("The notification:").append("\n\tNotification observed object = ").append(o.getObservedObject()).append("\n\tNotification observed attribute = ").append(getObservedAttribute()).append("\n\tNotification threshold level = ").append(o.getThreshold()).append("\n\tNotification derived gauge = ").append(o.getDerivedGauge()).append("\nhas already been sent");
            MONITOR_LOGGER.logp(Level.FINER, CounterMonitor.class.getName(), "updateNotifications", strb.toString());
        }
    }
    return n;
}
Also used : MonitorNotification(javax.management.monitor.MonitorNotification)

Example 10 with MonitorNotification

use of javax.management.monitor.MonitorNotification in project jdk8u_jdk by JetBrains.

the class Monitor method sendNotification.

/*
     * ------------------------------------------
     *  PRIVATE METHODS
     * ------------------------------------------
     */
/**
     * This method is used by the monitor MBean to create and send a
     * monitor notification to all the listeners registered for this
     * kind of notification.
     *
     * @param type The notification type.
     * @param timeStamp The notification emission date.
     * @param msg The notification message.
     * @param derGauge The derived gauge.
     * @param trigger The threshold/string (depending on the monitor
     * type) that triggered off the notification.
     * @param object The ObjectName of the observed object that triggered
     * off the notification.
     * @param onError Flag indicating if this monitor notification is
     * an error notification or an alarm notification.
     */
private void sendNotification(String type, long timeStamp, String msg, Object derGauge, Object trigger, ObjectName object, boolean onError) {
    if (!isActive())
        return;
    if (MONITOR_LOGGER.isLoggable(Level.FINER)) {
        MONITOR_LOGGER.logp(Level.FINER, Monitor.class.getName(), "sendNotification", "send notification: " + "\n\tNotification observed object = " + object + "\n\tNotification observed attribute = " + observedAttribute + "\n\tNotification derived gauge = " + derGauge);
    }
    long seqno = sequenceNumber.getAndIncrement();
    MonitorNotification mn = new MonitorNotification(type, this, seqno, timeStamp, msg, object, observedAttribute, derGauge, trigger);
    if (onError)
        onErrorNotification(mn);
    sendNotification(mn);
}
Also used : MonitorNotification(javax.management.monitor.MonitorNotification)

Aggregations

MonitorNotification (javax.management.monitor.MonitorNotification)12 AttributeNotFoundException (javax.management.AttributeNotFoundException)2 CamelContext (org.apache.camel.CamelContext)2 ConsumerTemplate (org.apache.camel.ConsumerTemplate)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 Test (org.junit.Test)2 IntrospectionException (java.beans.IntrospectionException)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 AttributeChangeNotification (javax.management.AttributeChangeNotification)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 MBeanException (javax.management.MBeanException)1 MBeanServerNotification (javax.management.MBeanServerNotification)1 ObjectName (javax.management.ObjectName)1 ReflectionException (javax.management.ReflectionException)1 OpenDataException (javax.management.openmbean.OpenDataException)1