KickJava   Java API By Example, From Geeks To Geeks.

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


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
33
34
35 package org.objectweb.clif.analyser;
36
37 import java.io.*;
38 import java.util.*;
39 import java.lang.Math JavaDoc;
40 import org.objectweb.clif.analyser.lib.gui.GuiPanelAutomaticAnalyser;
41
42
43
44 public class Brain
45 {
46     private int minth;
47     private int maxti;
48     private String JavaDoc[][] testmachine;
49     private String JavaDoc[] tabinterval;
50     private String JavaDoc[] tabthread;
51     private Rule rule;
52     private Neuronous[] neuronous = new Neuronous[100];
53  
54
55     public Brain(Rule rule,int minth,int maxti,String JavaDoc[][] testmachine)
56     {
57     this.minth=minth;
58     this.maxti=maxti;
59     this.testmachine=testmachine;
60     this.rule = rule;
61     for(int i=0;rule.hyp[i] != null;i++) this.neuronous[i] = new Neuronous(rule.hyp[i]);
62     tabthread = new String JavaDoc[15];
63     tabinterval = new String JavaDoc[15];
64     tabthread[0] = "-1";
65     tabthread[1] = "1";
66     tabthread[2] = ""+minth;
67     tabinterval[0] = "0-" + maxti;
68     }
69     /**
70      * Start the Brain
71      */

72     public void start()
73     {
74     System.out.println("Brain "+rule.getName() +" started");
75     for(int i=0; neuronous[i] != null;i++) neuronous[i].start();
76     }
77     
78     
79     /**
80      * Stop the rule search
81      */

82     public void stop()
83     {
84     System.out.println("Brain "+rule.getName() +" stopped");
85     for(int i=0; neuronous[i] != null;i++) neuronous[i].stop();
86     }
87     
88     
89   
90
91
92
93     class Neuronous implements Runnable JavaDoc
94     {
95     private Thread JavaDoc thisThread;
96     private volatile Thread JavaDoc monitor;
97     private Hypothesis hyp;
98     private String JavaDoc varname;
99     private String JavaDoc vartest;
100     private String JavaDoc varmachine;
101     private int varthread;
102     private String JavaDoc varinterval;
103     private long debut;
104     private long fin;
105     private View vue;
106     private StringTokenizer st;
107
108     public Neuronous(Hypothesis hyp)
109     {
110         this.hyp = hyp;
111     }
112
113
114     /**
115      * Start the Brain
116      */

117     public void start()
118     {
119         monitor = new Thread JavaDoc(this);
120         monitor.start();
121     }
122     
123     
124     /**
125      * Stop the rule search
126      */

127     public void stop()
128     {
129         monitor = null;
130     }
131     
132     
133     public void run()
134     {
135         int i=0;
136         thisThread = Thread.currentThread();
137         
138         while (monitor == thisThread) {
139         try {
140             Thread.sleep(10000);
141         } catch (InterruptedException JavaDoc e) {}
142         
143     
144         if(hyp.getTest().startsWith("VAR")){
145             for(int a=0;testmachine[a][0]!=null;a++){
146             vartest = testmachine[a][0];
147             if(hyp.getMachine().startsWith("VAR")){
148                 for(int b=1;testmachine[a][b]!=null;b++){
149                 varmachine = testmachine[a][b];
150                 creer();
151                 }
152             }else{
153                 varmachine = hyp.getMachine();
154                 creer();
155             }
156             }
157         }else{
158             vartest = hyp.getTest();
159             int index;
160             for(index=0;!(testmachine[index][0].equals(vartest));index++);
161             if(hyp.getTest().startsWith("VAR")){
162             for(int a=1;testmachine[index][a]!=null;a++){
163                 varmachine = testmachine[index][a];
164                 creer();
165             }
166             }else{
167             varmachine = hyp.getMachine();
168             creer();
169             }
170         }
171         
172         
173         }//fin du while
174
}//fin du run
175

176
177
178     public void creer()
179     {
180         
181         if(hyp.getThread().startsWith("VAR")){
182         for(int a=0;tabthread[a]!=null;a++){
183             varthread = (new Integer JavaDoc(tabthread[a])).intValue();
184             if(hyp.getInterval().startsWith("VAR")){
185             for(int b=0;tabinterval[b]!=null;b++){
186                 varinterval = tabinterval[b];
187                 st = new StringTokenizer(varinterval,"-");
188                 debut = (new Long JavaDoc(st.nextToken())).longValue();
189                 fin = (new Long JavaDoc(st.nextToken())).longValue();
190                 generer();
191             }
192             }else{
193             varinterval = hyp.getInterval();
194             st = new StringTokenizer(varinterval,"-");
195             debut = (new Long JavaDoc(st.nextToken())).longValue();
196             fin = (new Long JavaDoc(st.nextToken())).longValue();
197             generer();
198             }
199         }
200         }else{
201         varthread = (new Integer JavaDoc(hyp.getThread())).intValue();
202         if(hyp.getInterval().startsWith("VAR")){
203             for(int a=0;tabinterval[a]!=null;a++){
204             varinterval = tabinterval[a];
205             st = new StringTokenizer(varinterval,"-");
206             debut = (new Long JavaDoc(st.nextToken())).longValue();
207             fin = (new Long JavaDoc(st.nextToken())).longValue();
208             generer();
209             }
210         }else{
211             varinterval = hyp.getInterval();
212             st = new StringTokenizer(varinterval,"-");
213             debut = (new Long JavaDoc(st.nextToken())).longValue();
214             fin = (new Long JavaDoc(st.nextToken())).longValue();
215             generer();
216         }
217         }
218     }
219     
220     
221
222     public void generer()
223     {
224             varname = "auto_"+vartest+"_"+varmachine+"_"+varthread+"_"+ hyp.getX()+"_"+hyp.getY()+"_"+debut+"_"+fin;
225         View vue = new View(varname,vartest,varmachine,varthread,"hyp.getX()","hyp.getY()",debut,fin);
226         if(hyp.getFonction()==0) Fonction.fonctionMax(vue);
227         if(hyp.getFonction()==1) Fonction.fonctionMin(vue);
228         if(hyp.getFonction()==2) Fonction.fonctionMoyenne(vue);
229         if(hyp.getFonction()==3) Fonction.fonctionEcart(vue);
230         if(hyp.getFonction()==4) Fonction.fonctionPente(vue);
231     }
232
233
234
235     
236     }
237     
238     
239 }
240
Popular Tags