KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.Math JavaDoc;
37 import org.objectweb.clif.analyser.lib.gui.GuiPanelAutomaticAnalyser;
38
39
40
41 public class Hypothesis extends DecisionTree implements Runnable JavaDoc
42 {
43     
44     private BrancheX bx;
45     private BrancheY by;
46     private BrancheInterval bi;
47     private BrancheFonction bf;
48     private BrancheThread bth;
49     private BrancheMachine bm;
50     private BrancheTest bt;
51
52     private String JavaDoc name;
53     private String JavaDoc test;
54     private String JavaDoc machine;
55     private String JavaDoc thread;
56     private int X;
57     private int Y;
58     private String JavaDoc interval;
59     private int fonction;
60     private String JavaDoc fresult;
61
62     private DecisionTree dt;
63     private String JavaDoc[][] tabvar = new String JavaDoc[5][100];
64     private Thread JavaDoc thisThread;
65     private volatile Thread JavaDoc monitor;
66     private int numberOfVar ;
67     private int numberOfSoluc;
68
69
70     public Hypothesis(){};
71
72     //an hypothesis contain the same parameters than a View plus a statistic function name to be applied
73
//if a parameter name start with "VAR", this parameter is a liberty degree for the automatic search
74
public Hypothesis(String JavaDoc hyp, String JavaDoc test, String JavaDoc machine, String JavaDoc thread, int X, int Y, String JavaDoc interval, int fonction, String JavaDoc fresult)
75     {
76     int i=0;
77     this.name = hyp;
78     this.test = test;
79     if(test.startsWith("VAR")) { tabvar[0][0] = "1"; i++; }
80     else tabvar[0][0] = "0";
81     this.machine = machine;
82     if(machine.startsWith("VAR")) {tabvar[1][0] = "1";i++; }
83     else tabvar[1][0] = "0";
84     this.thread = thread;
85     if(thread.startsWith("VAR")) {tabvar[2][0] = "1";i++; }
86     else tabvar[2][0] = "0";
87     this.X = X;
88     this.Y = Y;
89     this.interval = interval;
90     if(interval.startsWith("VAR")) {tabvar[3][0] = "1";i++; }
91     else tabvar[3][0] = "0";
92     this.fonction = fonction;
93     this.fresult = fresult;
94     if(fresult.startsWith("VAR")) {tabvar[4][0] = "1";i++; }
95     else tabvar[4][0] = "0";
96     this.numberOfVar = i;
97     }
98        
99     //this function is used only if the hypothesis already exists
100
public void updateHyp(String JavaDoc test, String JavaDoc machine, String JavaDoc thread, int X, int Y, String JavaDoc interval, int fonction, String JavaDoc fresult)
101     {
102     int i=0;
103     this.test = test;
104     if(test.startsWith("VAR")) {tabvar[0][0] = "1";i++; }
105     else tabvar[0][0] = "0";
106     this.machine = machine;
107     if(machine.startsWith("VAR")) {tabvar[1][0] = "1";i++; }
108     else tabvar[1][0] = "0";
109     this.thread = thread;
110     if(thread.startsWith("VAR")) {tabvar[2][0] = "1";i++; }
111     else tabvar[2][0] = "0";
112     this.X = X;
113     this.Y = Y;
114     this.interval = interval;
115     if(interval.startsWith("VAR")) {tabvar[3][0] = "1"; i++; }
116     else tabvar[3][0] = "0";
117     this.fonction = fonction;
118     this.fresult = fresult;
119     if(fresult.startsWith("VAR")) {tabvar[4][0] = "1";i++; }
120     else tabvar[4][0] = "0";
121     this.numberOfVar = i;
122     }
123
124
125
126     public String JavaDoc getName() { return name; }
127     public String JavaDoc getTest() { return test; }
128     public String JavaDoc getMachine() { return machine; }
129     public String JavaDoc getInterval() { return interval; }
130
131
132     public long getDebut(){
133   
134     StringTokenizer st = new StringTokenizer(interval,"-"); ;
135     String JavaDoc temp = st.nextToken();
136     long toto = (new Long JavaDoc (temp)).longValue();
137     return toto;
138     }
139
140
141     public long getFin(){
142
143     StringTokenizer st = new StringTokenizer(interval,"-"); ;
144     st.nextToken();
145     String JavaDoc temp = st.nextToken();
146     long toto = (new Long JavaDoc(temp)).longValue();
147     return toto;
148
149     }
150
151
152     public String JavaDoc getThread() { return thread; }
153     public int getX() { return X; }
154     public int getY() { return Y; }
155     public int getFonction() { return fonction; }
156     public String JavaDoc getFresult() { return fresult; }
157
158     /**
159      * Start the hypothesis search
160      */

161     public void start()
162     {
163         monitor = new Thread JavaDoc(this);
164         monitor.start();
165     }
166
167
168     /**
169      * Stop the rule search
170      */

171     public void stop()
172     {
173     monitor = null;
174     }
175     
176     
177     //this is the algorithm of the search
178
//it's just a preview and can be very optimized
179

180     public void run()
181     {
182     
183     thisThread = Thread.currentThread();
184     numberOfSoluc =0;
185     while (monitor == thisThread) {
186         try {
187         Thread.sleep(5000);
188         } catch (InterruptedException JavaDoc e) {}
189         printResult();
190         dt = AutomaticAnalyser.getDecisionTree();
191         
192         if(tabvar[0][0].equals("0")){
193         int j;
194         for(j=0;dt.brancheTest[j]!=null;j++){
195             if(dt.brancheTest[j].getName().equals(test)) break;
196         }
197         if(dt.brancheTest[j]==null) ;
198         else{
199             bt = dt.brancheTest[j];
200             chercherFonction(bt);
201         }
202         }else{
203         int w;
204         for( w=0;dt.brancheTest[w]!=null;w++){
205             bt = dt.brancheTest[w];
206             chercherFonction(bt);
207         }
208         }
209     }
210     }
211     
212
213
214
215     public void chercherFonction(BrancheTest bt)
216     {
217
218     if(tabvar[1][0].equals("0")){
219         int k;
220         for( k=0;bt.brancheMachine[k]!=null;k++){
221         if(bt.brancheMachine[k].getName().equals(machine)) break;
222         }
223         if(bt.brancheMachine[k]==null) ;
224         else{
225         bm = bt.brancheMachine[k];
226         chercherFonction(bm);
227         }
228     }else{
229         int w;
230         for( w=0;bt.brancheMachine[w]!=null;w++){
231         bm = bt.brancheMachine[w];
232         chercherFonction(bm);
233         }
234     }
235     }
236
237
238
239     public void chercherFonction(BrancheMachine bm)
240     {
241     if(tabvar[2][0].equals("0")){
242         int l;
243         for( l=0;bm.brancheThread[l]!=null;l++){
244         if(bm.brancheThread[l].getName()==(new Integer JavaDoc(thread)).intValue()) break;
245         }
246         if(bm.brancheThread[l]==null) ;
247         else{
248         bth = bm.brancheThread[l];
249         chercherFonction(bth);
250         }
251     }else{
252         int w;
253         for( w=0;bm.brancheThread[w]!=null;w++){
254         bth = bm.brancheThread[w];
255         chercherFonction(bth);
256         }
257     }
258     }
259
260
261     public void chercherFonction(BrancheThread bth)
262     {
263
264
265     int m;
266     for( m=0;bth.brancheX[m]!=null;m++){
267         if(bth.brancheX[m].getName()==X) break;
268     }
269     if(bth.brancheX[m]==null) ;
270     else{
271         bx = bth.brancheX[m];
272         int n;
273         for( n=0;bx.brancheY[n]!=null;n++){
274         if(bx.brancheY[n].getName()==Y) break;
275         }
276         if(bx.brancheY[n]==null) ;
277         else{
278         by = bx.brancheY[n];
279         if(tabvar[3][0].equals("0")){
280             int o;
281             for( o=0;by.brancheInterval[o]!=null;o++){
282             if(by.brancheInterval[o].getName().equals(interval)) break;
283             }
284             if(by.brancheInterval[o]==null) ;
285             else{
286             bi = by.brancheInterval[o];
287             chercherFonction(bi);
288             }
289         }else{
290             int q;
291             for( q=0;by.brancheInterval[q]!=null;q++){
292             bi = by.brancheInterval[q];
293             chercherFonction(bi);
294             }
295         }
296         
297         }
298     }
299     
300     }
301     
302
303
304     public void chercherFonction(BrancheInterval bi)
305     {
306     int r;
307     for( r=0;bi.brancheFonction[r]!=null;r++){
308         if(bi.brancheFonction[r].getName()==fonction) break;
309     }
310     if(bi.brancheFonction[r]==null) bf = null;
311     else{
312         bf = bi.brancheFonction[r];
313         tabvar[0][numberOfSoluc+1] = bt.getName();
314         tabvar[1][numberOfSoluc+1] = bm.getName();
315         tabvar[2][numberOfSoluc+1] = (new Integer JavaDoc(bth.getName())).toString();
316         tabvar[3][numberOfSoluc+1] = bi.getName();
317         tabvar[4][numberOfSoluc+1] = (new Float JavaDoc(bf.getResult())).toString();
318         numberOfSoluc++;
319     }
320     }
321
322     public void printResult()
323     {
324     String JavaDoc result = "";
325     int i;
326     
327     if(tabvar[0][0].equals("1")) result = result + getTest()+"\t";
328     if(tabvar[1][0].equals("1")) result = result + getMachine()+"\t";
329     if(tabvar[2][0].equals("1")) result = result + getThread()+"\t";
330     if(tabvar[3][0].equals("1")) result = result + getInterval()+"\t";
331     if(tabvar[4][0].equals("1")) result = result + getFresult()+"\t";
332     result = result +"\n";
333
334     for(i=1;i < numberOfSoluc+1 ; i++)
335         {
336         if(tabvar[0][0].equals("1")) result = result + tabvar[0][i]+"\t";
337         if(tabvar[1][0].equals("1")) result = result + tabvar[1][i]+"\t";
338         if(tabvar[2][0].equals("1")) result = result + tabvar[2][i]+"\t";
339         if(tabvar[3][0].equals("1")) result = result + tabvar[3][i]+"\t";
340         if(tabvar[4][0].equals("1")) result = result + tabvar[4][i]+"\t";
341         result = result +"\n";
342         }
343
344     GuiPanelAutomaticAnalyser.updateResult(result);
345
346
347
348     }
349     
350     
351 }
352
Popular Tags