KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > console > lib > gui > ActionTestReport


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

27 package org.objectweb.clif.console.lib.gui;
28
29 import java.awt.event.ActionEvent JavaDoc;
30 import javax.swing.AbstractAction JavaDoc;
31 import org.objectweb.clif.supervisor.api.TestControl;
32
33 /**
34  * This is the action invoked to retrieve a ActionStat.
35  * The method actionPerformed of this class is invoked by the timer each
36  * interval of time.
37  */

38 final class ActionTestReport extends AbstractAction JavaDoc {
39
40     private Object JavaDoc[] injectors;
41     private GraphTableModel tModel = null;
42     private TestControl suis;
43     private Graph graph;
44     private int time;
45     private int totalTime = 0;
46     private long lastEvent = 0;
47     private long diff;
48
49     /**
50      * @param suis
51      * @param graph
52      * @param tModel
53      */

54     public ActionTestReport(
55         TestControl suis,
56         Graph graph,
57         GraphTableModel tModel) {
58         this.suis = suis;
59         this.graph = graph;
60         this.tModel = tModel;
61     }
62
63
64     /**
65      * Set the interval of time between each ActionStat
66      * @param time
67      */

68     public void setTime(int time) {
69         this.time = time;
70     }
71
72     public void reset() {
73         totalTime = 0;
74         lastEvent = 0;
75     }
76
77     /**
78      * Get the statistics from the blades and update the graph
79      */

80     public void actionPerformed(ActionEvent JavaDoc e)
81     {
82         if (lastEvent != 0) {
83             diff =
84                 new Long JavaDoc((System.currentTimeMillis() - lastEvent) / 1000)
85                     .longValue();
86             if (diff > time) {
87                 // The refresh interval has changed before the end of timer period
88
// So we have to update the difference of time on the graph
89
totalTime += (diff - time);
90             }
91         }
92
93         totalTime += time;
94         // This line update the X Axis. It is necessary if no data is collected.
95
graph.updateXAxis(totalTime);
96
97         // Get all injectors to collect data from
98
injectors = tModel.getInjectorsToCollect();
99
100         for (int i = 0; i < injectors.length; i++)
101         {
102             long[] stats = suis.getStats((String JavaDoc) injectors[i]);
103             if (stats != null)
104             {
105                 for (int j = 0 ; j < stats.length ; ++j)
106                 {
107                     graph.addPoint(
108                         (String JavaDoc) injectors[i],
109                         j,
110                         totalTime,
111                         stats[j]);
112                 }
113             }
114         }
115         lastEvent = System.currentTimeMillis();
116
117         // Remove the graph and redraw the injectors to display
118
injectors = tModel.getAllInjectors();
119         for (int i = 0; i < injectors.length; i++) {
120             graph.removePointsFromDisplay((String JavaDoc) injectors[i]);
121         }
122
123         injectors = tModel.getInjectorsToDisplay();
124         for (int i = 0; i < injectors.length; i++) {
125             graph.addPointsOnDisplay((String JavaDoc) injectors[i]);
126         }
127
128         graph.updateGraph();
129     }
130 }
Popular Tags