test SigarProcessMBean
This commit is contained in:
parent
6b46d63201
commit
06945a8e31
|
@ -28,6 +28,7 @@ import javax.management.MBeanServerFactory;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
|
||||||
import org.hyperic.sigar.SigarException;
|
import org.hyperic.sigar.SigarException;
|
||||||
|
import org.hyperic.sigar.jmx.SigarProcess;
|
||||||
import org.hyperic.sigar.jmx.SigarRegistry;
|
import org.hyperic.sigar.jmx.SigarRegistry;
|
||||||
|
|
||||||
public class Mx extends SigarCommandBase {
|
public class Mx extends SigarCommandBase {
|
||||||
|
@ -70,6 +71,8 @@ public class Mx extends SigarCommandBase {
|
||||||
SigarRegistry registry = new SigarRegistry();
|
SigarRegistry registry = new SigarRegistry();
|
||||||
try {
|
try {
|
||||||
server.registerMBean(registry, null);
|
server.registerMBean(registry, null);
|
||||||
|
SigarProcess proc = new SigarProcess();
|
||||||
|
server.registerMBean(proc, new ObjectName(proc.getObjectName()));
|
||||||
isRegistered = true;
|
isRegistered = true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new SigarException(e.getMessage());
|
throw new SigarException(e.getMessage());
|
||||||
|
|
|
@ -28,6 +28,7 @@ import javax.management.ObjectName;
|
||||||
|
|
||||||
import org.hyperic.sigar.SigarException;
|
import org.hyperic.sigar.SigarException;
|
||||||
import org.hyperic.sigar.cmd.Mx;
|
import org.hyperic.sigar.cmd.Mx;
|
||||||
|
import org.hyperic.sigar.jmx.SigarProcess;
|
||||||
import org.hyperic.sigar.jmx.SigarRegistry;
|
import org.hyperic.sigar.jmx.SigarRegistry;
|
||||||
|
|
||||||
public class TestMx extends SigarTestCase {
|
public class TestMx extends SigarTestCase {
|
||||||
|
@ -45,6 +46,19 @@ public class TestMx extends SigarTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void _testProcess(MBeanServer server) throws Exception {
|
||||||
|
long[] pids = getSigar().getProcList();
|
||||||
|
for (int i=0; i<pids.length; i++) {
|
||||||
|
SigarProcess proc = new SigarProcess();
|
||||||
|
proc.setPid(pids[i]);
|
||||||
|
ObjectName name = new ObjectName(proc.getObjectName());
|
||||||
|
if (server.isRegistered(name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
server.registerMBean(proc, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void _testRegister() throws Exception {
|
private void _testRegister() throws Exception {
|
||||||
MBeanServer server;
|
MBeanServer server;
|
||||||
try {
|
try {
|
||||||
|
@ -54,14 +68,18 @@ public class TestMx extends SigarTestCase {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
server.registerMBean(new SigarRegistry(), null);
|
SigarRegistry rgy = new SigarRegistry();
|
||||||
|
ObjectName name = new ObjectName(rgy.getObjectName());
|
||||||
|
if (!server.isRegistered(name)) {
|
||||||
|
server.registerMBean(new SigarRegistry(), name);
|
||||||
|
}
|
||||||
Set beans =
|
Set beans =
|
||||||
server.queryNames(new ObjectName("sigar:*"), null);
|
server.queryNames(new ObjectName("sigar:*"), null);
|
||||||
|
|
||||||
assertGtZeroTrace("beans.size", beans.size());
|
assertGtZeroTrace("beans.size", beans.size());
|
||||||
|
|
||||||
for (Iterator it=beans.iterator(); it.hasNext();) {
|
for (Iterator it=beans.iterator(); it.hasNext();) {
|
||||||
ObjectName name = (ObjectName)it.next();
|
name = (ObjectName)it.next();
|
||||||
MBeanInfo info = server.getMBeanInfo(name);
|
MBeanInfo info = server.getMBeanInfo(name);
|
||||||
MBeanAttributeInfo[] attrs = info.getAttributes();
|
MBeanAttributeInfo[] attrs = info.getAttributes();
|
||||||
for (int k = 0; k < attrs.length; k++) {
|
for (int k = 0; k < attrs.length; k++) {
|
||||||
|
@ -70,5 +88,7 @@ public class TestMx extends SigarTestCase {
|
||||||
traceln(name + ":" + attr + "=" + o);
|
traceln(name + ":" + attr + "=" + o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_testProcess(server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue