javax.management.relation.MBeanServerNotificationFilter Java Examples

The following examples show how to use javax.management.relation.MBeanServerNotificationFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JmxMetricTracker.java    From apm-agent-java with Apache License 2.0 6 votes vote down vote up
private void registerMBeanNotificationListener(final MBeanServer server) {
    MBeanServerNotificationFilter filter = new MBeanServerNotificationFilter();
    filter.enableAllObjectNames();
    filter.enableType(MBeanServerNotification.REGISTRATION_NOTIFICATION);
    listener = new NotificationListener() {
        @Override
        public void handleNotification(Notification notification, Object handback) {
            if (notification instanceof MBeanServerNotification) {
                ObjectName mBeanName = ((MBeanServerNotification) notification).getMBeanName();
                for (JmxMetric jmxMetric : jmxConfiguration.getCaptureJmxMetrics().get()) {
                    if (jmxMetric.getObjectName().apply(mBeanName)) {
                        logger.debug("MBean added at runtime: {}", jmxMetric.getObjectName());
                        register(Collections.singletonList(jmxMetric), server);
                    }
                }
            }
        }
    };
    try {
        server.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, filter, null);
    } catch (InstanceNotFoundException e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example #2
Source File: JmxDumper.java    From helix with Apache License 2.0 6 votes vote down vote up
public JmxDumper(String jmxService, String domain, String beanClassName, String namePattern,
    int samplePeriod, List<String> fields, List<String> operations, String outputfile,
    int sampleCount) throws Exception {
  _jmxUrl = jmxService;
  _domain = domain;
  _beanClassName = beanClassName;
  _samplePeriod = samplePeriod;
  _outputFields.addAll(fields);
  _operations.addAll(operations);
  _outputFileName = outputfile;
  _namePattern = namePattern;
  _targetSamples = sampleCount;

  JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + _jmxUrl + "/jmxrmi");
  JMXConnector jmxc = JMXConnectorFactory.connect(url, null);

  _mbeanServer = jmxc.getMBeanServerConnection();
  MBeanServerNotificationFilter filter = new MBeanServerNotificationFilter();
  filter.enableAllObjectNames();
  _mbeanServer.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, this, filter, null);
  init();
  _timer = new Timer(true);
  _timer.scheduleAtFixedRate(new SampleTask(), _samplePeriod, _samplePeriod);
}
 
Example #3
Source File: ClusterMBeanObserver.java    From helix with Apache License 2.0 5 votes vote down vote up
public ClusterMBeanObserver(String domain) throws IOException, InstanceNotFoundException {
  // Get a reference to the target MBeanServer
  _domain = domain;
  _server = ManagementFactory.getPlatformMBeanServer();
  MBeanServerNotificationFilter filter = new MBeanServerNotificationFilter();
  filter.enableAllObjectNames();
  _server.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, this, filter, null);
}
 
Example #4
Source File: ClusterMBeanObserver.java    From helix with Apache License 2.0 5 votes vote down vote up
public void disconnect() {
  MBeanServerNotificationFilter filter = new MBeanServerNotificationFilter();
  try {
    _server.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, this);
  } catch (Exception e) {
    _logger.error("", e);
  }
}