1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.performance;
19
20 import java.util.logging.Logger;
21
22
23
24
25 public class TesterClientThread extends ClientThread {
26
27
28
29
30
31
32
33 private final long minServiceDelay;
34 private final long maxServiceDelay;
35 private final double meanServiceDelay;
36 private final double sigmaServiceDelay;
37 private final String serviceDelayType;
38
39
40
41
42 private boolean initialized = false;
43 private boolean finalized = false;
44 private long setups = 0;
45 private long tearDowns = 0;
46
47
48 private boolean hurling = false;
49
50 public boolean isHurling() {
51 return hurling;
52 }
53
54 public void setHurling(boolean hurling) {
55 this.hurling = hurling;
56 }
57
58
59 protected void init() throws Exception {
60 initialized = true;
61 }
62
63
64 protected void setUp() throws Exception {
65 setups++;
66 }
67
68
69 protected void cleanUp() throws Exception {
70 tearDowns++;
71 }
72
73
74 protected void finish() throws Exception {
75 finalized = true;
76 }
77
78 public boolean isInitialized() {
79 return initialized;
80 }
81
82 public boolean isFinalized() {
83 return finalized;
84 }
85
86 public long getSetups() {
87 return setups;
88 }
89
90 public long getTearDowns() {
91 return tearDowns;
92 }
93
94 public TesterClientThread(long iterations, long minDelay, long maxDelay,
95 double sigma, String delayType, long rampPeriod, long peakPeriod,
96 long troughPeriod, String cycleType, String rampType,
97 Logger logger, Statistics stats, long minServiceDelay,
98 long maxServiceDelay, double meanServiceDelay,
99 double sigmaServiceDelay, String serviceDelayType) {
100
101 super(iterations, minDelay, maxDelay, sigma, delayType, rampPeriod,
102 peakPeriod, troughPeriod, cycleType, rampType, logger,
103 stats);
104 this.minServiceDelay = minServiceDelay;
105 this.maxServiceDelay = maxServiceDelay;
106 this.meanServiceDelay = meanServiceDelay;
107 this.sigmaServiceDelay = sigmaServiceDelay;
108 this.serviceDelayType = serviceDelayType;
109 }
110
111
112
113
114 public void execute() throws Exception {
115 if (hurling) {
116 throw new RuntimeException("Bang!");
117 }
118 if (meanServiceDelay <= 0) {
119 return;
120 }
121 if (serviceDelayType.equals("constant")) {
122 Thread.sleep(Math.round(meanServiceDelay));
123 } else if (serviceDelayType.equals("gaussian")) {
124 Thread.sleep(Math.round(randomData.nextGaussian(
125 meanServiceDelay, sigmaServiceDelay)));
126 } else if (serviceDelayType.equals("poisson")) {
127 Thread.sleep(Math.round(
128 randomData.nextPoisson(meanServiceDelay)));
129 }
130 else if (serviceDelayType.equals("uniform")) {
131 Thread.sleep(Math.round(
132 randomData.nextUniform(minServiceDelay, maxServiceDelay)));
133 }
134
135 }
136 }