added skeleton ant.jar to unify classpath

added MBean impl for Swap
fixed several MBeanConstructorInfo specs (were reporting SigarCpu as class)
fixed possible (de)registration problem in registry bean (was not handling ObjectInstances correctly)
This commit is contained in:
Bjoern Martin 2007-04-29 18:59:13 +00:00
parent 36434a0a23
commit 3471b84099
7 changed files with 251 additions and 15 deletions

View File

@ -6,8 +6,8 @@
<classpathentry kind="lib" path="lib/junit.jar"/>
<classpathentry kind="lib" path="hyperic_jni/lib/cpptasks.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/Developer/Java/Ant/lib/ant.jar"/>
<classpathentry kind="lib" path="lib/log4j.jar"/>
<classpathentry kind="lib" path="lib/mx4j-jmx.jar"/>
<classpathentry kind="lib" path="lib/ant.jar"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>

BIN
bindings/java/lib/ant.jar Normal file

Binary file not shown.

View File

@ -89,14 +89,14 @@ public class SigarCpuInfo extends AbstractMBean {
"sigar", Sigar.class.getName(),
"The Sigar instance to use to fetch data from");
MBEAN_CONSTR_CPUINDEX = new MBeanConstructorInfo(
SigarCpu.class.getName(),
SigarCpuInfo.class.getName(),
"Creates a new instance for the CPU index specified, " +
"using a new Sigar instance to fetch the data. " +
"Fails if the CPU index is out of range.",
new MBeanParameterInfo[]{
MBEAN_PARAM_CPUINDEX});
MBEAN_CONSTR_CPUINDEX_SIGAR = new MBeanConstructorInfo(
SigarCpu.class.getName(),
SigarCpuInfo.class.getName(),
"Creates a new instance for the CPU index specified, " +
"using the Sigar instance specified to fetch the data. " +
"Fails if the CPU index is out of range.",
@ -104,7 +104,7 @@ public class SigarCpuInfo extends AbstractMBean {
MBEAN_PARAM_SIGAR,
MBEAN_PARAM_CPUINDEX});
MBEAN_INFO = new MBeanInfo(
SigarCpu.class.getName(),
SigarCpuInfo.class.getName(),
"Sigar CPU Info MBean, provides overall information for a " +
"single CPU. This information only changes if, for example, " +
"a CPU is reducing its clock frequency or shutting down " +

View File

@ -101,14 +101,14 @@ public class SigarCpuPerc extends AbstractMBean {
"sigar", Sigar.class.getName(),
"The Sigar instance to use to fetch data from");
MBEAN_CONSTR_CPUINDEX = new MBeanConstructorInfo(
SigarCpu.class.getName(),
SigarCpuPerc.class.getName(),
"Creates a new instance for the CPU index specified, " +
"using a new Sigar instance to fetch the data. " +
"Fails if the CPU index is out of range.",
new MBeanParameterInfo[]{
MBEAN_PARAM_CPUINDEX});
MBEAN_CONSTR_CPUINDEX_SIGAR = new MBeanConstructorInfo(
SigarCpu.class.getName(),
SigarCpuPerc.class.getName(),
"Creates a new instance for the CPU index specified, " +
"using the Sigar instance specified to fetch the data. " +
"Fails if the CPU index is out of range.",
@ -116,7 +116,7 @@ public class SigarCpuPerc extends AbstractMBean {
MBEAN_PARAM_SIGAR,
MBEAN_PARAM_CPUINDEX});
MBEAN_INFO = new MBeanInfo(
SigarCpu.class.getName(),
SigarCpuPerc.class.getName(),
"Sigar CPU MBean. Provides percentage data for a single " +
"CPU, averaged over the timeframe between the last and " +
"the current measurement point. Two measurement points " +

View File

@ -88,13 +88,13 @@ public class SigarMem extends AbstractMBean {
"sigar", Sigar.class.getName(),
"The Sigar instance to use to fetch data from");
MBEAN_CONSTR_SIGAR = new MBeanConstructorInfo(
SigarCpu.class.getName(),
SigarMem.class.getName(),
"Creates a new instance, using the Sigar instance " +
"specified to fetch the data.",
new MBeanParameterInfo[]{
MBEAN_PARAM_SIGAR});
MBEAN_INFO = new MBeanInfo(
SigarCpu.class.getName(),
SigarMem.class.getName(),
"Sigar Memory MBean, provides raw data for the physical " +
"memory installed on the system. Uses an internal cache " +
"that invalidates within 500ms, allowing for bulk request " +

View File

@ -174,30 +174,41 @@ public class SigarRegistry extends AbstractMBean {
try {
final int cpuCount = sigar.getCpuInfoList().length;
for (int i = 0; i < cpuCount; i++) {
// add CPU bean
SigarCpu nextCpu = new SigarCpu(sigarImpl, i);
SigarCpuPerc nextCpuPerc = new SigarCpuPerc(sigarImpl, i);
SigarCpuInfo nextCpuInfo = new SigarCpuInfo(sigarImpl, i);
try {
if (!mbeanServer.isRegistered(new ObjectName(nextCpu.getObjectName())))
nextRegistered = mbeanServer.registerMBean(nextCpu, null);
} catch (Exception e) { // ignore
}
// add MBean to set of managed beans
managedBeans.add(nextRegistered.getObjectName());
if (nextRegistered != null)
managedBeans.add(nextRegistered.getObjectName());
nextRegistered = null;
// add CPU percentage bean
SigarCpuPerc nextCpuPerc = new SigarCpuPerc(sigarImpl, i);
try {
if (!mbeanServer.isRegistered(new ObjectName(nextCpuPerc.getObjectName())))
nextRegistered = mbeanServer.registerMBean(nextCpuPerc, null);
} catch (Exception e) { // ignore
}
// add MBean to set of managed beans
managedBeans.add(nextRegistered.getObjectName());
if (nextRegistered != null)
managedBeans.add(nextRegistered.getObjectName());
nextRegistered = null;
// add CPU info bean
SigarCpuInfo nextCpuInfo = new SigarCpuInfo(sigarImpl, i);
try {
if (!mbeanServer.isRegistered(new ObjectName(nextCpuInfo.getObjectName())))
nextRegistered = mbeanServer.registerMBean(nextCpuInfo, null);
} catch (Exception e) { // ignore
}
// add MBean to set of managed beans
managedBeans.add(nextRegistered.getObjectName());
if (nextRegistered != null)
managedBeans.add(nextRegistered.getObjectName());
nextRegistered = null;
}
} catch (SigarException e) {
@ -212,6 +223,7 @@ public class SigarRegistry extends AbstractMBean {
ObjectInstance nextRegistered = null;
// add physical memory bean
SigarMem mem = new SigarMem(sigarImpl);
try {
@ -221,7 +233,23 @@ public class SigarRegistry extends AbstractMBean {
}
// add MBean to set of managed beans
managedBeans.add(nextRegistered.getObjectName());
if (nextRegistered != null)
managedBeans.add(nextRegistered.getObjectName());
nextRegistered = null;
// add swap memory bean
SigarSwap swap = new SigarSwap(sigarImpl);
try {
if (!mbeanServer.isRegistered(new ObjectName(swap.getObjectName())))
nextRegistered = mbeanServer.registerMBean(swap, null);
} catch (Exception e) { // ignore
nextRegistered = null;
}
// add MBean to set of managed beans
if (nextRegistered != null)
managedBeans.add(nextRegistered.getObjectName());
nextRegistered = null;
}
/**

View File

@ -0,0 +1,208 @@
/*
* Copyright (C) [2004, 2005, 2006, 2007], Hyperic, Inc.
* This file is part of SIGAR.
*
* SIGAR is free software; you can redistribute it and/or modify
* it under the terms version 2 of the GNU General Public License as
* published by the Free Software Foundation. This program is distributed
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*/
package org.hyperic.sigar.jmx;
import javax.management.Attribute;
import javax.management.AttributeNotFoundException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanParameterInfo;
import javax.management.ReflectionException;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
/**
* Sigar JMX MBean implementation for the <code>Swap</code> information
* package. Provides an OpenMBean conform implementation.
*
* @author Bjoern Martin
* @since 1.4 (2007-04)
*/
public class SigarSwap extends AbstractMBean {
private static final String MBEAN_TYPE = "Swap";
private static final MBeanInfo MBEAN_INFO;
private static final MBeanAttributeInfo MBEAN_ATTR_FREE;
private static final MBeanAttributeInfo MBEAN_ATTR_TOTAL;
private static final MBeanAttributeInfo MBEAN_ATTR_USED;
private static final MBeanConstructorInfo MBEAN_CONSTR_SIGAR;
private static MBeanParameterInfo MBEAN_PARAM_SIGAR;
static {
MBEAN_ATTR_FREE = new MBeanAttributeInfo(
"Free", "long",
"The amount of free swap memory, in [bytes]",
true, false, false);
MBEAN_ATTR_TOTAL = new MBeanAttributeInfo(
"Total", "long",
"The total amount of swap memory, in [bytes]",
true, false, false);
MBEAN_ATTR_USED = new MBeanAttributeInfo(
"Used", "long",
"The amount of swap memory in use, in [bytes]",
true, false, false);
MBEAN_PARAM_SIGAR = new MBeanParameterInfo(
"sigar", Sigar.class.getName(),
"The Sigar instance to use to fetch data from");
MBEAN_CONSTR_SIGAR = new MBeanConstructorInfo(
SigarSwap.class.getName(),
"Creates a new instance, using the Sigar instance " +
"specified to fetch the data.",
new MBeanParameterInfo[]{
MBEAN_PARAM_SIGAR});
MBEAN_INFO = new MBeanInfo(
SigarSwap.class.getName(),
"Sigar Swap MBean, provides raw data for the swap memory " +
"configured on the system. Uses an internal cache that " +
"invalidates within 5 seconds.",
new MBeanAttributeInfo[]{
MBEAN_ATTR_FREE,
MBEAN_ATTR_TOTAL,
MBEAN_ATTR_USED},
new MBeanConstructorInfo[]{
MBEAN_CONSTR_SIGAR},
null, null);
}
/**
* Object name this instance will give itself when being registered to an
* MBeanServer.
*/
private final String objectName;
/**
* Creates a new instance, using the Sigar instance specified to fetch the
* data.
*
* @param sigar
* The Sigar instance to use to fetch data from
*
* @throws IllegalArgumentException
* If an unexpected Sigar error occurs
*/
public SigarSwap(Sigar sigar) throws IllegalArgumentException {
super(sigar, CACHED_5SEC);
this.objectName = SigarInvokerJMX.DOMAIN_NAME + ":" + MBEAN_ATTR_TYPE
+ "=Swap";
}
/**
* Object name this instance will give itself when being registered to an
* MBeanServer.
*/
public String getObjectName() {
return this.objectName;
}
/**
* @return The amount of free swap memory, in [bytes]
*/
public long getFree() {
try {
return sigar.getSwap().getFree();
} catch (SigarException e) {
throw unexpectedError(MBEAN_TYPE, e);
}
}
/**
* @return The total amount of swap memory, in [bytes]
*/
public long getTotal() {
try {
return sigar.getSwap().getTotal();
} catch (SigarException e) {
throw unexpectedError(MBEAN_TYPE, e);
}
}
/**
* @return The amount of swap memory in use, in [bytes]
*/
public long getUsed() {
try {
return sigar.getSwap().getUsed();
} catch (SigarException e) {
throw unexpectedError(MBEAN_TYPE, e);
}
}
// -------
// Implementation of the DynamicMBean interface
// -------
/*
* (non-Javadoc)
*
* @see javax.management.DynamicMBean#getAttribute(java.lang.String)
*/
public Object getAttribute(String attr) throws AttributeNotFoundException,
MBeanException, ReflectionException {
if (MBEAN_ATTR_FREE.getName().equals(attr)) {
return new Long(getFree());
} else if (MBEAN_ATTR_TOTAL.getName().equals(attr)) {
return new Long(getTotal());
} else if (MBEAN_ATTR_USED.getName().equals(attr)) {
return new Long(getUsed());
} else {
throw new AttributeNotFoundException(attr);
}
}
/*
* (non-Javadoc)
* @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute)
*/
public void setAttribute(Attribute attr) throws AttributeNotFoundException {
throw new AttributeNotFoundException(attr.getName());
}
/*
* (non-Javadoc)
* @see javax.management.DynamicMBean#invoke(java.lang.String,
* java.lang.Object[], java.lang.String[])
*/
public Object invoke(String actionName, Object[] params, String[] signature)
throws ReflectionException {
throw new ReflectionException(new NoSuchMethodException(actionName),
actionName);
}
/*
* (non-Javadoc)
* @see javax.management.DynamicMBean#getMBeanInfo()
*/
public MBeanInfo getMBeanInfo() {
return MBEAN_INFO;
}
}