Example usage for javax.management Notification getUserData

List of usage examples for javax.management Notification getUserData

Introduction

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

Prototype

public Object getUserData() 

Source Link

Document

Get the user data.

Usage

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

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

    String msg;//  w  w  w  .j av a 2 s . c om
    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:com.heliosapm.script.AbstractDeployedScript.java

/**
 * Initializes the configuration//from   w w  w  . j a v  a 2s . co  m
 */
public void initConfig() {
    watchedConfig.set(findWatchedConfiguration());
    if (watchedConfig.get() != null) {
        Map<String, String> parentConfig = getParentConfigurationMap();
        if (parentConfig != null && !parentConfig.isEmpty()) {
            this.getConfiguration().load(parentConfig);
        }
        if (watchedConfigListenerRegistered.compareAndSet(false, true)) {
            try {
                JMXHelper.addNotificationListener(watchedConfig.get(), configChangeListener,
                        new NotificationFilter() {
                            /**  */
                            private static final long serialVersionUID = -2890751194005498532L;

                            @Override
                            public boolean isNotificationEnabled(final Notification notification) {
                                final Object userData = notification.getUserData();
                                return (notification.getSource().equals(watchedConfig.get())
                                        && NOTIF_CONFIG_MOD.equals(notification.getType()) && userData != null
                                        && (userData instanceof Configuration)
                                        && !(((Configuration) userData).isEmpty()));
                            }
                        }, null);
            } catch (Exception ex) {
                try {
                    JMXHelper.removeNotificationListener(watchedConfig.get(), configChangeListener);
                } catch (Exception x) {
                    /* No Op */}
                log.error("Failed to register configuration listener", ex);
                watchedConfigListenerRegistered.set(false);
            }
        }
    }
}

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  w  w  w  .  j  a  v a  2 s  . c om
            // 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:org.apache.giraph.graph.GraphTaskManager.java

/**
 * Install GC monitoring. This method intercepts all GC, log the gc, and
 * notifies an out-of-core engine (if any is used) about the GC.
 *///from   w ww. j av  a 2  s . c o  m
private void installGCMonitoring() {
    List<GarbageCollectorMXBean> mxBeans = ManagementFactory.getGarbageCollectorMXBeans();
    final OutOfCoreEngine oocEngine = serviceWorker.getServerData().getOocEngine();
    for (GarbageCollectorMXBean gcBean : mxBeans) {
        NotificationEmitter emitter = (NotificationEmitter) gcBean;
        NotificationListener listener = new NotificationListener() {
            @Override
            public void handleNotification(Notification notification, Object handle) {
                if (notification.getType()
                        .equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
                    GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo
                            .from((CompositeData) notification.getUserData());

                    if (LOG.isInfoEnabled()) {
                        LOG.info("installGCMonitoring: name = " + info.getGcName() + ", action = "
                                + info.getGcAction() + ", cause = " + info.getGcCause() + ", duration = "
                                + info.getGcInfo().getDuration() + "ms");
                    }
                    gcTimeMetric.inc(info.getGcInfo().getDuration());
                    if (oocEngine != null) {
                        oocEngine.gcCompleted(info);
                    }
                }
            }
        };
        //Add the listener
        emitter.addNotificationListener(listener, null, null);
    }
}

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

/**
 * System Notification Listener//from  w ww . j  a  v  a 2 s. com
 */
@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//from   w  w 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());
            }
        }
    }
}