KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > engine > IsacScenarioEngine


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

23 package org.objectweb.clif.scenario.util.isac.engine;
24
25 import java.io.Serializable JavaDoc;
26 import java.util.Hashtable JavaDoc;
27 import java.util.StringTokenizer JavaDoc;
28
29 import org.objectweb.clif.datacollector.api.DataCollectorWrite;
30 import org.objectweb.clif.scenario.util.isac.engine.behavior.BehaviorManager;
31 import org.objectweb.clif.scenario.util.isac.engine.loadprofile.GroupDescriptionManager;
32 import org.objectweb.clif.scenario.util.isac.engine.sessionobject.SessionObjectManager;
33 import org.objectweb.clif.server.api.BladeControl;
34 import org.objectweb.clif.server.api.BladeInsertResponse;
35 import org.objectweb.clif.util.ClifClassLoader;
36 import org.objectweb.fractal.api.control.BindingController;
37 import org.objectweb.fractal.api.control.LifeCycleController;
38 import org.objectweb.util.monolog.Monolog;
39 import org.objectweb.util.monolog.api.Logger;
40 import org.objectweb.util.monolog.api.LoggerFactory;
41
42 /**
43  * This is an abstract class which impelements the fractal methods, this class
44  * will be sub-classed which a class which will be implements the execution
45  * managing methods
46  *
47  * @author JC Meillaud
48  * @author A Peyrard
49  */

