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

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

package org.gridkit.nimble.probe.jmx;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.management.MBeanServerConnection;

import org.gridkit.lab.jvm.attach.AttachManager;
import org.gridkit.lab.jvm.attach.JavaProcessId;
import org.gridkit.lab.jvm.attach.JavaProcessMatcher;

public class AttachMBeanConnector implements MBeanConnector, Serializable {

	private static final long serialVersionUID = 20121027L;
	
	private final JavaProcessMatcher processMatcher;
	
	public AttachMBeanConnector(JavaProcessMatcher processMatcher) {
		this.processMatcher = processMatcher;
	}

	@Override
	public Collection connect() {
		List result = new ArrayList();
		for(JavaProcessId id: AttachManager.listJavaProcesses(processMatcher)) {
			MBeanServerConnection conn = AttachManager.getJmxConnection(id);
			if (conn != null) {
				result.add(conn);
				System.out.println("Matched [" + processMatcher + "] " + id);
			}
		}
		return result;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy