All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gridkit.nimble.probe.jmx.MBeanProbe Maven / Gradle / Ivy

The newest version!
package org.gridkit.nimble.probe.jmx;

import java.io.Serializable;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;

import org.gridkit.lab.monitoring.probe.PollProbe;
import org.gridkit.lab.monitoring.probe.PollProbeDeployer;
import org.gridkit.lab.monitoring.probe.SamplerProvider;

public class MBeanProbe implements PollProbeDeployer, Serializable {

	private static final long serialVersionUID = 20121017L;
	
	@Override
	public PollProbe deploy(MBeanTarget target, SamplerProvider provider) {
		MBeanSampler sampler = provider.getSampler(target);
		if (sampler == null) {
			return null;
		}
		else {
			return new MBeanTracker(target.getConnection(), target.getMbeanName(), sampler);
		}
	}
	
	private static class MBeanTracker implements PollProbe {
		
		MBeanServerConnection connection;
		ObjectName name;
		MBeanSampler sampler;
		
		public MBeanTracker(MBeanServerConnection connection, ObjectName name, MBeanSampler sampler) {
			this.connection = connection;
			this.name = name;
			this.sampler = sampler;
		}

		@Override
		public void poll() {
			try {
				// validate connection
				connection.getMBeanCount();
			}
			catch(Exception e) {
				return;
			}
			sampler.report(connection, name);
		}

		@Override
		public void stop() {
			// do nothing			
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy