Example usage for javax.management AttributeChangeNotification getNewValue

List of usage examples for javax.management AttributeChangeNotification getNewValue

Introduction

In this page you can find the example usage for javax.management AttributeChangeNotification getNewValue.

Prototype

public Object getNewValue() 

Source Link

Document

Gets the new value of the attribute which has changed.

Usage

From source file:com.buschmais.maexo.test.spring.SpringTest.java

/**
 * Test notification listener.//w w w .  jav  a2s  .  c o  m
 * 
 * @throws InterruptedException
 */
public void test_notificationListener() throws InterruptedException {
    String newValue = "a new value";
    this.standardMBean.setAttribute(newValue);
    // notifications may be asynchronous, wait some time
    Thread.sleep(1000);
    Notification notification = this.notificationListener.getLastNotification();
    assertNotNull(notification);
    assertEquals(NOTIFICATION_HANDBACK, this.notificationListener.getLastHandback());
    if (notification instanceof AttributeChangeNotification) {
        AttributeChangeNotification attributeChangeNotification = (AttributeChangeNotification) notification;
        assertEquals(newValue, attributeChangeNotification.getNewValue());
    } else {
        super.fail("expected instance of " + AttributeChangeNotification.class.getName() + ", received "
                + notification.getClass().getName());
    }
}

From source file:org.hyperic.hq.plugin.weblogic.config.WeblogicAttributeChangeListener.java

public synchronized void handleNotification(Notification notification, Object handback) {

    if (!(notification instanceof AttributeChangeNotification)) {
        return;/*  w  ww .  j ava  2  s  .c o m*/
    }

    AttributeChangeNotification change = (AttributeChangeNotification) notification;

    String msg = change.getAttributeName() + " changed from " + change.getOldValue() + " to "
            + change.getNewValue();

    log.info(msg);

    TrackEvent event = new TrackEvent(this.plugin.getName(), System.currentTimeMillis(),
            LogTrackPlugin.LOGLEVEL_INFO, change.getSource().toString(), msg);

    this.plugin.getManager().reportEvent(event);
}

From source file:org.josso.util.config.SSOConfigurationEventHandler.java

/**
 * Handles an BaseSSOEvent and updates JOSSO config if necessary.
 * The event object must be instance of javax.management.AttributeChangeNotification
 *
 * @param eventType the event type (this may be a JMX event type)
 * @param event     the event object. Only AttributeChangeNotification events are supported by this handler.
 *//*from w  w  w.  ja  v  a  2  s.c om*/
public void handleEvent(String eventType, EventObject event) {

    // An attribute has change in the SSOAgent ... update config file.
    if (event instanceof AttributeChangeNotification) {
        AttributeChangeNotification notification = (AttributeChangeNotification) event;
        String attrName = notification.getAttributeName();

        if (ignore(attrName))
            return;

        // This should cover longs, ints and of course, strings.
        String newValue = notification.getNewValue().toString();
        String oldValue = (notification.getOldValue() != null ? notification.getOldValue().toString() : null);

        this.saveElement(attrName, oldValue, newValue);
    }

}

From source file:org.hyperic.hq.product.jmx.MxNotificationListener.java

