1 23 24 package org.objectweb.clif.datacollector.lib; 25 26 import org.objectweb.clif.storage.api.ProbeEvent; 27 import java.io.Serializable ; 28 29 34 abstract public class AbstractProbeDataCollector extends AbstractDataCollector 35 { 36 protected long[] stats; 37 protected long samples = 0; 38 39 40 43 private void resetStats() 44 { 45 samples = 0; 46 for (int i=0 ; i<stats.length ; stats[i++] = 0); 47 } 48 49 50 54 public void init(Serializable testId, String probeId) 55 { 56 super.init(testId, probeId); 57 resetStats(); 58 } 59 60 61 64 public void add(ProbeEvent measure) 65 { 66 if (measure != null) 67 { 68 super.add(measure); 69 for (int i=0 ; i<stats.length ; ++i) 70 { 71 stats[i] += measure.values[i]; 72 } 73 ++samples; 74 } 75 } 76 77 78 82 83 86 public long[] getStat() 87 { 88 if (samples > 0) 89 { 90 long[] mean = new long[stats.length]; 91 for (int i=0 ; i<stats.length ; ++i) 92 { 93 mean[i] = stats[i] / samples; 94 } 95 resetStats(); 96 return mean; 97 } 98 else 99 { 100 return null; 101 } 102 } 103 } 104 | Popular Tags |