add version attributes

This commit is contained in:
Doug MacEachern 2008-10-03 15:48:56 +00:00
parent 913f1ca5a6
commit e0b67cf3fa
1 changed files with 40 additions and 2 deletions

View File

@ -19,9 +19,13 @@
package org.hyperic.sigar.jmx;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.management.Attribute;
import javax.management.AttributeNotFoundException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
@ -33,6 +37,7 @@ import javax.management.ReflectionException;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.SigarLoader;
/**
* <p>Registry of all Sigar MBeans. Can be used as a convenient way to invoke
@ -63,6 +68,8 @@ public class SigarRegistry extends AbstractMBean {
private static final String MBEAN_TYPE = "SigarRegistry";
private static final Map VERSION_ATTRS = new LinkedHashMap();
private static final MBeanInfo MBEAN_INFO;
private static final MBeanConstructorInfo MBEAN_CONSTR_DEFAULT;
@ -87,7 +94,7 @@ public class SigarRegistry extends AbstractMBean {
+ "and destruction of Sigar MBeans. Any Sigar MBean created via "
+ "this instance will automatically be cleaned up when this "
+ "instance is deregistered from the MBean server.",
null /*new MBeanAttributeInfo[0]*/,
getAttributeInfo(),
new MBeanConstructorInfo[] { MBEAN_CONSTR_DEFAULT },
null /*new MBeanOperationInfo[0] */,
null /*new MBeanNotificationInfo[0]*/);
@ -97,6 +104,33 @@ public class SigarRegistry extends AbstractMBean {
private final ArrayList managedBeans;
private static MBeanAttributeInfo[] getAttributeInfo() {
VERSION_ATTRS.put("JarVersion", Sigar.VERSION_STRING);
VERSION_ATTRS.put("NativeVersion", Sigar.NATIVE_VERSION_STRING);
VERSION_ATTRS.put("JarBuildDate", Sigar.BUILD_DATE);
VERSION_ATTRS.put("NativeBuildDate", Sigar.NATIVE_BUILD_DATE);
VERSION_ATTRS.put("JarSourceRevision", Sigar.SCM_REVISION);
VERSION_ATTRS.put("NativeSourceRevision", Sigar.NATIVE_SCM_REVISION);
VERSION_ATTRS.put("NativeLibraryName", SigarLoader.getNativeLibraryName());
MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[VERSION_ATTRS.size()];
int i=0;
for (Iterator it=VERSION_ATTRS.entrySet().iterator();
it.hasNext();)
{
Map.Entry entry = (Map.Entry)it.next();
String name = (String)entry.getKey();
attrs[i++] =
new MBeanAttributeInfo(name,
entry.getValue().getClass().getName(),
name,
true, // isReadable
false, // isWritable
false); // isIs
}
return attrs;
}
/**
* Creates a new instance of this class. Will create the Sigar instance this
* class uses when constructing other MBeans.
@ -141,7 +175,11 @@ public class SigarRegistry extends AbstractMBean {
* @see javax.management.DynamicMBean#getAttribute(java.lang.String)
*/
public Object getAttribute(String attr) throws AttributeNotFoundException {
throw new AttributeNotFoundException(attr);
Object obj = VERSION_ATTRS.get(attr);
if (obj == null) {
throw new AttributeNotFoundException(attr);
}
return obj;
}
/* (non-Javadoc)