KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > analyser > Analyser


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2003 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
25
26 /**
27  *
28  * @author Damien Croizer
29  */

30
31
32 package org.objectweb.clif.analyser;
33
34 import java.io.*;
35 import java.util.*;
36 import javax.swing.*;
37 import java.awt.*;
38 import org.objectweb.clif.analyser.lib.gui.GuiPanelAnalyser;
39
40
41 public class Analyser
42 {
43
44     private static String JavaDoc[][] vuesdisponibles = new String JavaDoc[100][100];
45     private static View[] existingviews = new View[100];
46     private static int index;
47     private static int i=0;
48
49     private static GuiPanelAnalyser guipanelanalyser;
50
51   public Analyser()
52     {
53     }
54
55     public Analyser(GuiPanelAnalyser guiPanelAnalyser)
56     {
57     this.guipanelanalyser = guiPanelAnalyser;
58     }
59
60     public void update()
61     {
62     index=0;
63     listerFichier();
64     fileToView();
65     guipanelanalyser.updateViewTree(vuesdisponibles);
66     }
67     
68   /**
69      * start the analyser interface
70      */

71     public static void start(){
72
73     index=0;
74     listerFichier();
75     fileToView();
76     guipanelanalyser.updateViewTree(vuesdisponibles);
77     
78     
79     }
80     /**
81      * make a view from the selectionned params
82      */

83     public static View creer(String JavaDoc name, String JavaDoc testId, String JavaDoc blade,int thread,String JavaDoc paramX,String JavaDoc paramY, String JavaDoc interval, int option){
84
85     StringTokenizer st;
86     st = new StringTokenizer(interval,"-") ;
87     int tempdatedebut = (new Integer JavaDoc(st.nextToken())).intValue() ;
88     int tempdatefin = (new Integer JavaDoc(st.nextToken())).intValue() ;
89                 
90     View vue = new View(name,testId,blade,thread,paramX,paramY,tempdatedebut,tempdatefin,option);
91     return vue;
92     }
93
94
95
96
97     public static View wichViewNamed(String JavaDoc nodeparent,String JavaDoc node)
98     {
99     for(int i=0; i < index ;i++)
100         {
101         String JavaDoc temp;
102         String JavaDoc temp2;
103         if(node.endsWith(".view")) temp = existingviews[i].getName() + ".view" ;
104         else temp = existingviews[i].getName();
105         if(nodeparent.endsWith("_rapport")) temp2 = existingviews[i].getTestId() + "_rapport" ;
106         else temp2 = existingviews[i].getTestId();
107     
108         if (node.equalsIgnoreCase(temp) && nodeparent.equalsIgnoreCase(temp2) ) return existingviews[i];
109         }
110     return null;
111     }
112
113
114
115
116
117     
118  
119     /**
120      * calcul the maximum of the selected view
121      */

122     public static void max(String JavaDoc testname,String JavaDoc vuename){
123     View selectedView = wichViewNamed(testname,vuename);
124     if(selectedView != null){
125         Fonction.fonctionMax(selectedView);
126     }
127     else System.out.println("vue non valide");
128     guipanelanalyser.setView(selectedView);
129     }
130  
131   public static void min(String JavaDoc testname,String JavaDoc vuename){
132     View selectedView = wichViewNamed(testname,vuename);
133     if(selectedView != null){
134         Fonction.fonctionMin(selectedView);
135     }
136     else System.out.println("vue non valide");
137     guipanelanalyser.setView(selectedView);
138     }
139
140
141   public static void moyenne(String JavaDoc testname,String JavaDoc vuename){
142     View selectedView = wichViewNamed(testname,vuename);
143     if(selectedView != null){
144         Fonction.fonctionMoyenne(selectedView);
145     }
146     else System.out.println("vue non valide");
147     guipanelanalyser.setView(selectedView);
148     }
149
150   public static void ecart(String JavaDoc testname,String JavaDoc vuename){
151     View selectedView = wichViewNamed(testname,vuename);
152     if(selectedView != null){
153         Fonction.fonctionEcart(selectedView);
154     }
155     else System.out.println("vue non valide");
156     guipanelanalyser.setView(selectedView);
157     }
158
159  public static void pente(String JavaDoc testname,String JavaDoc vuename){
160     View selectedView = wichViewNamed(testname,vuename);
161     if(selectedView != null){
162         Fonction.fonctionPente(selectedView);
163     }
164     else System.out.println("vue non valide");
165     guipanelanalyser.setView(selectedView);
166     }
167
168
169   public static void augmentreg(String JavaDoc testname,String JavaDoc vuename,int indice){
170     View selectedView = wichViewNamed(testname,vuename);
171     if(selectedView != null){
172         selectedView.setResult(Fonction.fonctionAugmentReg(selectedView,indice));
173     }
174     else System.out.println("vue non valide");
175     guipanelanalyser.setView(selectedView);
176     }
177
178
179   public static void diminreg(String JavaDoc testname,String JavaDoc vuename,int indice){
180     View selectedView = wichViewNamed(testname,vuename);
181     if(selectedView != null){
182         selectedView.setResult(Fonction.fonctionDiminReg(selectedView,indice));
183     }
184     else System.out.println("vue non valide");
185     guipanelanalyser.setView(selectedView);
186     }
187
188   public static void stationreg(String JavaDoc testname,String JavaDoc vuename,int indice){
189     View selectedView = wichViewNamed(testname,vuename);
190     if(selectedView != null){
191         selectedView.setResult(Fonction.fonctionStationReg(selectedView, indice));
192     }
193     else System.out.println("vue non valide");
194     guipanelanalyser.setView(selectedView);
195     }
196
197
198
199
200
201
202     public static void listerFichier()
203     {
204     File homeDir = new File("report/");
205     if(homeDir.exists())
206         {
207         String JavaDoc[] contient = homeDir.list();
208         int i;
209         for (i=0; i < contient.length ;i++)
210             {
211             try {
212                 (new File("report/" + contient[i] + "/vues")).mkdir();
213             }catch (Exception JavaDoc e) {
214                 e.printStackTrace() ;
215                 System.exit(0) ;
216             }
217             String JavaDoc archive = new String JavaDoc("report/" + contient[i] + "/archive.clif");
218             if((new File(archive)).exists())
219                 {
220                 int k=0;
221                 vuesdisponibles[i][k] = contient[i];
222                 guipanelanalyser.addTest(contient[i]);
223                 File vueDir = new File("report/" + contient[i] + "/vues");
224                 if(vueDir.exists())
225                     {
226                     String JavaDoc[] contient2 = new String JavaDoc[100];
227                     contient2 = vueDir.list();
228                     k++;
229                     for (int z=0;z<contient2.length ; z++)
230                         {
231                         if(contient2[z].endsWith(".view")) vuesdisponibles[i][k++] = contient2[z];
232                         }
233                     vuesdisponibles[i][k] = null;
234                     }
235                 }
236             }
237         vuesdisponibles[i+1][0] = null;
238         }
239     }
240
241     public static void fileToView()
242     {
243     String JavaDoc line = null ;
244         BufferedReader file ;
245     FileInputStream fileInput;
246     StringTokenizer st;
247     
248     try {
249     for(int i = 0 ; vuesdisponibles[i][0] != null ; i++)
250         for(int j = 1 ; vuesdisponibles[i][j] != null ; j++)
251         {
252
253             fileInput = new FileInputStream("report/" +vuesdisponibles[i][0] + "/vues/" + vuesdisponibles[i][j] );
254             file = new BufferedReader(new InputStreamReader(fileInput));
255             line = file.readLine() ;
256             st = new StringTokenizer(line,"|") ;
257             if(!st.nextToken().equalsIgnoreCase("#")) System.out.println("le fichier " + vuesdisponibles[i][0] + "/" + vuesdisponibles[i][j] + " est erroné !");
258             else
259             {
260                 View vue = new View();
261                 vue.setName(st.nextToken());
262                 vue.setTestId(st.nextToken());
263                 vue.setParamX(st.nextToken());
264                 vue.setParamY(st.nextToken());
265                 vue.setNommachine(st.nextToken());
266                 vue.setNumthread((new Integer JavaDoc(st.nextToken())).intValue());
267                 vue.setDatedebut((new Long JavaDoc(st.nextToken())).longValue());
268                 vue.setDatefin((new Long JavaDoc(st.nextToken())).longValue());
269                 existingviews[index++] = vue;
270
271             }
272                                     
273         }
274         }
275     catch (Exception JavaDoc e) {
276         e.printStackTrace() ;
277         System.exit(0) ;
278     }
279     
280     }
281     
282     public static String JavaDoc parseArchive(String JavaDoc archive)
283     {
284     String JavaDoc result = "";
285     try {
286     String JavaDoc line = null;
287     BufferedReader file = new BufferedReader(new InputStreamReader(new FileInputStream(archive)));
288     String JavaDoc[] bladeList = new String JavaDoc[100];
289     int indexblade=0;
290     String JavaDoc[] paramList = new String JavaDoc[100];
291     int indexparam=0;
292     long maxTime=0;
293     
294     line = file.readLine() ;
295     while(line != null)
296         {
297         StringTokenizer st = new StringTokenizer(line,";") ;
298         long temp = (new Long JavaDoc(st.nextToken())).longValue();
299         if(temp > maxTime) maxTime = temp;
300         st.nextToken();
301         String JavaDoc tempblade = st.nextToken();
302         if(!exists(tempblade,bladeList)) bladeList[indexblade++] = tempblade;
303         st.nextToken();st.nextToken();st.nextToken();st.nextToken();st.nextToken();
304         String JavaDoc tempparam = st.nextToken();
305         if(!exists(tempparam,paramList)) paramList[indexparam++] = tempparam;
306         line = file.readLine() ;
307         }
308     result = result + maxTime + ";";
309     for(int i=0; bladeList[i] != null ;i++) result = result + bladeList[i] + "|" ;
310     result = result + ";" ;
311     for(int i=0; paramList[i] != null ;i++) result = result + paramList[i] + "|" ;
312     }
313     catch (Exception JavaDoc e) {
314         e.printStackTrace() ;
315         System.exit(0) ;
316     }
317     return result;
318     }
319
320     public static boolean exists(String JavaDoc instance, String JavaDoc[] list)
321     {
322     for(int i=0; list[i] != null ;i++)
323         if(list[i].equals(instance)) return true;
324     return false;
325     }
326     
327 }
328
Popular Tags