1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.commons.jelly.tags.threads; |
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
public class RunnableStatus { |
26 |
|
public static final int NONE = 0; |
27 |
|
public static final int SUCCESS = 1; |
28 |
|
public static final int FAILURE = 2; |
29 |
|
public static final int AVOIDED = 3; |
30 |
|
public static final int TIMED_OUT = 4; |
31 |
|
public static final int KILLED = 5; |
32 |
|
|
33 |
76 |
private int status = NONE; |
34 |
|
|
35 |
|
|
36 |
76 |
private Exception exception = null; |
37 |
|
|
38 |
76 |
public RunnableStatus() { |
39 |
|
|
40 |
76 |
} |
41 |
|
|
42 |
0 |
public RunnableStatus(int status) { |
43 |
0 |
set(status); |
44 |
0 |
} |
45 |
|
|
46 |
|
public synchronized void set(int status) { |
47 |
32 |
set(status, null); |
48 |
32 |
} |
49 |
|
|
50 |
|
public synchronized void set(int status, Exception e) { |
51 |
|
|
52 |
|
|
53 |
34 |
if (this.status != status) { |
54 |
34 |
this.status = status; |
55 |
|
|
56 |
|
|
57 |
34 |
if (e != null) |
58 |
2 |
this.exception = e; |
59 |
|
} |
60 |
34 |
} |
61 |
|
|
62 |
|
public synchronized int get() { |
63 |
0 |
return status; |
64 |
|
} |
65 |
|
|
66 |
|
public synchronized boolean isSuccess() { |
67 |
0 |
return (status == SUCCESS); |
68 |
|
} |
69 |
|
|
70 |
|
public synchronized boolean isFailure() { |
71 |
0 |
return (status == FAILURE); |
72 |
|
} |
73 |
|
|
74 |
|
public synchronized boolean isAvoided() { |
75 |
0 |
return (status == AVOIDED); |
76 |
|
} |
77 |
|
|
78 |
|
public synchronized boolean isTimedOut() { |
79 |
0 |
return (status == TIMED_OUT); |
80 |
|
} |
81 |
|
|
82 |
|
public synchronized boolean isKilled() { |
83 |
0 |
return (status == KILLED); |
84 |
|
} |
85 |
|
|
86 |
|
public synchronized Exception getException() { |
87 |
0 |
return exception; |
88 |
|
} |
89 |
|
|
90 |
|
public synchronized boolean equals(RunnableStatus status) { |
91 |
0 |
return status.get() == this.status; |
92 |
|
} |
93 |
|
|
94 |
|
public synchronized boolean equals(int status) { |
95 |
6 |
return this.status == status; |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
public static int getStatusCode(String status) { |
105 |
6 |
if (status.equalsIgnoreCase("SUCCESS")) { |
106 |
2 |
return SUCCESS; |
107 |
4 |
} else if (status.equalsIgnoreCase("FAILURE")) { |
108 |
2 |
return FAILURE; |
109 |
2 |
} else if (status.equalsIgnoreCase("TIMED_OUT")) { |
110 |
0 |
return TIMED_OUT; |
111 |
2 |
} else if (status.equalsIgnoreCase("AVOIDED")) { |
112 |
2 |
return AVOIDED; |
113 |
0 |
} else if (status.equalsIgnoreCase("KILLED")) { |
114 |
0 |
return KILLED; |
115 |
|
} else { |
116 |
0 |
throw new IllegalArgumentException(status + " is invalid status"); |
117 |
|
} |
118 |
|
} |
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
public static String getStatusString(int status) { |
124 |
0 |
if (status == SUCCESS) { |
125 |
0 |
return "SUCCESS"; |
126 |
0 |
} else if (status == FAILURE) { |
127 |
0 |
return "FAILURE"; |
128 |
0 |
} else if (status == TIMED_OUT) { |
129 |
0 |
return "TIMED_OUT"; |
130 |
0 |
} else if (status == AVOIDED) { |
131 |
0 |
return "AVOIDED"; |
132 |
0 |
} else if (status == KILLED) { |
133 |
0 |
return "KILLED"; |
134 |
|
} else { |
135 |
0 |
throw new IllegalArgumentException(status + " is invalid status"); |
136 |
|
} |
137 |
|
} |
138 |
|
|
139 |
|
public static boolean isValidStatus(int status) { |
140 |
0 |
if (status == SUCCESS) { |
141 |
0 |
return true; |
142 |
0 |
} else if (status == FAILURE) { |
143 |
0 |
return true; |
144 |
0 |
} else if (status == TIMED_OUT) { |
145 |
0 |
return true; |
146 |
0 |
} else if (status == AVOIDED) { |
147 |
0 |
return true; |
148 |
0 |
} else if (status == KILLED) { |
149 |
0 |
return true; |
150 |
|
} else { |
151 |
0 |
return false; |
152 |
|
} |
153 |
|
} |
154 |
|
|
155 |
|
public String toString() { |
156 |
0 |
return getStatusString(status); |
157 |
|
} |
158 |
|
} |