KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > performance > http > load > TestProperties


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tctest.performance.http.load;
5
6 import java.io.File JavaDoc;
7 import java.io.FileInputStream JavaDoc;
8 import java.util.Properties JavaDoc;
9
10 public class TestProperties {
11   static final String JavaDoc PROPERTIES_FILE = "http-load-client.properties";
12   static final String JavaDoc PROP_HOSTS = "hosts"; // comma delimited
13
static final String JavaDoc PROP_THREADS = "threads";
14   static final String JavaDoc PROP_STICKY_RATIO = "sticky-ratio";
15   static final String JavaDoc PROP_SESSIONS = "sessions";
16
17   private final int stickyRatio;
18   private final int sessionsCount;
19   private final String JavaDoc[] hosts;
20   private final int threadCount;
21
22   public TestProperties(File JavaDoc workingDir) {
23     this(workingDir.getAbsolutePath());
24   }
25
26   public TestProperties(String JavaDoc workingDir) {
27     Properties JavaDoc props = new Properties JavaDoc();
28     try {
29       props.load(new FileInputStream JavaDoc(workingDir + File.separator + PROPERTIES_FILE));
30     } catch (Exception JavaDoc e) {
31       e.printStackTrace();
32       throw new RuntimeException JavaDoc(e);
33     }
34     stickyRatio = toInt(props.getProperty(PROP_STICKY_RATIO, "100"), 100);
35     sessionsCount = toInt(props.getProperty(PROP_SESSIONS, "100"), 100);
36     hosts = props.getProperty(PROP_HOSTS, "http://127.0.0.1").split(",");
37     threadCount = toInt(props.getProperty(PROP_THREADS, "50"), 50);
38   }
39
40   public String JavaDoc[] getHosts() {
41     return hosts;
42   }
43
44   public int getSessionsCount() {
45     return sessionsCount;
46   }
47
48   public int getStickyRatio() {
49     return stickyRatio;
50   }
51
52   public int getThreadCount() {
53     return threadCount;
54   }
55   
56   private static int toInt(String JavaDoc v, int def) {
57     try {
58       return Integer.parseInt(v);
59     } catch (Exception JavaDoc e) {
60       return def;
61     }
62   }
63 }
64
Popular Tags