diff --git a/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/LimitableFieldsModel.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/LimitableFieldsModel.java index b4bd1d5d..12f17389 100644 --- a/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/LimitableFieldsModel.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/LimitableFieldsModel.java @@ -9,8 +9,8 @@ import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "limitableFields") public class LimitableFieldsModel { + private List fieldsParent; private List fields; - @XmlElementWrapper(name = "fieldList") @XmlElement(name = "field") public List getFields() { @@ -23,10 +23,31 @@ public class LimitableFieldsModel { public LimitableFieldsModel() { this.fields = new ArrayList(); - this.fields.add("memoryUsedPercent"); - this.fields.add("processorTimePercent"); - this.fields.add("userTimePercent"); - this.fields.add("privilegedTimePercent"); + this.fieldsParent = new ArrayList(); + this.fields.add("MemoryUsedPercent"); + this.fieldsParent.add("org.bench4q.monitor.model.MemoryModel"); + this.fields.add("ProcessorTimePercent"); + this.fieldsParent.add("org.bench4q.monitor.model.ProcessorModel"); + this.fields.add("UserTimePercent"); + this.fieldsParent.add("org.bench4q.monitor.model.ProcessorModel"); + this.fields.add("PrivilegedTimePercent"); + this.fieldsParent.add("org.bench4q.monitor.model.ProcessorModel"); + } + + public String validname(String name){ + for (int i = 0; i < this.fields.size(); i++){ + if (name.toUpperCase().equals(fields.get(i).toUpperCase())) + return fieldsParent.get(i); + } + return ""; + } + + public List getFieldsParent() { + return fieldsParent; + } + + public void setFieldsParent(List fieldsParent) { + this.fieldsParent = fieldsParent; } diff --git a/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/MonitorMain.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/MonitorMain.java index b6a26662..e99c83d5 100644 --- a/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/MonitorMain.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/MonitorMain.java @@ -1,11 +1,13 @@ package org.bench4q.monitor.model; +import java.lang.reflect.Method; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.TimeZone; import java.util.concurrent.ExecutionException; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @@ -97,21 +99,18 @@ public class MonitorMain extends SampleModel { for (int i = 0; i < list.size(); i++){ String name = list.get(i).getName(); double limit = list.get(i).getLimit(); - if (name.equals("memoryUsedPercent")){ - if (limit <= this.memoryModel.getMemoryUsedPercent()) - limitResult = true; - } - if (name.equals("processorTimePercent")){ - if (limit <= this.processorModel.getProcessorTimePercent()) - limitResult = true; - } - if (name.equals("userTimePercent")){ - if (limit <= this.processorModel.getUserTimePercent()) - limitResult = true; - } - if (name.equals("privilegedTimePercent")){ - if (limit <= this.processorModel.getPrivilegedTimePercent()) - limitResult = true; + LimitableFieldsModel limitableFieldsModel = new LimitableFieldsModel(); + String parent = limitableFieldsModel.validname(name); + if (parent !=""){ + try { + Class c = Class.forName(parent); + Object obj=c.newInstance(); + Method mget=c.getMethod("get"+name); + double currentvalue=(Double) mget.invoke(obj); + if (currentvalue >= limit) limitResult = true; + } catch (Exception e) { + e.printStackTrace(); + } } } return limitResult;