Example usage for javax.management Notification getMessage

List of usage examples for javax.management Notification getMessage

Introduction

In this page you can find the example usage for javax.management Notification getMessage.

Prototype

public String getMessage() 

Source Link

Document

Get the notification message.

Usage

From source file:org.apache.cassandra.tools.NodeProbe.java

public void handleNotification(Notification notification, Object handback) {
    if ("repair".equals(notification.getType())) {
        int[] status = (int[]) notification.getUserData();
        assert status.length == 2;
        if (cmd == status[0]) {
            String message = String.format("[%s] %s", format.format(notification.getTimeStamp()),
                    notification.getMessage());
            out.println(message);/*from www. j av a2 s. c  o  m*/
            // repair status is int array with [0] = cmd number, [1] = status
            if (status[1] == ActiveRepairService.Status.SESSION_FAILED.ordinal())
                success = false;
            else if (status[1] == ActiveRepairService.Status.FINISHED.ordinal())
                condition.signalAll();
        }
    } else if (JMXConnectionNotification.NOTIFS_LOST.equals(notification.getType())) {
        String message = String.format(
                "[%s] Lost notification. You should check server log for repair status of keyspace %s",
                format.format(notification.getTimeStamp()), keyspace);
        out.println(message);
    } else if (JMXConnectionNotification.FAILED.equals(notification.getType())
            || JMXConnectionNotification.CLOSED.equals(notification.getType())) {
        String message = String
                .format("JMX connection closed. You should check server log for repair status of keyspace %s"
                        + "(Subsequent keyspaces are not going to be repaired).", keyspace);
        error = new IOException(message);
        condition.signalAll();
    }
}

From source file:com.pivotal.gemfire.tools.pulse.internal.data.JMXDataUpdater.java

/**
 * System Notification Listener//from   w  w  w  . j  av a 2s .c  o  m
 */
@Override
public void handleNotification(Notification notification, Object handback) {
    String type = notification.getType();

    if (PulseConstants.NOTIFICATION_TYPE_SYSTEM_ALERT.equals(type)) {
        Cluster.Alert alert = new Cluster.Alert();
        Long timeStamp = notification.getTimeStamp();
        Date date = new Date(timeStamp);
        alert.setTimestamp(date);
        String notificationSource = (String) notification.getUserData();
        alert.setMemberName(notificationSource);
        String alertDescription = notification.getMessage();
        if (alertDescription.startsWith("[error")) {
            alert.setSeverity(Cluster.Alert.ERROR);
        } else if (alertDescription.startsWith("[warning")) {
            alert.setSeverity(Cluster.Alert.WARNING);
        } else if (alertDescription.startsWith("[severe")) {
            alert.setSeverity(Cluster.Alert.SEVERE);
        } else {
            alert.setSeverity(Cluster.Alert.INFO);
        }
        alert.setDescription(notification.getMessage());
        alert.setAcknowledged(false);
        alert.setId(Cluster.Alert.nextID());
        cluster.addAlert(alert);
    } else {
        Cluster.Alert alert = new Cluster.Alert();
        Long timeStamp = notification.getTimeStamp();
        Date date = new Date(timeStamp);
        alert.setTimestamp(date);
        String notificationSource = (String) notification.getSource();
        alert.setMemberName(notificationSource);
        String alertDescription = notification.getMessage();
        alert.setDescription(alertDescription);

        alert.setSeverity(Cluster.Alert.INFO);

        alert.setAcknowledged(false);
        alert.setId(Cluster.Alert.nextID());
        cluster.addAlert(alert);
    }
}

From source file:edu.nwpu.gemfire.monitor.data.JMXDataUpdater.java

/**
 * System Notification Listener/*ww w  .  j a v a2s  .c o m*/
 */
@Override
public void handleNotification(Notification notification, Object handback) {
    String type = notification.getType();

    if (PulseConstants.NOTIFICATION_TYPE_SYSTEM_ALERT.equals(type)) {
        Cluster.Alert alert = new Cluster.Alert();
        Long timeStamp = notification.getTimeStamp();
        Date date = new Date(timeStamp);
        alert.setTimestamp(date);
        String notificationSource = (String) notification.getUserData();
        alert.setMemberName(notificationSource);
        String alertDescription = notification.getMessage();
        if (alertDescription.startsWith("[error")) {
            alert.setSeverity(Cluster.Alert.ERROR);
        } else if (alertDescription.startsWith("[warning")) {
            alert.setSeverity(Cluster.Alert.WARNING);
        } else if (alertDescription.startsWith("[severe")) {
            alert.setSeverity(Cluster.Alert.SEVERE);
        } else {
            alert.setSeverity(Cluster.Alert.INFO);
        }
        alert.setDescription(notification.getMessage());
        alert.setAcknowledged(false);
        alert.setId(Cluster.Alert.nextID());
        cluster.addAlert(alert);
    } else {
        Cluster.Alert alert = new Cluster.Alert();
        Long timeStamp = notification.getTimeStamp();
        Date date = new Date(timeStamp);
        alert.setTimestamp(date);
        String notificationSource = (String) notification.getSource();
        alert.setMemberName(notificationSource);
        String alertDescription = notification.getMessage();
        alert.setDescription(alertDescription);

        alert.setSeverity(Cluster.Alert.INFO);

        alert.setAcknowledged(false);
        alert.setId(Cluster.Alert.nextID());
        cluster.addAlert(alert);

        if (PulseConstants.NOTIFICATION_TYPE_REGION_DESTROYED.equals(type)) {
            // Remove deleted region from member's regions list
            String msg = notification.getMessage();
            String deletedRegion = msg.substring(msg.indexOf("Name ") + "Name ".length());
            String memberName = notificationSource;
            Cluster.Member member = cluster.getMembersHMap().get(memberName);

            if (member.getMemberRegions().get(deletedRegion) != null) {
                member.getMemberRegions().remove(deletedRegion);
                member.setTotalRegionCount(member.getMemberRegions().size());
            }
        }
    }
}

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

public void handleNotification(Notification notification, Object obj) {
    Boolean sendEvent = true;/*from   w  ww  . j  av a  2  s.  c om*/
    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();
    }
}