KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.objectweb.clif.analyser;
32
33 import java.io.*;
34 import java.util.*;
35 import java.lang.Math JavaDoc;
36 import org.objectweb.clif.analyser.lib.gui.GuiPanelAutomaticAnalyser;
37
38
39
40 //a rule is composed by its name and an array of hypothesis.
41
//a rule is true if and only if there exist one or more solution to all hypothesis of that rule
42
//and if the combination of all the solution of the hypothesis verify the condition of the rule
43

44 public class Rule
45 {
46     private String JavaDoc name;
47     protected Hypothesis[] hyp;
48     private Thread JavaDoc thisThread;
49     private volatile Thread JavaDoc[] monitor= new Thread JavaDoc[100];
50
51  
52
53     //when a rule is creating an hypothesis is also created.
54
//all rules must have at least one hypothesis
55
public Rule(String JavaDoc name, String JavaDoc hypo, String JavaDoc test, String JavaDoc machine, String JavaDoc thread, int X, int Y, String JavaDoc interval, int fonction, String JavaDoc fresult)
56     {
57     this.name = name;
58     this.hyp = new Hypothesis[100];
59     hyp[0] = new Hypothesis(hypo,test,machine,thread,X,Y,interval,fonction,fresult);
60     }
61        
62
63     public String JavaDoc getName() { return name; }
64
65     
66
67     /* this fonction update an existing rule by creating new hypothesis or
68      * modifying an existing ones
69      */

70     public void updateRule(String JavaDoc hypo,String JavaDoc test,String JavaDoc machine,String JavaDoc thread,int X,int Y,String JavaDoc interval,int fonction,String JavaDoc fresult)
71     {
72     int i;
73     for(i=0; hyp[i] != null; i++)
74         if(hyp[i].getName().equals(hypo))
75         {
76             hyp[i].updateHyp(test,machine,thread,X,Y,interval,fonction,fresult);
77             break;
78         }
79     if(hyp[i] == null) hyp[i] = new Hypothesis(hypo,test,machine,thread,X,Y,interval,fonction,fresult);
80     }
81      
82
83
84     /* erase an hypothesis from the current rule
85      *
86      */

87     public void eraseHyp(String JavaDoc name,String JavaDoc hypo)
88     {
89     int i,j;
90     int etat =0;
91     for(i=0; hyp[i] != null; i++)
92         if(hyp[i].getName().equals(hypo))
93         {
94             for(j=i; hyp[j] != null; j++) hyp[j] = hyp[j+1];
95             etat = 1;
96         }
97     if(etat==0) System.out.println("l'hypothese "+hypo+" n'existe pas ! impossible de l'effacer...");
98     AutomaticAnalyser aa = new AutomaticAnalyser();
99     if(i==1) aa.eraseRule(name);
100     }
101
102
103     /**
104      * Start the rule search...
105 //this function create one thread by hypothesis contained by this rule
106      */

107     public void start()
108     {
109         System.out.println("rule "+getName() +" started");
110         for(int i=0;hyp[i]!=null;i++)
111             {
112                hyp[i].start();
113             }
114     }
115
116
117     /**
118      * Stop the rule search...
119 //this function stop all the searching threads of all hypothesis contained by this rule
120      */

121     public void stop()
122     {
123     System.out.println("rule "+getName() +" stopped");
124     for(int i=0;hyp[i]!=null;i++)
125         {
126         hyp[i].stop();
127         }
128     }
129        
130 }
131
Popular Tags