50 public abstract class IsacScenarioEngine implements BladeControl,
51         BindingController, LifeCycleController {
52     // logger
53
protected Logger log;
54
55     public final static boolean DEBUG_ON = true;
56
57     private static final String JavaDoc PROPS_FILE = "etc/monolog.properties";
58
59     static public LoggerFactory logger = Monolog.getMonologFactory(PROPS_FILE);
60
61     // attributes
62
static private final String JavaDoc[] interfaceNames = new String JavaDoc[] {
63             DataCollectorWrite.DATA_COLLECTOR_WRITE,
64             BladeInsertResponse.BLADE_INSERT_RESPONSE };
65
66     protected Serializable JavaDoc testId;
67
68     protected String JavaDoc scenarioId;
69
70     private String JavaDoc scenarioFileName;
71
72     protected BladeInsertResponse bladeInsertResponse;
73
74     protected Object JavaDoc bladeInsertResponse_lock = new Object JavaDoc();
75
76     protected DataCollectorWrite dataCollectorWrite;
77
78     protected Object JavaDoc dataCollectorWrite_lock = new Object JavaDoc();
79
80     protected String JavaDoc fcState = LifeCycleController.STOPPED;
81
82     // the managers
83
protected SessionObjectManager sessionObjectManager;
84
85     protected BehaviorManager behaviorManager;
86
87     protected GroupDescriptionManager groupDescriptionManager;
88
89     /**
90      * Empty constructor, never used
91      */

92     public IsacScenarioEngine() {
93     }
94
95     /////////////////////////////////////
96
// Logger
97
/////////////////////////////////////
98

99     /**
100      * This method initialize the logger
101      */

102     private void initLogger() {
103         // init the log for this class
104
this.log = logger.getLogger(IsacScenarioEngine.class.getName());
105     }
106
107     ////////////////////////////////////////
108
// BladeControl methods
109
////////////////////////////////////////
110

111     /**
112      * Sets scenario filename and the methods of thread life cycle If this
113      * second parameter is false, then don't force the thread to stop, wait for
114      * the end of the threads, else set the force mode
115      *
116      * @param arg
117      * should begin with two string parameters (separated with usual
118      * separators) setting (1) the filename of the scenario (2) the
119      * method of the behaviors threads endings.
120      */

121     public void setArgument(String JavaDoc arg) {
122         // parse the argument string
123
StringTokenizer JavaDoc parser = new StringTokenizer JavaDoc(arg);
124         try {
125             this.scenarioFileName = parser.nextToken();
126         } catch (Exception JavaDoc ex) {
127             throw new RuntimeException JavaDoc(
128                     "IsacScenarioEngine expects 1 argument: <scenarioFileName>");
129         }
130     }
131
132     /**
133      * Sets this scenario's unique identifier
134      */

135     public void setId(String JavaDoc id) {
136         scenarioId = id;
137     }
138
139     /**
140      * @return the scenario/blade identifier
141      */

142     public String JavaDoc getId() {
143         return scenarioId;
144     }
145
146     //////////////////////////////////////////////
147
// Binding controler methods
148
//////////////////////////////////////////////
149

150     /**
151      * @see org.objectweb.fractal.api.control.BindingController#bindFc(java.lang.String,
152      * java.lang.Object)
153      */

154     public void bindFc(String JavaDoc clientItfName, Object JavaDoc serverItf) {
155         if (clientItfName.equals(DataCollectorWrite.DATA_COLLECTOR_WRITE)) {
156             synchronized (dataCollectorWrite_lock) {
157                 dataCollectorWrite = (DataCollectorWrite) serverItf;
158             }
159         } else if (clientItfName
160                 .equals(BladeInsertResponse.BLADE_INSERT_RESPONSE)) {
161             synchronized (bladeInsertResponse_lock) {
162                 bladeInsertResponse = (BladeInsertResponse) serverItf;
163             }
164         }
165     }
166
167     /**
168      * @see org.objectweb.fractal.api.control.BindingController#listFc()
169      */

170     public String JavaDoc[] listFc() {
171         return interfaceNames;
172     }
173
174     /**
175      * @see org.objectweb.fractal.api.control.BindingController#lookupFc(java.lang.String)
176      */

177     public Object JavaDoc lookupFc(String JavaDoc clientItfName) {
178         if (clientItfName.equals(DataCollectorWrite.DATA_COLLECTOR_WRITE)) {
179             return dataCollectorWrite;
180         } else if (clientItfName
181                 .equals(BladeInsertResponse.BLADE_INSERT_RESPONSE)) {
182             return bladeInsertResponse;
183         } else {
184             return null;
185         }
186     }
187
188     /**
189      * @see org.objectweb.fractal.api.control.BindingController#unbindFc(java.lang.String)
190      */

191     public void unbindFc(String JavaDoc clientItfName) {
192         if (clientItfName.equals(DataCollectorWrite.DATA_COLLECTOR_WRITE)) {
193             synchronized (dataCollectorWrite_lock) {
194                 dataCollectorWrite = null;
195             }
196         } else if (clientItfName
197                 .equals(BladeInsertResponse.BLADE_INSERT_RESPONSE)) {
198             synchronized (bladeInsertResponse_lock) {
199                 bladeInsertResponse = null;
200             }
201         }
202     }
203
204     ///////////////////////////////////////////
205
// LifeCycleController methods...
206
///////////////////////////////////////////
207

208     /**
209      * @see org.objectweb.fractal.api.control.LifeCycleController#getFcState()
210      */

211     public String JavaDoc getFcState() {
212         return fcState;
213     }
214
215     /**
216      * @see org.objectweb.fractal.api.control.LifeCycleController#startFc()
217      */

218     public void startFc() {
219         fcState = LifeCycleController.STARTED;
220     }
221
222     /**
223      * @see org.objectweb.fractal.api.control.LifeCycleController#stopFc()
224      */

225     public void stopFc() {
226         stop();
227         fcState = LifeCycleController.STOPPED;
228     }
229
230     ////////////////////////////////////////////////
231
// BladeControl methods
232
////////////////////////////////////////////////
233

234     /**
235      * @see org.objectweb.clif.server.api.ActivityControl#init(java.io.Serializable)
236      */

237     public void init(Serializable JavaDoc arg) {
238         // init monolog factory
239
this.initLogger();
240         // init some temporary hashtable which will be used in transfer of datas
241
// between manager
242
Hashtable JavaDoc methodNameConversionTable = new Hashtable JavaDoc();
243         Hashtable JavaDoc sessionObjectPluginName = new Hashtable JavaDoc();
244         // initialize the session object manager
245
this.sessionObjectManager = new SessionObjectManager(
246                 methodNameConversionTable, sessionObjectPluginName);
247         this.behaviorManager = new BehaviorManager(methodNameConversionTable,
248                 sessionObjectPluginName, this.sessionObjectManager
249                         .getSessionObjectTable(), this.sessionObjectManager
250                         .getSessionObjectForABehavior());
251         this.groupDescriptionManager = new GroupDescriptionManager();
252
253         // load the scenario file
254
EngineScenarioAnalyzer.analyseScenarioFile(
255             scenarioFileName,
256             ClifClassLoader.getClassLoader(),
257             sessionObjectManager,
258             behaviorManager,
259             groupDescriptionManager);
260     }
261
262     /**
263      * @see org.objectweb.clif.server.api.ActivityControl#join()
264      */

265     abstract public void join();
266
267     /**
268      * @see org.objectweb.clif.server.api.ActivityControl#resume()
269      */

270     abstract public void resume();
271
272     /**
273      * @see org.objectweb.clif.server.api.ActivityControl#start()
274      */

275     abstract public void start();
276
277     /**
278      * @see org.objectweb.clif.server.api.ActivityControl#stop()
279      */

280     abstract public void stop();
281
282     /**
283      * @see org.objectweb.clif.server.api.ActivityControl#suspend()
284      */

285     abstract public void suspend();
286 }
Popular Tags