public synchronized void handleNotification(Notification notification, Object handback) {

    String msg;/*from  w w  w . j av  a  2  s  .com*/
    boolean isAttrChange = notification instanceof AttributeChangeNotification;

    if (log.isDebugEnabled()) {
        log.debug(this.plugin.getName() + " received notification: " + notification);
    }

    if (isAttrChange && this.isConfigTrackEnabled) {
        AttributeChangeNotification change = (AttributeChangeNotification) notification;

        msg = "Attribute: " + change.getAttributeName() + " changed from " + change.getOldValue() + " to "
                + change.getNewValue();
    } else if (this.isLogTrackEnabled) {
        msg = notification.getMessage();
    } else {
        return;
    }

    if (msg == null) {
        Object data = notification.getUserData();
        if (data != null) {
            msg = data.toString();
        } else {
            msg = notification.getType();
        }
    }

    long time = notification.getTimeStamp();

    // Default level to INFO
    int level = LogTrackPlugin.LOGLEVEL_INFO;

    // Check notification.getType() for Error, Warn, Info, Debug (case insensitive)
    String typeString = notification.getType();
    if (typeString != null) {
        if (typeString.equalsIgnoreCase(LogTrackPlugin.LOGLEVEL_ERROR_LABEL)) {
            level = LogTrackPlugin.LOGLEVEL_ERROR;
        } else if (typeString.equalsIgnoreCase(LogTrackPlugin.LOGLEVEL_WARN_LABEL)) {
            level = LogTrackPlugin.LOGLEVEL_WARN;
        } else if (typeString.equalsIgnoreCase(LogTrackPlugin.LOGLEVEL_DEBUG_LABEL)) {
            level = LogTrackPlugin.LOGLEVEL_DEBUG;
        }
    }

    String source = notification.getSource().toString();

    if (isAttrChange) {
        TrackEvent event = new TrackEvent(this.plugin.getName(), time, level, source, msg);
        this.plugin.getManager().reportEvent(event);
    } else {
        //apply filters to msg
        this.plugin.reportEvent(time, level, source, msg);
    }
}

From source file:org.zenoss.jmxnl.NotificationListener.java

public void handleNotification(Notification notification, Object obj) {
    Boolean sendEvent = true;//from w ww.j a  v a  2s  .  co  m
    Boolean reconnect = false;
    String type = notification.getType();

    Map<String, String> evt = new HashMap<String, String>();
    evt.put("device", (String) obj);
    evt.put("severity", "2");
    evt.put("eventClassKey", type);

    if (notification instanceof JMXConnectionNotification) {
        if (type.equals(JMXConnectionNotification.CLOSED)) {
            sendConnectionEvent("4", "JMX connection has been closed");
            reconnect = true;
        } else if (type.equals(JMXConnectionNotification.FAILED)) {
            sendConnectionEvent("4", "JMX connection has failed");
            reconnect = true;
        } else if (type.equals(JMXConnectionNotification.NOTIFS_LOST)) {
            sendConnectionEvent("3", "JMX connection has possibly lost notifications");
        } else if (type.equals(JMXConnectionNotification.OPENED)) {
            sendConnectionEvent("0", "JMX connection has been opened");
        }

        // Event has already been sent
        sendEvent = false;
    } else if (notification instanceof AttributeChangeNotification) {
        AttributeChangeNotification notif = (AttributeChangeNotification) notification;
        evt.put("component", notif.getAttributeName());
        evt.put("eventKey", notif.getSource().toString() + ":" + notif.getAttributeName());
        evt.put("summary", "Attribute changed from " + notif.getOldValue() + " to " + notif.getNewValue());
    } else if (notification instanceof MBeanServerNotification) {
        MBeanServerNotification notif = (MBeanServerNotification) notification;
        evt.put("severity", "1");
        evt.put("component", notif.getMBeanName().getDomain());
        evt.put("eventKey", notif.getMBeanName().toString());
        if (type.equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) {
            evt.put("summary", "MBean Registered");
        } else if (type.equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
            evt.put("summary", "MBean Unregistered");
        } else {
            evt.put("summary", "Unknown MBean Server Notification");
        }

        // These are too noisy and unlikely to be useful
        sendEvent = false;
    } else if (notification instanceof MonitorNotification) {
        MonitorNotification notif = (MonitorNotification) notification;
        evt.put("severity", "3");
        evt.put("component", notif.getObservedObject().toString() + ":" + notif.getObservedAttribute());
        if (type.equals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR)) {
            evt.put("summary", "Observed attribute not contained within the observed object");
        } else if (type.equals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR)) {
            evt.put("summary", "Type of the observed attribute is not correct");
        } else if (type.equals(MonitorNotification.OBSERVED_OBJECT_ERROR)) {
            evt.put("summary", "The observed object is not registered in the MBean server");
        } else if (type.equals(MonitorNotification.RUNTIME_ERROR)) {
            evt.put("summary", "Non pre-defined error has occurred");
        } else if (type.equals(MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED)) {
            evt.put("summary", "Attribute differs from the string to compare");
        } else if (type.equals(MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED)) {
            evt.put("summary", "Attribute matched the string to compare");
        } else if (type.equals(MonitorNotification.THRESHOLD_ERROR)) {
            evt.put("summary", "Type of threshold is not correct");
        } else if (type.equals(MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED)) {
            evt.put("summary", "Attribute has exceeded the threshold high value");
        } else if (type.equals(MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED)) {
            evt.put("summary", "Attribute has exceeded the threshold low value");
        } else if (type.equals(MonitorNotification.THRESHOLD_VALUE_EXCEEDED)) {
            evt.put("summary", "Attribute has reached the threshold value");
        } else {
            evt.put("summary", "Unknown Monitor Notification");
        }
    } else if (notification instanceof RelationNotification) {
        RelationNotification notif = (RelationNotification) notification;
        evt.put("component", notif.getRelationId());
        if (type.equals(RelationNotification.RELATION_BASIC_CREATION)) {
            evt.put("summary", "Internal relation created");
        } else if (type.equals(RelationNotification.RELATION_BASIC_REMOVAL)) {
            evt.put("summary", "Internal relation removed");
        } else if (type.equals(RelationNotification.RELATION_BASIC_UPDATE)) {
            evt.put("summary", "Internal relation updated");
        } else if (type.equals(RelationNotification.RELATION_MBEAN_CREATION)) {
            evt.put("summary", "MBean relation created");
        } else if (type.equals(RelationNotification.RELATION_MBEAN_REMOVAL)) {
            evt.put("summary", "MBean relation removed");
        } else if (type.equals(RelationNotification.RELATION_MBEAN_UPDATE)) {
            evt.put("summary", "MBean relation updated");
        }
    } else {
        if (notification.getMessage().equals("")) {
            evt.put("summary", "Unknown JMX Notification Type");
        } else {
            evt.put("summary", notification.getMessage());
        }
    }

    if (sendEvent) {
        try {
            EventSender.getEventSender().sendEvent(evt);
        } catch (XmlRpcException e) {
            log.error("Error sending event: " + e);
        }
    }

    if (reconnect) {
        run();
    }
}

