1 23 24 package org.objectweb.clif.isac.plugins.httpmatrix10; 25 26 import java.util.Hashtable ; 27 28 import org.apache.commons.httpclient.HostConfiguration; 29 import org.apache.commons.httpclient.HttpClient; 30 import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; 31 import org.objectweb.clif.isac.plugins.httpmatrix10.actions.MatrixSamples; 32 import org.objectweb.clif.isac.plugins.httpmatrix10.actions.MatrixTests; 33 import org.objectweb.clif.isac.plugins.httpmatrix10.actions.MatrixTimers; 34 import org.objectweb.clif.scenario.util.isac.exception.IsacRuntimeException; 35 import org.objectweb.clif.scenario.util.isac.plugin.SampleAction; 36 import org.objectweb.clif.scenario.util.isac.plugin.TestAction; 37 import org.objectweb.clif.scenario.util.isac.plugin.TimerAction; 38 import org.objectweb.clif.scenario.util.isac.util.SessionObjectAction; 39 import org.objectweb.clif.scenario.util.transitions.TransitionTable; 40 import org.objectweb.clif.storage.api.ActionEvent; 41 42 49 public class SessionObject implements SampleAction, TimerAction, TestAction, SessionObjectAction { 50 public static final int SAMPLE_DO_NEXT = 0; 54 55 public static final int TIMER_WAITING_TIME = 0; 57 58 public static final int TEST_HAS_NEXT = 1; 60 61 public static final int TEST_HAS_PREVIOUS = 0; 63 64 65 private static final double DEFAULT_WAITING_TIME = 5; 67 private static final int DEFAULT_NB_HITS = 0 ; 70 71 public static final String FILE_MATRIX = "filematrix" ; 73 public static final String FILE_ACTIONS = "fileactions"; 74 public static final String HOST = "host" ; 75 public static final String PORT = "port" ; 76 77 private TransitionTable transitionTable ; 79 80 private HttpClient httpClient; 82 83 private String host ; 85 private String port ; 86 87 private boolean finishState ; 89 90 96 public SessionObject(Hashtable params) { 97 this.httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); 99 this.port = (String )params.get(PORT); 101 this.host = (String )params.get(HOST); 102 try { 105 if (!host.equals("") && !port.equals("")) { 106 this.setProxy(host, (new Integer (port)).intValue()); 107 } 108 } catch (NullPointerException ne) { 109 System.err.println("Unable to set the proxy...") ; 110 } catch (NumberFormatException nfe) { 111 System.err.println("Unable to set the proxy, the port seams to be malformed"); 112 } 113 114 String fileName = (String )params.get(FILE_MATRIX); 116 String fileActions = (String )params.get(FILE_ACTIONS); 118 this.transitionTable = new TransitionTable(fileName, fileActions, false, false); 120 this.finishState = false; 122 } 123 124 128 private SessionObject(SessionObject so) { 129 this.httpClient = so.getHttpClient() ; 132 this.transitionTable = so.getTransitionTable().createNewTransitionTable() ; 134 this.finishState = false; 136 } 137 138 142 public ActionEvent doSample(int number, Hashtable params, ActionEvent report) { 143 switch (number) { 145 case SAMPLE_DO_NEXT: 146 return MatrixSamples.doNext(this, params, report); 147 default: 148 throw new IsacRuntimeException( 149 "Unable to find this sample in matrix plugin : " + number); 150 } 151 } 152 153 157 public long doTimer(int number, Hashtable params) { 158 switch (number) { 160 case TIMER_WAITING_TIME: 161 return MatrixTimers.waitingTime(this); 162 default: 163 throw new IsacRuntimeException( 164 "Unable to find this timer in matrix plugin : " + number); 165 } 166 } 167 168 172 public boolean doTest(int number, Hashtable params) { 173 switch (number) { 175 case TEST_HAS_NEXT: 176 return MatrixTests.hasNext(this); 177 case TEST_HAS_PREVIOUS: 178 return MatrixTests.hasNext(this); 179 default: 180 throw new IsacRuntimeException( 181 "Unable to find this test in matrix plugin : " + number); 182 } 183 } 184 185 193 private void setProxy(String host, int port) { 194 HostConfiguration hostConfiguration = new HostConfiguration(); 196 hostConfiguration.setProxy(host, port); 197 this.httpClient.setHostConfiguration(hostConfiguration); 199 } 200 201 205 208 public Object createNewSessionObject() { 209 return new SessionObject(this) ; 210 } 211 212 215 public void close() { 216 } 218 219 222 public void reset() { 223 this.transitionTable.resetPreviousState(); 225 this.finishState = false; 227 } 228 229 233 236 public HttpClient getHttpClient() { 237 return httpClient; 238 } 239 240 244 public void setHttpClient(HttpClient httpClient) { 245 this.httpClient = httpClient; 246 } 247 248 251 public TransitionTable getTransitionTable() { 252 return transitionTable; 253 } 254 255 258 public String getHost() { 259 return host; 260 } 261 264 public String getPort() { 265 return port; 266 } 267 268 271 public boolean isFinishState() { 272 return finishState; 273 } 274 277 public void setFinishState(boolean finishState) { 278 this.finishState = finishState; 279 } 280 284 301 } 334 | Popular Tags |