getObjectName method for SigarProcess

This commit is contained in:
Doug MacEachern 2008-10-18 23:31:03 +00:00
parent 27a8d74436
commit 2bc3a6ce2a
2 changed files with 20 additions and 2 deletions

View File

@ -46,8 +46,8 @@ import org.hyperic.sigar.SigarProxyCache;
*/
public abstract class AbstractMBean implements DynamicMBean, MBeanRegistration {
protected static final String MBEAN_DOMAIN = SigarInvokerJMX.DOMAIN_NAME;
protected static final String MBEAN_ATTR_TYPE = SigarInvokerJMX.PROP_TYPE;
public static final String MBEAN_DOMAIN = SigarInvokerJMX.DOMAIN_NAME;
public static final String MBEAN_ATTR_TYPE = SigarInvokerJMX.PROP_TYPE;
protected static final short CACHED_30SEC = 0;

View File

@ -21,6 +21,7 @@ package org.hyperic.sigar.jmx;
import org.hyperic.sigar.ProcCpu;
import org.hyperic.sigar.ProcFd;
import org.hyperic.sigar.ProcMem;
import org.hyperic.sigar.ProcUtil;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.SigarProxy;
@ -82,6 +83,23 @@ public class SigarProcess implements SigarProcessMBean {
}
}
public String getObjectName() throws SigarException {
long pid = getPid();
String name = this.sigar.getProcState(pid).getName();
String cls = "unknown";
if (name.startsWith("java")) {
try {
cls = ProcUtil.getJavaMainClass(this.sigar, pid);
} catch (SigarException e) {}
} //else XXX
return
AbstractMBean.MBEAN_DOMAIN + ":" +
AbstractMBean.MBEAN_ATTR_TYPE + "=" + "Process" + "," +
"Name" + "=" + name + "," +
"Class" + "=" + cls + "," +
"Pid" + "=" + pid;
}
public long getPid() {
if (this.pid < 0) {
return this.sigar.getPid();