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

org.gridkit.lab.util.jmx.mxstruct.MXHelper Maven / Gradle / Ivy

package org.gridkit.lab.util.jmx.mxstruct;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.openmbean.CompositeData;


public class MXHelper {

	public static  Map collectBeans(MBeanServerConnection conn, ObjectName pattern, V proto) throws IOException, ReflectionException {
		Map result = new LinkedHashMap();
		for(ObjectName name: conn.queryNames(pattern, null)) {
			StringBuffer sb = new StringBuffer();
			for(String key: pattern.getKeyPropertyList().keySet()) {
				String val = pattern.getKeyProperty(key);
				if ("*".equals(val)) {
					if (sb.length() > 0) {
						sb.append(',');
					}
					sb.append(name.getKeyProperty(key));
				}				
			}
			V mstruct = proto.read(conn, name);
			result.put(sb.toString(), mstruct);
		}
		return result;
	}	

	public static  V parseComposite(CompositeData cdata, V proto) throws IOException, ReflectionException {
		return proto.read(cdata);
	}	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy