From 7ff83f9ba9002f3f8414a56d4095f41c864da3d0 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Thu, 9 Oct 2008 05:55:17 +0000 Subject: [PATCH] use SigarInvokerJMX --- .../org/hyperic/sigar/jmx/ReflectedMBean.java | 71 +++++-------------- 1 file changed, 19 insertions(+), 52 deletions(-) diff --git a/bindings/java/src/org/hyperic/sigar/jmx/ReflectedMBean.java b/bindings/java/src/org/hyperic/sigar/jmx/ReflectedMBean.java index 084dbc56..50c907fd 100644 --- a/bindings/java/src/org/hyperic/sigar/jmx/ReflectedMBean.java +++ b/bindings/java/src/org/hyperic/sigar/jmx/ReflectedMBean.java @@ -33,12 +33,11 @@ import org.hyperic.sigar.Sigar; public class ReflectedMBean extends AbstractMBean { - private Method method; private Map methods; private Map attrs = new HashMap(); private String type; - private Object[] args; private String name; + private SigarInvokerJMX invoker; protected String getType() { return this.type; @@ -78,9 +77,13 @@ public class ReflectedMBean extends AbstractMBean { } } - protected Class getMBeanClass() { + private String getMBeanClassName() { + return "org.hyperic.sigar." + getType(); + } + + private Class getMBeanClass() { try { - return getMethod().getReturnType(); + return Class.forName(getMBeanClassName()); } catch (Exception e) { e.printStackTrace(); return null; @@ -88,21 +91,15 @@ public class ReflectedMBean extends AbstractMBean { } protected ReflectedMBean(Sigar sigar, String type) { - super(sigar, CACHELESS); + super(sigar, CACHED_5SEC); this.type = type; - this.args = new Object[0]; this.name = SigarInvokerJMX.DOMAIN_NAME + ":" + MBEAN_ATTR_TYPE + "=" + getType(); } - protected ReflectedMBean(Sigar sigar, String type, Object[] args) { - this(sigar, type); - this.args = args; - } - protected ReflectedMBean(Sigar sigar, String type, String arg) { - this(sigar, type, new Object[] { arg }); + this(sigar, type); this.name += ",Name=" + encode(arg); } @@ -114,42 +111,15 @@ public class ReflectedMBean extends AbstractMBean { return this.name; } - protected Method getMethod() throws Exception { - if (this.method == null) { - String getName = "get" + getType(); - Class[] params = getMethodParamTypes(); - this.method = - this.sigarImpl.getClass().getDeclaredMethod(getName, - params); + protected SigarInvokerJMX getInvoker() { + if (this.invoker == null) { + this.invoker = + SigarInvokerJMX.getInstance(this.sigar, getObjectName()); + this.invoker.setType(getType()); } - return this.method; + return this.invoker; } - - protected Class[] getMethodParamTypes() { - int len = this.args.length; - Class[] types = new Class[len]; - for (int i=0; i