org/objectweb/proactive/benchmarks/timit/util/observing/defaultobserver/DefaultEventData.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
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             // Add current value
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 }

Generated on Mon Jan 22 15:16:04 2007 for ProActive by  doxygen 1.5.1