下面列出了javax.management.MBeanServerConnection#queryNames ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* test JMX connection to DataNode..
* @throws Exception
*/
@Test
public void testDataNode() throws Exception {
int numDatanodes = 2;
cluster = new MiniDFSCluster.Builder(config).numDataNodes(numDatanodes).build();
cluster.waitActive();
writeFile(cluster.getFileSystem(), new Path("/test"), 2);
JMXGet jmx = new JMXGet();
String serviceName = "DataNode";
jmx.setService(serviceName);
jmx.init();
assertEquals(fileSize, Integer.parseInt(jmx.getValue("BytesWritten")));
cluster.shutdown();
MBeanServerConnection mbsc = ManagementFactory.getPlatformMBeanServer();
ObjectName query = new ObjectName("Hadoop:service=" + serviceName + ",*");
Set<ObjectName> names = mbsc.queryNames(query, null);
assertTrue("No beans should be registered for " + serviceName, names.isEmpty());
}
private void checkQueryMBeans(MBeanServerConnection connection, int count, ObjectName filter) throws Exception {
Set<ObjectInstance> instances = connection.queryMBeans(filter, null);
Set<ObjectName> objectNames = connection.queryNames(filter, null);
Assert.assertEquals(count, instances.size());
Assert.assertEquals(count, objectNames.size());
checkSameMBeans(instances, objectNames);
final ObjectName[] names = {LEGACY_ROOT_NAME, LEGACY_INTERFACE_NAME, LEGACY_SOCKET_BINDING_GROUP_NAME, LEGACY_SERVER_SOCKET_BINDING_NAME, LEGACY_SUBSYSTEM_NAME,
EXPR_ROOT_NAME, EXPR_INTERFACE_NAME, EXPR_SOCKET_BINDING_GROUP_NAME, EXPR_SERVER_SOCKET_BINDING_NAME, EXPR_SUBSYSTEM_NAME};
assertContainsNames(objectNames, names);
for (ObjectName name : names) {
checkQuerySingleMBean(connection, name);
}
}
private static void printAttrs(
MBeanServerConnection mbsc1, Class<? extends Exception> expectX)
throws Exception {
Set<ObjectName> names = mbsc1.queryNames(null, null);
for (ObjectName name : names) {
System.out.println(name + ":");
MBeanInfo mbi = mbsc1.getMBeanInfo(name);
MBeanAttributeInfo[] mbais = mbi.getAttributes();
for (MBeanAttributeInfo mbai : mbais) {
String attr = mbai.getName();
Object value;
try {
value = mbsc1.getAttribute(name, attr);
} catch (Exception e) {
if (expectX != null && expectX.isInstance(e))
value = "<" + e + ">";
else
throw e;
}
String s = " " + attr + " = " + value;
if (s.length() > 80)
s = s.substring(0, 77) + "...";
System.out.println(s);
}
}
}
private <T> Map<String, T> getMetricValues(String group, String metric, String attribute) {
try {
StringBuilder nameBuilder = new StringBuilder();
nameBuilder.append(JmxUtil.makeNameJmxSafe(group));
nameBuilder.append(":type=*,name=");
nameBuilder.append(JmxUtil.makeNameJmxSafe(metric));
ObjectName query = new ObjectName(nameBuilder.toString());
Map<String, T> values = new HashMap<>();
MBeanServerConnection conn = jmxc.getMBeanServerConnection();
for (ObjectName objName : conn.queryNames(query, null)) {
String type = objName.getKeyProperty("type");
T val = (T) conn.getAttribute(objName, attribute);
values.put(type, val);
}
return values;
} catch (Exception e) {
log.error(e.getMessage(), e);
return Collections.EMPTY_MAP;
}
}
private static void printAttrs(
MBeanServerConnection mbsc1, Class<? extends Exception> expectX)
throws Exception {
Set<ObjectName> names = mbsc1.queryNames(null, null);
for (ObjectName name : names) {
System.out.println(name + ":");
MBeanInfo mbi = mbsc1.getMBeanInfo(name);
MBeanAttributeInfo[] mbais = mbi.getAttributes();
for (MBeanAttributeInfo mbai : mbais) {
String attr = mbai.getName();
Object value;
try {
value = mbsc1.getAttribute(name, attr);
} catch (Exception e) {
if (expectX != null && expectX.isInstance(e))
value = "<" + e + ">";
else
throw e;
}
String s = " " + attr + " = " + value;
if (s.length() > 80)
s = s.substring(0, 77) + "...";
System.out.println(s);
}
}
}
public static List<String> checkForMBeanProxies(MBeanServerConnection server,List<String> listOFNS, Map<String,String> map) throws IOException{
logInfo("Checking " + listOFNS + " names on server "+ server);
try {
Set<ObjectName> objectNames = server.queryNames(null, null);
logFine("Mbean Set registered at platform mbean server after federation : " + objectNames);
for(ObjectName n : objectNames){
for(String s : map.values())
if(n.toString().contains(s)){
listOFNS.remove(s);
}
}
logInfo("Final count of remaining mbeans not present in Manager view : " + listOFNS.size() + " List : " + listOFNS);
return listOFNS;
} finally{
}
}
@Override
public void setup(MBeanServerConnection mbs, OperatorContext context) throws InstanceNotFoundException, Exception {
seq.increment();
ObjectName consistentWildcard = ObjectName.getInstance("com.ibm.streams.control:type=consistent,index=*");
Set<ObjectName> regions = mbs.queryNames(consistentWildcard, null);
if (regions.isEmpty()) {
fail.setValue(1);
trace.severe("No consistent regions!");
return;
}
for (ObjectName name : regions) {
ConsistentRegionMXBean crbean = JMX.newMXBeanProxy(mbs, name,
ConsistentRegionMXBean.class, true);
if (trace.isLoggable(Level.FINE))
trace.fine("Discovered consistent region: " + crbean.getName());
String metricName = "nResets." + crbean.getName();
Metric resetCount;
try {
resetCount = context.getMetrics().createCustomMetric(metricName, "Requested resets for region", Metric.Kind.COUNTER);
} catch (IllegalArgumentException e) {
resetCount = context.getMetrics().getCustomMetric(metricName);
}
resetCounts.add(resetCount);
scheduleReset(crbean, resetCount);
seq.increment();
}
}
private void testAllMBeanInfos(MBeanServerConnection connection) throws Exception {
Set<ObjectName> names = connection.queryNames(RESOLVED_MODEL_FILTER, null);
Map<ObjectName, Exception> failedInfos = new HashMap<ObjectName, Exception>();
for (ObjectName name : names) {
try {
Assert.assertNotNull(connection.getMBeanInfo(name));
} catch (Exception e) {
System.out.println("Error getting info for " + name);
failedInfos.put(name, e);
}
}
Assert.assertTrue(failedInfos.toString(), failedInfos.isEmpty());
}
private final int doGarbageCollectorMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0 ;
System.out.println("---- GarbageCollectorMXBean") ;
try {
ObjectName filterName =
new ObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
+ ",*");
Set<ObjectName> onSet = mbsc.queryNames(filterName, null);
for (Iterator<ObjectName> iter = onSet.iterator(); iter.hasNext(); ) {
ObjectName garbageName = iter.next() ;
System.out.println("-------- " + garbageName) ;
MBeanInfo mbInfo = mbsc.getMBeanInfo(garbageName);
errorCount += checkNonEmpty(mbInfo);
System.out.println("getMBeanInfo\t\t" + mbInfo);
GarbageCollectorMXBean garbage = null ;
garbage =
JMX.newMXBeanProxy(mbsc,
garbageName,
GarbageCollectorMXBean.class) ;
System.out.println("getCollectionCount\t\t"
+ garbage.getCollectionCount());
System.out.println("getCollectionTime\t\t"
+ garbage.getCollectionTime());
}
System.out.println("---- OK\n") ;
} catch (Exception e) {
Utils.printThrowable(e, true) ;
errorCount++ ;
System.out.println("---- ERROR\n") ;
}
return errorCount ;
}
public static boolean checkForManagerMBean(MBeanServerConnection server) throws IOException{
try {
Set<ObjectName> objectNames = server.queryNames(null, null);
boolean flag = false;
for(ObjectName n : objectNames){
if(n.equals(MBeanJMXAdapter.getManagerName())){
flag = true;
logFine("Found ManagerMBean " + n + " in gemfire mbean set");
break;
}
}
return flag;
} finally{
}
}
private final int doGarbageCollectorMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0 ;
System.out.println("---- GarbageCollectorMXBean") ;
try {
ObjectName filterName =
new ObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
+ ",*");
Set<ObjectName> onSet = mbsc.queryNames(filterName, null);
for (Iterator<ObjectName> iter = onSet.iterator(); iter.hasNext(); ) {
ObjectName garbageName = iter.next() ;
System.out.println("-------- " + garbageName) ;
MBeanInfo mbInfo = mbsc.getMBeanInfo(garbageName);
errorCount += checkNonEmpty(mbInfo);
System.out.println("getMBeanInfo\t\t" + mbInfo);
GarbageCollectorMXBean garbage = null ;
garbage =
JMX.newMXBeanProxy(mbsc,
garbageName,
GarbageCollectorMXBean.class) ;
System.out.println("getCollectionCount\t\t"
+ garbage.getCollectionCount());
System.out.println("getCollectionTime\t\t"
+ garbage.getCollectionTime());
}
System.out.println("---- OK\n") ;
} catch (Exception e) {
Utils.printThrowable(e, true) ;
errorCount++ ;
System.out.println("---- ERROR\n") ;
}
return errorCount ;
}
/**
* Call Mbean server for some mbeans with same domain, attributes.
* with <em>attributebinding=true</em> you can save all attributes from all found objects
* as your ant properties
* @param jmxServerConnection
* @param qry
* @return The query result
*/
protected String jmxQuery(MBeanServerConnection jmxServerConnection,
String qry) {
String isError = null;
Set<ObjectName> names = null;
String resultproperty = getResultproperty();
try {
names = jmxServerConnection.queryNames(new ObjectName(qry), null);
if (resultproperty != null) {
setProperty(resultproperty + ".Length",Integer.toString(names.size()));
}
} catch (Exception e) {
if (isEcho())
handleErrorOutput(e.getMessage());
return "Can't query mbeans " + qry;
}
if (resultproperty != null) {
Iterator<ObjectName> it = names.iterator();
int oindex = 0;
String pname = null;
while (it.hasNext()) {
ObjectName oname = it.next();
pname = resultproperty + "." + Integer.toString(oindex) + ".";
oindex++;
setProperty(pname + "Name", oname.toString());
if (isAttributebinding()) {
bindAttributes(jmxServerConnection, resultproperty, pname, oname);
}
}
}
return isError;
}
protected static String getMemberId(final String jmxManagerHost, final int jmxManagerPort, final String memberName)
throws Exception
{
JMXConnector connector = null;
try {
connector = JMXConnectorFactory.connect(new JMXServiceURL(String.format(
"service:jmx:rmi://%1$s/jndi/rmi://%1$s:%2$d/jmxrmi", jmxManagerHost, jmxManagerPort)));
final MBeanServerConnection connection = connector.getMBeanServerConnection();
final ObjectName objectNamePattern = ObjectName.getInstance("GemFire:type=Member,*");
final QueryExp query = Query.eq(Query.attr("Name"), Query.value(memberName));
final Set<ObjectName> objectNames = connection.queryNames(objectNamePattern, query);
assertNotNull(objectNames);
assertEquals(1, objectNames.size());
//final ObjectName objectName = ObjectName.getInstance("GemFire:type=Member,Name=" + memberName);
final ObjectName objectName = objectNames.iterator().next();
//System.err.printf("ObjectName for Member with Name (%1$s) is %2$s%n", memberName, objectName);
return ObjectUtils.toString(connection.getAttribute(objectName, "Id"));
}
finally {
IOUtils.close(connector);
}
}
private final int doMemoryManagerMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0 ;
System.out.println("---- MemoryManagerMXBean") ;
try {
ObjectName filterName =
new ObjectName(ManagementFactory.MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE
+ ",*");
Set<ObjectName> onSet = mbsc.queryNames(filterName, null);
for (Iterator<ObjectName> iter = onSet.iterator(); iter.hasNext(); ) {
ObjectName memoryManagerName = iter.next() ;
System.out.println("-------- " + memoryManagerName) ;
MBeanInfo mbInfo = mbsc.getMBeanInfo(memoryManagerName);
System.out.println("getMBeanInfo\t\t" + mbInfo);
errorCount += checkNonEmpty(mbInfo);
MemoryManagerMXBean memoryManager = null;
memoryManager =
JMX.newMXBeanProxy(mbsc,
memoryManagerName,
MemoryManagerMXBean.class) ;
System.out.println("getMemoryPoolNames\t\t"
+ Arrays.deepToString(memoryManager.getMemoryPoolNames()));
System.out.println("getName\t\t"
+ memoryManager.getName());
System.out.println("isValid\t\t"
+ memoryManager.isValid());
}
System.out.println("---- OK\n") ;
} catch (Exception e) {
Utils.printThrowable(e, true) ;
errorCount++ ;
System.out.println("---- ERROR\n") ;
}
return errorCount ;
}
private Set<ObjectName> getMetricObjectNames(MBeanServerConnection mbs) {
Set<ObjectName> objectNames = null;
try {
objectNames = mbs.queryNames(null, null);
} catch (IOException e) {
LOG.error("Failed to get object names", e);
}
return objectNames;
}
private final int doGarbageCollectorMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0 ;
System.out.println("---- GarbageCollectorMXBean") ;
try {
ObjectName filterName =
new ObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
+ ",*");
Set<ObjectName> onSet = mbsc.queryNames(filterName, null);
for (Iterator<ObjectName> iter = onSet.iterator(); iter.hasNext(); ) {
ObjectName garbageName = iter.next() ;
System.out.println("-------- " + garbageName) ;
MBeanInfo mbInfo = mbsc.getMBeanInfo(garbageName);
errorCount += checkNonEmpty(mbInfo);
System.out.println("getMBeanInfo\t\t" + mbInfo);
GarbageCollectorMXBean garbage = null ;
garbage =
JMX.newMXBeanProxy(mbsc,
garbageName,
GarbageCollectorMXBean.class) ;
System.out.println("getCollectionCount\t\t"
+ garbage.getCollectionCount());
System.out.println("getCollectionTime\t\t"
+ garbage.getCollectionTime());
}
System.out.println("---- OK\n") ;
} catch (Exception e) {
Utils.printThrowable(e, true) ;
errorCount++ ;
System.out.println("---- ERROR\n") ;
}
return errorCount ;
}
private void validateStatementStatistics(boolean expectedBeans, MBeanServerConnection mbeanServer, String memberId)
throws MalformedObjectNameException, IOException, TestException {
String statementONStr = statementONTemplate.replace("{0}", memberId);
statementONStr = statementONStr.replace("{1}", "*");
ObjectName statementON = new ObjectName(statementONStr);
Set<ObjectName> set = mbeanServer.queryNames(statementON, null);
Log.getLogWriter().info("Statement MBeans found " + HydraUtil.ObjectToString(set));
if (expectedBeans) {
if (set.size() == 0)
throw new TestException("Found 0 Statement Mbeans");
} else {
if (set.size() > 0)
throw new TestException("Found " + set.size() + " Statement Mbeans when expecting zero mbeans");
}
}
private final int doMemoryPoolMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0 ;
System.out.println("---- MemoryPoolMXBean") ;
try {
ObjectName filterName =
new ObjectName(ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE
+ ",*");
Set<ObjectName> onSet = mbsc.queryNames(filterName, null);
for (Iterator<ObjectName> iter = onSet.iterator(); iter.hasNext(); ) {
ObjectName memoryPoolName = iter.next() ;
System.out.println("-------- " + memoryPoolName) ;
MBeanInfo mbInfo = mbsc.getMBeanInfo(memoryPoolName);
errorCount += checkNonEmpty(mbInfo);
System.out.println("getMBeanInfo\t\t" + mbInfo);
MemoryPoolMXBean memoryPool = null;
memoryPool =
JMX.newMXBeanProxy(mbsc,
memoryPoolName,
MemoryPoolMXBean.class,
true) ;
System.out.println("getCollectionUsage\t\t"
+ memoryPool.getCollectionUsage());
System.out.println("getMemoryManagerNames\t\t"
+ Arrays.deepToString(memoryPool.getMemoryManagerNames()));
System.out.println("getName\t\t"
+ memoryPool.getName());
System.out.println("getPeakUsage\t\t"
+ memoryPool.getPeakUsage());
System.out.println("getType\t\t"
+ memoryPool.getType());
System.out.println("getUsage\t\t"
+ memoryPool.getUsage());
System.out.println("isValid\t\t"
+ memoryPool.isValid());
boolean supported = memoryPool.isUsageThresholdSupported() ;
System.out.println("isUsageThresholdSupported\t\t"
+ supported);
if ( supported ) {
System.out.println("getUsageThreshold\t\t"
+ memoryPool.getUsageThreshold());
System.out.println("isUsageThresholdExceeded\t\t"
+ memoryPool.isUsageThresholdExceeded());
System.out.println("getUsageThresholdCount\t\t"
+ memoryPool.getUsageThresholdCount());
}
supported = memoryPool.isCollectionUsageThresholdSupported() ;
System.out.println("isCollectionUsageThresholdSupported\t\t"
+ supported);
if ( supported ) {
System.out.println("getCollectionUsageThreshold\t\t"
+ memoryPool.getCollectionUsageThreshold());
System.out.println("getCollectionUsageThresholdCount\t\t"
+ memoryPool.getCollectionUsageThresholdCount());
System.out.println("isCollectionUsageThresholdExceeded\t\t"
+ memoryPool.isCollectionUsageThresholdExceeded());
}
memoryPool.resetPeakUsage();
}
System.out.println("---- OK\n") ;
} catch (Exception e) {
Utils.printThrowable(e, true) ;
errorCount++ ;
System.out.println("---- ERROR\n") ;
}
return errorCount ;
}
@Test
public void testAddMethodSiblingChildren() throws Exception {
final ObjectName testObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test");
final ObjectName child1ObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test,siblings=test1");
final ObjectName child2ObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test,siblings=test2");
MBeanServerConnection connection = setupAndGetConnection(new MBeanInfoAdditionalInitialization(ProcessType.STANDALONE_SERVER, new SubystemWithSiblingChildrenChildExtension()));
Set<ObjectName> names = connection.queryNames(createObjectName(LEGACY_DOMAIN + ":subsystem=test,*"), null);
Assert.assertEquals(1, names.size());
Assert.assertTrue(names.contains(testObjectName));
MBeanInfo subsystemInfo = connection.getMBeanInfo(testObjectName);
Assert.assertEquals(0, subsystemInfo.getAttributes().length);
Assert.assertEquals(1, subsystemInfo.getOperations().length);
OpenMBeanOperationInfo op = findOperation(subsystemInfo.getOperations(), "addSiblings");
Assert.assertEquals("add", op.getDescription());
Assert.assertEquals(2, op.getSignature().length);
Assert.assertEquals(String.class.getName(), op.getSignature()[0].getType());
Assert.assertEquals(Integer.class.getName(), op.getSignature()[1].getType());
connection.invoke(testObjectName, "addSiblings", new Object[]{"test1", 123}, new String[]{String.class.getName(), String.class.getName()});
names = connection.queryNames(createObjectName(LEGACY_DOMAIN + ":subsystem=test,*"), null);
Assert.assertEquals(2, names.size());
Assert.assertTrue(names.contains(testObjectName));
Assert.assertTrue(names.contains(child1ObjectName));
subsystemInfo = connection.getMBeanInfo(testObjectName);
Assert.assertEquals(0, subsystemInfo.getAttributes().length);
Assert.assertEquals(1, subsystemInfo.getOperations().length);
op = findOperation(subsystemInfo.getOperations(), "addSiblings");
Assert.assertEquals("add", op.getDescription());
Assert.assertEquals(2, op.getSignature().length);
Assert.assertEquals(String.class.getName(), op.getSignature()[0].getType());
Assert.assertEquals(Integer.class.getName(), op.getSignature()[1].getType());
MBeanInfo childInfo = connection.getMBeanInfo(child1ObjectName);
Assert.assertEquals(1, childInfo.getAttributes().length);
Assert.assertEquals(Integer.class.getName(), childInfo.getAttributes()[0].getType());
Assert.assertEquals(1, childInfo.getOperations().length);
op = findOperation(childInfo.getOperations(), REMOVE);
Assert.assertEquals("remove", op.getDescription());
Assert.assertEquals(0, op.getSignature().length);
connection.invoke(testObjectName, "addSiblings", new Object[]{"test2", 456}, new String[]{String.class.getName(), String.class.getName()});
names = connection.queryNames(createObjectName(LEGACY_DOMAIN + ":subsystem=test,*"), null);
Assert.assertEquals(3, names.size());
Assert.assertTrue(names.contains(testObjectName));
Assert.assertTrue(names.contains(child1ObjectName));
Assert.assertTrue(names.contains(child2ObjectName));
subsystemInfo = connection.getMBeanInfo(testObjectName);
Assert.assertEquals(0, subsystemInfo.getAttributes().length);
Assert.assertEquals(1, subsystemInfo.getOperations().length);
op = findOperation(subsystemInfo.getOperations(), "addSiblings");
Assert.assertEquals("add", op.getDescription());
Assert.assertEquals(2, op.getSignature().length);
Assert.assertEquals(String.class.getName(), op.getSignature()[0].getType());
Assert.assertEquals(Integer.class.getName(), op.getSignature()[1].getType());
childInfo = connection.getMBeanInfo(child1ObjectName);
Assert.assertEquals(1, childInfo.getAttributes().length);
Assert.assertEquals(Integer.class.getName(), childInfo.getAttributes()[0].getType());
Assert.assertEquals(1, childInfo.getOperations().length);
op = findOperation(childInfo.getOperations(), REMOVE);
Assert.assertEquals("remove", op.getDescription());
Assert.assertEquals(0, op.getSignature().length);
childInfo = connection.getMBeanInfo(child2ObjectName);
Assert.assertEquals(1, childInfo.getAttributes().length);
Assert.assertEquals(Integer.class.getName(), childInfo.getAttributes()[0].getType());
Assert.assertEquals(1, childInfo.getOperations().length);
op = findOperation(childInfo.getOperations(), REMOVE);
Assert.assertEquals("remove", op.getDescription());
Assert.assertEquals(0, op.getSignature().length);
Assert.assertEquals(123, connection.getAttribute(child1ObjectName, "attr"));
Assert.assertEquals(456, connection.getAttribute(child2ObjectName, "attr"));
connection.invoke(child1ObjectName, REMOVE, new Object[]{}, new String[]{});
names = connection.queryNames(createObjectName(LEGACY_DOMAIN + ":subsystem=test,*"), null);
Assert.assertEquals(2, names.size());
Assert.assertTrue(names.contains(testObjectName));
Assert.assertTrue(names.contains(child2ObjectName));
connection.invoke(child2ObjectName, REMOVE, new Object[]{}, new String[]{});
names = connection.queryNames(createObjectName(LEGACY_DOMAIN + ":subsystem=test,*"), null);
Assert.assertEquals(1, names.size());
Assert.assertTrue(names.contains(testObjectName));
}
public Map<String, Object> getOSJMXStats(JMXDeamons jmxDaemon, String host, String port, boolean jmxPluginEnabled) throws IOException,
AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, IntrospectionException {
if (jmxPluginEnabled) {
JumbuneJMXClient client = new JumbuneJMXClient();
try{
return client.getOSStats(host, jmxDaemon.toString()+Constants.OS_IDENTIFIER);
}catch(ClassNotFoundException e){
LOGGER.error("error fetching jmx stats through plugin - " + e.getMessage());
}
}
List<String> jmxAttributeList = new ArrayList<String>();
JMXConnector connector = null;
MBeanServerConnection connection = null;
Map<String, Object> serviceStats = null;
JMXServiceURL url = new JMXServiceURL(JMX_URL_PREFIX + host + ":" + port + JMX_URL_POSTFIX);
String serviceUrl = ProfilerConstants.OS_URL;
connector = JMXConnectorInstance.getJMXConnectorInstance(url);
connection = connector.getMBeanServerConnection();
Set<ObjectName> names = connection.queryNames(null, null);
String objectName;
MBeanInfo info;
MBeanAttributeInfo[] mbi;
for (ObjectName objName : names) {
objectName = objName.toString();
if(objectName.indexOf(serviceUrl) > -1) {
if (serviceStats == null) {
serviceStats = new HashMap<String, Object>();
}
info = connection.getMBeanInfo(objName);
mbi = info.getAttributes();
String name = null;
for (int i = 0; i < info.getAttributes().length; i++) {
name = mbi[i].getName();
jmxAttributeList.add(name);
Object attributeValue = connection.getAttribute(objName, name);
if (attributeValue != null) {
serviceStats.put(name, String.valueOf(attributeValue));
}
if("".equals(attributeValue) || "[]".equals(attributeValue)){
serviceStats.put(getKeyName(objName, name), "-");
}
}
}
}
return serviceStats;
}