00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.benchmarks.timit.util.observing.defaultobserver;
00032
00033 import java.util.Vector;
00034
00035 import org.objectweb.proactive.benchmarks.timit.util.observing.EventData;
00036
00041 public class DefaultEventData implements EventData {
00042
00046 private static final long serialVersionUID = -8362004552051089021L;
00047
00048 public static final int MIN = 0;
00049
00050 public static final int MAX = 1;
00051
00052 public static final int AVERAGE = 2;
00053
00054 public static final int SUM = 3;
00055
00056 private String name;
00057
00058 private int collapseOperation;
00059
00060 private int notifyOperation;
00061
00062 private double value, result;
00063
00064 private int nbNotify;
00065
00066 private Vector<Object> collapsedValues;
00067
00069 public DefaultEventData(String name, int collapseOperation,
00070 int notifyOperation) {
00071
00072 this.name = name;
00073 this.collapseOperation = collapseOperation;
00074 this.notifyOperation = notifyOperation;
00075 this.nbNotify = 0;
00076 this.result = 0;
00077
00078 switch (this.notifyOperation) {
00079 case DefaultEventData.MIN:
00080 this.value = Double.MAX_VALUE;
00081 break;
00082 case DefaultEventData.MAX:
00083 this.value = Double.MIN_VALUE;
00084 break;
00085 default:
00086 this.value = 0;
00087 }
00088 }
00089
00090 public void performNotifyOperation(double value) {
00091 switch (this.notifyOperation) {
00092 case DefaultEventData.MIN:
00093 if (value < this.value) {
00094 this.value = value;
00095 }
00096 break;
00097 case DefaultEventData.MAX:
00098 if (value > this.value) {
00099 this.value = value;
00100 }
00101 break;
00102 case DefaultEventData.AVERAGE:
00103 this.nbNotify++;
00104 this.value += value;
00105 break;
00106 default:
00107 this.value += value;
00108 }
00109 }
00110
00111 public void setData(Object object) {
00112 }
00113
00114 public Object getData() {
00115 if (this.notifyOperation == DefaultEventData.AVERAGE) {
00116 this.value /= this.nbNotify;
00117 }
00118 return this.value;
00119 }
00120
00121 public String getName() {
00122 return this.name;
00123 }
00124
00128 public Object collapseWith(EventData anotherData, int anotherRank) {
00129 if (this.collapsedValues == null) {
00130 this.collapsedValues = new Vector<Object>();
00131
00132 if (this.notifyOperation == DefaultEventData.AVERAGE) {
00133 this.value /= this.nbNotify;
00134 }
00135 this.collapsedValues.add(this.value);
00136 }
00137 if (anotherData.equals(this)) {
00138 this.result = this.value;
00139 return this.collapsedValues;
00140 }
00141
00142 this.collapsedValues.add(anotherData.getData());
00143 switch (this.collapseOperation) {
00144 case DefaultEventData.MIN:
00145 this.result = Double.MAX_VALUE;
00146 for (int i = 0; i < this.collapsedValues.size(); i++) {
00147 this.result = ((Double) this.collapsedValues.get(i) < this.result ? (Double) this.collapsedValues
00148 .get(i)
00149 : this.result);
00150 }
00151 break;
00152 case DefaultEventData.MAX:
00153 this.result = Double.MIN_VALUE;
00154 for (int i = 0; i < this.collapsedValues.size(); i++) {
00155 this.result = ((Double) this.collapsedValues.get(i) > this.result ? (Double) this.collapsedValues
00156 .get(i)
00157 : this.result);
00158 }
00159 break;
00160 case DefaultEventData.AVERAGE:
00161 this.result = 0;
00162 for (int i = 0; i < this.collapsedValues.size(); i++) {
00163 this.result += (Double) this.collapsedValues.get(i);
00164 }
00165 this.result /= this.collapsedValues.size();
00166 break;
00167 default:
00168 this.result = 0;
00169 for (int i = 0; i < this.collapsedValues.size(); i++) {
00170 this.result += (Double) this.collapsedValues.get(i);
00171 }
00172 break;
00173 }
00174 return this.collapsedValues;
00175 }
00176
00177 public Object getFinalized() {
00178 return this.result;
00179 }
00180
00181 public String toString() {
00182 return "" + this.result;
00183 }
00184 }