diff -urBN jmxquery.a/src/jmxquery/src/org/munin/JMXQuery.java jmxquery.b/src/jmxquery/src/org/munin/JMXQuery.java --- jmxquery.a/src/jmxquery/src/org/munin/JMXQuery.java 2007-05-14 01:07:44.000000000 -0700 +++ jmxquery.b/src/jmxquery/src/org/munin/JMXQuery.java 2010-01-15 15:40:00.000000000 -0800 @@ -61,7 +61,7 @@ this.password = password; } - private void connect() throws IOException + public void connect() throws IOException { Map environment = null; if (username != null && password != null) @@ -78,7 +78,18 @@ connection = connector.getMBeanServerConnection(); } - private void list() throws IOException, InstanceNotFoundException, IntrospectionException, ReflectionException + public void ping() throws IOException + { + try { + MBeanServerConnection testConnection = connector.getMBeanServerConnection(); + if (testConnection == null) + this.connect(); + } catch (IOException e) { + this.connect(); + } + } + + public void list() throws IOException, InstanceNotFoundException, IntrospectionException, ReflectionException { if (config == null) { @@ -90,7 +101,7 @@ } } - private void listConfig() + public void listConfig() { for (FieldProperties field : config.getFields()) { @@ -107,7 +118,22 @@ } } - private void output(String name, Object attr, String key) + public String output(String name, String JmxObjectName, String JmxAttributeName, String Key) + { + try + { + Object value = connection.getAttribute(new ObjectName(JmxObjectName), JmxAttributeName); + return output(name, value, Key); + } + catch (Exception e) + { + System.err.println("Fail to output " + name); + e.printStackTrace(); + } + return null; + } + + public String output(String name, Object attr, String key) { if (attr instanceof CompositeDataSupport) { @@ -116,15 +142,17 @@ { throw new IllegalArgumentException("Key is null for composed data " + name); } - System.out.println(name + ".value " + format(cds.get(key))); + //System.out.println(name + ".value " + format(cds.get(key))); + return format(cds.get(key)); } else { - System.out.println(name + ".value " + format(attr)); + //System.out.println(name + ".value " + format(attr)); + return format(attr); } } - private void output(String name, Object attr) + public void output(String name, Object attr) { if (attr instanceof CompositeDataSupport) { @@ -142,7 +170,7 @@ } @SuppressWarnings("unchecked") - private void listAll() throws IOException, InstanceNotFoundException, IntrospectionException, ReflectionException + public void listAll() throws IOException, InstanceNotFoundException, IntrospectionException, ReflectionException { Set mbeans = connection.queryNames(null, null); for (ObjectName name : mbeans) @@ -156,7 +184,7 @@ } try { - List attributes = connection.getAttributes(name, attrNames); + List attributes = connection.getAttributes(name, attrNames).asList(); for (Attribute attribute : attributes) { output(name.getCanonicalName() + "%" + attribute.getName(), attribute.getValue()); @@ -170,7 +198,7 @@ } } - private String format(Object value) + public String format(Object value) { if (value == null) { @@ -194,7 +222,7 @@ return value.toString(); } - private void disconnect() throws IOException + public void disconnect() throws IOException { connector.close(); } @@ -293,7 +321,7 @@ } - private void setConfig(Configuration configuration) + public void setConfig(Configuration configuration) { this.config = configuration; }