1 24 25 package org.objectweb.cjdbc.requestplayer; 26 27 import java.io.File ; 28 import java.io.FileInputStream ; 29 import java.io.IOException ; 30 import java.io.InputStream ; 31 import java.util.Properties ; 32 33 41 public class RequestPlayerProperties extends Properties 42 { 43 44 public static final String DEFAULT_CONFIG_FILE = "requestplayer.properties"; 45 46 47 public static final int STANDARD_CONNECTION = 0; 48 49 50 public static final int FIXED_CONNECTION = 1; 51 52 53 public static final int POOLING_CONNECTION = 2; 54 55 56 private File configFile; 57 58 59 private String traceFile; 60 61 65 private int nbRequests = 0; 66 67 68 private int nbClients = 0; 69 70 71 private int timeout = 0; 72 73 74 private String databaseDriver; 75 76 77 private String databaseUrl; 78 79 80 private String databaseLogin; 81 82 83 private String databasePassword; 84 85 89 private int connectionType; 90 91 95 private int poolSize = 0; 96 97 106 public RequestPlayerProperties(String configFileString) 107 { 108 if (configFileString == null) 109 { 110 configFile = new File (DEFAULT_CONFIG_FILE); 111 } 112 else 113 { 114 configFile = new File (configFileString); 115 116 if (!configFile.isFile() || !configFile.exists()) 118 { 119 System.err.println( 120 "Cannot read the request player configuration file '" 121 + configFile.toString() 122 + "'"); 123 Runtime.getRuntime().exit(1); 124 } 125 } 126 127 try 129 { 130 InputStream stream = null; 131 if (configFileString == null) 132 { 133 134 stream = 135 RequestPlayerProperties.class.getResourceAsStream( 136 "/" + DEFAULT_CONFIG_FILE); 137 if (stream == null) 138 { 139 System.err.println( 140 "Cannot find request player properties file '" 141 + DEFAULT_CONFIG_FILE 142 + "' in classpath"); 143 } 144 } 145 else 146 { 147 stream = new FileInputStream (configFile); 148 } 149 150 super.load(stream); 151 stream.close(); 152 } 153 catch (IOException e) 154 { 155 System.err.println( 156 "An error occured when reading the request player properties file '" 157 + configFile.toString() 158 + "'"); 159 Runtime.getRuntime().exit(1); 160 } 161 } 162 163 169 public boolean checkPropertiesFile() 170 { 171 try 172 { 173 System.out.println(); 174 System.out.println("### Database information ###"); 175 databaseUrl = getProperty("db_url"); 176 System.out.println("Database url : " + databaseUrl); 177 databaseDriver = getProperty("db_driver"); 178 System.out.println("Database driver : " + databaseDriver); 179 databaseLogin = getProperty("db_username"); 180 System.out.println("Username : " + databaseLogin); 181 databasePassword = getProperty("db_password"); 182 System.out.println("Password : " + databasePassword); 183 184 System.out.println(); 185 System.out.println("### General information ###"); 186 traceFile = getProperty("trace_file"); 187 System.out.println("Trace file : " + traceFile); 188 nbRequests = new Integer (getProperty("nb_requests")).intValue(); 189 System.out.println("Number of requests : " + nbRequests); 190 timeout = new Integer (getProperty("timeout")).intValue(); 191 System.out.println("Timeout on requests : " + timeout + " seconds"); 192 nbClients = new Integer (getProperty("nb_clients")).intValue(); 193 194 System.out.println("Number of clients : " + nbClients); 195 String connType = getProperty("connection_type"); 196 System.out.println("Connection type : " + connType); 197 if (connType.equalsIgnoreCase("fixed")) 198 connectionType = FIXED_CONNECTION; 199 else if (connType.equalsIgnoreCase("standard")) 200 connectionType = STANDARD_CONNECTION; 201 else if (connType.equalsIgnoreCase("pooling")) 202 { 203 connectionType = POOLING_CONNECTION; 204 poolSize = new Integer (getProperty("poolsize")).intValue(); 205 System.out.println("Connection pool size: " + poolSize); 206 } 207 208 return true; 209 } 210 catch (Exception e) 211 { 212 System.err.println( 213 "Error while checking request player properties file '" 214 + configFile.toString() 215 + "': " 216 + e.getMessage()); 217 return false; 218 } 219 } 220 221 226 public String getTraceFile() 227 { 228 return traceFile; 229 } 230 231 237 public int getNbRequests() 238 { 239 return nbRequests; 240 } 241 242 247 public String getDatabaseURL() 248 { 249 return databaseUrl; 250 } 251 252 257 public String getDatabaseDriver() 258 { 259 return databaseDriver; 260 } 261 262 267 public String getDatabaseUsername() 268 { 269 return databaseLogin; 270 } 271 272 277 public String getDatabasePassword() 278 { 279 return databasePassword; 280 } 281 282 287 public int getNbClients() 288 { 289 return nbClients; 290 } 291 292 297 public int getConnectionType() 298 { 299 return connectionType; 300 } 301 302 307 public int getPoolSize() 308 { 309 return poolSize; 310 } 311 312 317 public int getTimeout() 318 { 319 return timeout; 320 } 321 } 322 | Popular Tags |