Example usage for javax.management NotificationFilter NotificationFilter

List of usage examples for javax.management NotificationFilter NotificationFilter

Introduction

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

Prototype

NotificationFilter

Source Link

Usage

From source file:co.paralleluniverse.common.monitoring.PeriodicMonitor.java

private void registerMBean() {
    try {/*from  w  w  w .java 2  s . c  o m*/
        LOG.info("Registering MBean {}", name);
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName mxbeanName = new ObjectName(name);
        mbs.registerMBean(this, mxbeanName);

        timer.addNotificationListener(this, new NotificationFilter() {
            @Override
            public boolean isNotificationEnabled(Notification notification) {
                return "tickTimer".equals(notification.getType());
            }
        }, null);
        this.registered = true;
    } catch (InstanceAlreadyExistsException ex) {
        throw new RuntimeException(ex);
    } catch (MBeanRegistrationException ex) {
        throw new RuntimeException(ex);
    } catch (NotCompliantMBeanException ex) {
        throw new AssertionError(ex);
    } catch (MalformedObjectNameException ex) {
        throw new AssertionError(ex);
    }
}

From source file:com.heliosapm.script.AbstractDeployedScript.java

/**
 * Initializes the configuration//from   w w  w .  j  a va2s.c  om
 */
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);
            }
        }
    }
}