From 27a8d744363acdba628d03be72d94b7030a41812 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sat, 18 Oct 2008 22:41:17 +0000 Subject: [PATCH] support pid other than self --- .../org/hyperic/sigar/jmx/SigarProcess.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/bindings/java/src/org/hyperic/sigar/jmx/SigarProcess.java b/bindings/java/src/org/hyperic/sigar/jmx/SigarProcess.java index 49014c3c..8c62fff2 100644 --- a/bindings/java/src/org/hyperic/sigar/jmx/SigarProcess.java +++ b/bindings/java/src/org/hyperic/sigar/jmx/SigarProcess.java @@ -35,6 +35,7 @@ public class SigarProcess implements SigarProcessMBean { private Sigar sigarImpl; private SigarProxy sigar; + private long pid = -1; public SigarProcess() { this(new Sigar()); @@ -59,8 +60,7 @@ public class SigarProcess implements SigarProcessMBean { private synchronized ProcMem getMem() { try { - long pid = this.sigar.getPid(); - return this.sigar.getProcMem(pid); + return this.sigar.getProcMem(getPid()); } catch (SigarException e) { throw unexpectedError("Mem", e); } @@ -68,8 +68,7 @@ public class SigarProcess implements SigarProcessMBean { private synchronized ProcCpu getCpu() { try { - long pid = this.sigar.getPid(); - return this.sigar.getProcCpu(pid); + return this.sigar.getProcCpu(getPid()); } catch (SigarException e) { throw unexpectedError("Cpu", e); } @@ -77,13 +76,25 @@ public class SigarProcess implements SigarProcessMBean { private synchronized ProcFd getFd() { try { - long pid = this.sigar.getPid(); - return this.sigar.getProcFd(pid); + return this.sigar.getProcFd(getPid()); } catch (SigarException e) { throw unexpectedError("Fd", e); } } - + + public long getPid() { + if (this.pid < 0) { + return this.sigar.getPid(); + } + else { + return this.pid; + } + } + + public void setPid(long pid) { + this.pid = pid; + } + public Long getMemSize() { return new Long(getMem().getSize()); }