KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > datacollector > lib > AbstractProbeDataCollector


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2004 France Telecom R&D
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * CLIF $Name: $
20 *
21 * Contact: clif@objectweb.org
22 */

23
24 package org.objectweb.clif.datacollector.lib;
25
26 import org.objectweb.clif.storage.api.ProbeEvent;
27 import java.io.Serializable JavaDoc;
28
29 /**
30  * Data collector for probes generating ProbeEvent-derived events.
31  *
32  * @author Bruno Dillenseger
33  */

34 abstract public class AbstractProbeDataCollector extends AbstractDataCollector
35 {
36     protected long[] stats;
37     protected long samples = 0;
38
39
40     /**
41      * resets all statistics but the cumulative ones
42      */

43     private void resetStats()
44     {
45         samples = 0;
46         for (int i=0 ; i<stats.length ; stats[i++] = 0);
47     }
48
49
50     /**
51      * new test initialization => call super class' init() method and resets all statistics,
52      * including the cumulative ones
53      */

54     public void init(Serializable JavaDoc testId, String JavaDoc probeId)
55     {
56         super.init(testId, probeId);
57         resetStats();
58     }
59
60
61     /**
62      * new measure available => call super class' add() method and compute statistics
63      */

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     //////////////////////////////////
79
// interface DataCollectorAdmin //
80
//////////////////////////////////
81

82
83     /**
84      * Get statistics computed since previous call (or initialization for 1st call)
85      */

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