1 23 package org.objectweb.clif.scenario.util.isac.engine; 24 25 import java.io.Serializable ; 26 import java.util.Hashtable ; 27 import java.util.StringTokenizer ; 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 50 public abstract class IsacScenarioEngine implements BladeControl, 51 BindingController, LifeCycleController { 52 protected Logger log; 54 55 public final static boolean DEBUG_ON = true; 56 57 private static final String PROPS_FILE = "etc/monolog.properties"; 58 59 static public LoggerFactory logger = Monolog.getMonologFactory(PROPS_FILE); 60 61 static private final String [] interfaceNames = new String [] { 63 DataCollectorWrite.DATA_COLLECTOR_WRITE, 64 BladeInsertResponse.BLADE_INSERT_RESPONSE }; 65 66 protected Serializable testId; 67 68 protected String scenarioId; 69 70 private String scenarioFileName; 71 72 protected BladeInsertResponse bladeInsertResponse; 73 74 protected Object bladeInsertResponse_lock = new Object (); 75 76 protected DataCollectorWrite dataCollectorWrite; 77 78 protected Object dataCollectorWrite_lock = new Object (); 79 80 protected String fcState = LifeCycleController.STOPPED; 81 82 protected SessionObjectManager sessionObjectManager; 84 85 protected BehaviorManager behaviorManager; 86 87 protected GroupDescriptionManager groupDescriptionManager; 88 89 92 public IsacScenarioEngine() { 93 } 94 95 99 102 private void initLogger() { 103 this.log = logger.getLogger(IsacScenarioEngine.class.getName()); 105 } 106 107 111 121 public void setArgument(String arg) { 122 StringTokenizer parser = new StringTokenizer (arg); 124 try { 125 this.scenarioFileName = parser.nextToken(); 126 } catch (Exception ex) { 127 throw new RuntimeException ( 128 "IsacScenarioEngine expects 1 argument: <scenarioFileName>"); 129 } 130 } 131 132 135 public void setId(String id) { 136 scenarioId = id; 137 } 138 139 142 public String getId() { 143 return scenarioId; 144 } 145 146 150 154 public void bindFc(String clientItfName, Object 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 170 public String [] listFc() { 171 return interfaceNames; 172 } 173 174 177 public Object lookupFc(String 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 191 public void unbindFc(String 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 208 211 public String getFcState() { 212 return fcState; 213 } 214 215 218 public void startFc() { 219 fcState = LifeCycleController.STARTED; 220 } 221 222 225 public void stopFc() { 226 stop(); 227 fcState = LifeCycleController.STOPPED; 228 } 229 230 234 237 public void init(Serializable arg) { 238 this.initLogger(); 240 Hashtable methodNameConversionTable = new Hashtable (); 243 Hashtable sessionObjectPluginName = new Hashtable (); 244 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 EngineScenarioAnalyzer.analyseScenarioFile( 255 scenarioFileName, 256 ClifClassLoader.getClassLoader(), 257 sessionObjectManager, 258 behaviorManager, 259 groupDescriptionManager); 260 } 261 262 265 abstract public void join(); 266 267 270 abstract public void resume(); 271 272 275 abstract public void start(); 276 277 280 abstract public void stop(); 281 282 285 abstract public void suspend(); 286 } | Popular Tags |