FileDocCategorySizeDatePackage
Listener.javaAPI DocExample3347Thu May 23 09:32:50 BST 2002 sample.monitor

Listener

public class Listener extends Object implements NotificationListener
author
sperry
version

Fields Summary
private boolean
_traceOn
MessageLog
_logger
Constructors Summary
public Listener()
Creates new Listener


             
       
    
Methods Summary
public voidhandleNotification(javax.management.Notification notification, java.lang.Object obj)

        String type = notification.getType();
        if (notification instanceof MonitorNotification) {
            MonitorNotification notif = (MonitorNotification)notification;
            String attribute = notif.getObservedAttribute();
            ObjectName obsObj = notif.getObservedObject();
            Object derivedGauge = notif.getDerivedGauge();
            Object trigger = notif.getTrigger();
            if (type.equals(MonitorNotification.THRESHOLD_VALUE_EXCEEDED)) {
                trace("THRESHOLD EXCEEDED: Attribute: " + attribute + ", Object: "
                        + obsObj + ", Derived Gauge: " + derivedGauge + ", Trigger: "
                        + trigger);
            } 
            else if (type.equals(MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED)) {
                trace("STRING DIFFERS: Attribute: " + attribute + ", Object: "
                        + obsObj + ", Derived Gauge: " + derivedGauge + ", Trigger: "
                        + trigger);
            } 
            else if (type.equals(MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED)) {
                trace("STRING MATCHES: Attribute: " + attribute + ", Object: "
                        + obsObj + ", Derived Gauge: " + derivedGauge + ", Trigger: "
                        + trigger);
            } 
            else if (type.equals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR)) {
                trace("ATTRIBUTE ERROR (" + attribute + "): " + notif.getMessage());
            } 
            else if (type.equals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR)) {
                trace("ATTRIBUTE TYPE ERROR (" + attribute + "): " + notif.getMessage());
            } 
            else if (type.equals(MonitorNotification.OBSERVED_OBJECT_ERROR)) {
                trace("OBJECT ERROR (" + obsObj + "): " + notif.getMessage());
            } 
            else if (type.equals(MonitorNotification.RUNTIME_ERROR)) {
                trace("RUNTIME ERROR (" + obsObj + "): " + notif.getMessage());
            } 
            else if (type.equals(MonitorNotification.THRESHOLD_ERROR)) {
                trace("THRESHOLD ERROR (" + obsObj + "): " + notif.getMessage());
            }
        }
    
private booleanisTraceOn()

        return  _traceOn;
    
private voidtrace(java.lang.String message)

        if (isTraceOn()) {
            System.out.println(message);
        }
        traceLog(message);
    
private voidtrace(java.lang.Throwable t)

        traceLog(t);
    
private voidtraceLog(java.lang.Throwable t)

        if (isTraceOn()) {
            _logger.write(t);
        }
    
private voidtraceLog(java.lang.String message)


         
        if (isTraceOn()) {
            _logger.write(message);
        }