support arguments

This commit is contained in:
Doug MacEachern 2008-10-04 00:29:44 +00:00
parent 6f7b2751f2
commit ceec932585
1 changed files with 33 additions and 5 deletions

View File

@ -35,6 +35,8 @@ public class ReflectedMBean extends AbstractMBean {
private Method method; private Method method;
private Map methods; private Map methods;
private String type; private String type;
private Object[] args;
private String name;
protected String getType() { protected String getType() {
return this.type; return this.type;
@ -52,12 +54,28 @@ public class ReflectedMBean extends AbstractMBean {
protected ReflectedMBean(Sigar sigar, String type) { protected ReflectedMBean(Sigar sigar, String type) {
super(sigar, CACHELESS); super(sigar, CACHELESS);
this.type = type; 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.name += ",Name=" + encode(arg);
}
private String encode(String arg) {
return arg.replaceAll(":", "%3A");
} }
public String getObjectName() { public String getObjectName() {
return return this.name;
SigarInvokerJMX.DOMAIN_NAME + ":" +
MBEAN_ATTR_TYPE + "=" + getType();
} }
protected Method getMethod() throws Exception { protected Method getMethod() throws Exception {
@ -72,7 +90,16 @@ public class ReflectedMBean extends AbstractMBean {
} }
protected Class[] getMethodParamTypes() { protected Class[] getMethodParamTypes() {
return new Class[0]; int len = this.args.length;
Class[] types = new Class[len];
for (int i=0; i<len; i++) {
types[i] = this.args[i].getClass();
}
return types;
}
protected Object[] getMethodParams() {
return this.args;
} }
private Object getReflectedAttribute(String name) private Object getReflectedAttribute(String name)
@ -81,7 +108,7 @@ public class ReflectedMBean extends AbstractMBean {
Method method = getMethod(); Method method = getMethod();
Object obj = Object obj =
method.invoke(this.sigarImpl, method.invoke(this.sigarImpl,
getMethodParamTypes()); getMethodParams());
Method attr = Method attr =
obj.getClass().getMethod("get" + name, new Class[0]); obj.getClass().getMethod("get" + name, new Class[0]);
return attr.invoke(obj, new Object[0]); return attr.invoke(obj, new Object[0]);
@ -93,6 +120,7 @@ public class ReflectedMBean extends AbstractMBean {
try { try {
return getReflectedAttribute(name); return getReflectedAttribute(name);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
throw new ReflectionException(e); throw new ReflectionException(e);
} }
} }