1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.http.nio.integration;
29
30 import java.util.Random;
31
32 @Deprecated
33 public class Job {
34
35 private static final Random RND = new Random();
36 private static final String TEST_CHARS = "0123456789ABCDEF";
37
38 private final int count;
39 private final String pattern;
40
41 private volatile boolean completed;
42 private volatile int statusCode;
43 private volatile String result;
44 private volatile String failureMessage;
45 private volatile Exception ex;
46
47 public Job(int maxCount) {
48 super();
49 this.count = RND.nextInt(maxCount - 1) + 1;
50 StringBuilder buffer = new StringBuilder();
51 for (int i = 0; i < 5; i++) {
52 char rndchar = TEST_CHARS.charAt(RND.nextInt(TEST_CHARS.length() - 1));
53 buffer.append(rndchar);
54 }
55 this.pattern = buffer.toString();
56 }
57
58 public Job() {
59 this(1000);
60 }
61
62 public Job(final String pattern, int count) {
63 super();
64 this.count = count;
65 this.pattern = pattern;
66 }
67
68 public int getCount() {
69 return this.count;
70 }
71
72 public String getPattern() {
73 return this.pattern;
74 }
75
76 public String getExpected() {
77 StringBuilder buffer = new StringBuilder();
78 for (int i = 0; i < this.count; i++) {
79 buffer.append(this.pattern);
80 }
81 return buffer.toString();
82 }
83
84 public int getStatusCode() {
85 return this.statusCode;
86 }
87
88 public String getResult() {
89 return this.result;
90 }
91
92 public boolean isSuccessful() {
93 return this.result != null;
94 }
95
96 public String getFailureMessage() {
97 return this.failureMessage;
98 }
99
100 public Exception getException() {
101 return this.ex;
102 }
103
104 public boolean isCompleted() {
105 return this.completed;
106 }
107
108 public synchronized void setResult(int statusCode, final String result) {
109 if (this.completed) {
110 return;
111 }
112 this.completed = true;
113 this.statusCode = statusCode;
114 this.result = result;
115 notifyAll();
116 }
117
118 public synchronized void fail(final String message, final Exception ex) {
119 if (this.completed) {
120 return;
121 }
122 this.completed = true;
123 this.result = null;
124 this.failureMessage = message;
125 this.ex = ex;
126 notifyAll();
127 }
128
129 public void fail(final String message) {
130 fail(message, null);
131 }
132
133 public synchronized void waitFor() throws InterruptedException {
134 while (!this.completed) {
135 wait();
136 }
137 }
138
139 }