From source file:org.helios.jzab.agent.net.active.ActiveAgent.java

/**
 * {@inheritDoc}/*from ww w  .  j  ava  2 s.  co  m*/
 * @see javax.management.NotificationListener#handleNotification(javax.management.Notification, java.lang.Object)
 */
@Override
public void handleNotification(Notification notif, Object handback) {
    if (notif instanceof AttributeChangeNotification) {
        AttributeChangeNotification acn = (AttributeChangeNotification) notif;
        log.debug("Handling Attribute Change Notification [{}]", acn);

        if (handback instanceof ActiveHost) {
            ActiveHost host = (ActiveHost) handback;

            if (ActiveHostState.ACTIVE.name().equals(acn.getNewValue())) {
                executeChecks(host);
                return;
            }

            JSONObject results = new JSONObject();
            JSONArray array = new JSONArray();

            for (ActiveHostCheck check : host.getDiscoveryChecks()) {
                try {
                    JSONObject[] checkResults = (JSONObject[]) check.discover();
                    for (JSONObject disc : checkResults) {
                        array.put(disc);
                    }
                } catch (Exception e) {
                }
            }
            try {
                results.put("data", array);
            } catch (Exception e) {
                log.error("JSON Error", e);
            }
            try {
                log.debug("Sending Discovery Check Results\n[{}]", results);
                JSONObject result = ActiveClient.getInstance().requestResponse(results, JSONObject.class,
                        host.getServer(), 2, TimeUnit.SECONDS);
                log.info("Discovery Check Result \n[{}]", result);
            } catch (Exception e) {
                log.error("Failed to execute discovery check submission for [{}]", host, e);
            }
        }
    }
}

From source file:jp.co.acroquest.endosnipe.web.explorer.entity.InvocationModel.java

private void handleExceedThresholdAlarm(final AttributeChangeNotification notification) {
    //setAverage((Long)notification.getOldValue());
    setMaximum((Long) notification.getNewValue());
    this.component_.setExceededThresholdAlarm(this.methodName_);
}