64 |
|
} |
65 |
|
|
66 |
|
public boolean isCancelled() { |
67 |
< |
return sync.doIsCancelled(); |
67 |
> |
return sync.innerIsCancelled(); |
68 |
|
} |
69 |
|
|
70 |
|
public boolean isDone() { |
71 |
< |
return sync.doIsDone(); |
71 |
> |
return sync.innerIsDone(); |
72 |
|
} |
73 |
|
|
74 |
|
public boolean cancel(boolean mayInterruptIfRunning) { |
75 |
< |
return sync.doCancel(mayInterruptIfRunning); |
75 |
> |
return sync.innerCancel(mayInterruptIfRunning); |
76 |
|
} |
77 |
|
|
78 |
|
/** |
88 |
|
* while waiting |
89 |
|
*/ |
90 |
|
public V get() throws InterruptedException, ExecutionException { |
91 |
< |
return sync.doGet(); |
91 |
> |
return sync.innerGet(); |
92 |
|
} |
93 |
|
|
94 |
|
/** |
108 |
|
*/ |
109 |
|
public V get(long timeout, TimeUnit unit) |
110 |
|
throws InterruptedException, ExecutionException, TimeoutException { |
111 |
< |
return sync.doGet(unit.toNanos(timeout)); |
111 |
> |
return sync.innerGet(unit.toNanos(timeout)); |
112 |
|
} |
113 |
|
|
114 |
|
/** |
128 |
|
* @param v the value |
129 |
|
*/ |
130 |
|
protected void set(V v) { |
131 |
< |
sync.doSet(v); |
131 |
> |
sync.innerSet(v); |
132 |
|
} |
133 |
|
|
134 |
|
/** |
138 |
|
* @param t the cause of failure. |
139 |
|
*/ |
140 |
|
protected void setException(Throwable t) { |
141 |
< |
sync.doSetException(t); |
141 |
> |
sync.innerSetException(t); |
142 |
|
} |
143 |
|
|
144 |
|
/** |
146 |
|
* it has been cancelled. |
147 |
|
*/ |
148 |
|
public void run() { |
149 |
< |
sync.doRun(); |
149 |
> |
sync.innerRun(); |
150 |
|
} |
151 |
|
|
152 |
|
/** |
158 |
|
* @return true if successfully run and reset |
159 |
|
*/ |
160 |
|
protected boolean runAndReset() { |
161 |
< |
return sync.doRunAndReset(); |
161 |
> |
return sync.innerRunAndReset(); |
162 |
|
} |
163 |
|
|
164 |
|
/** |
165 |
|
* Synchronization control for FutureTask. Note that this must be |
166 |
|
* a non-static inner class in order to invoke protected |
167 |
|
* <tt>done</tt> method. For clarity, all inner class support |
168 |
< |
* methods are same as outer, prefixed with "do". |
168 |
> |
* methods are same as outer, prefixed with "inner". |
169 |
|
* |
170 |
|
* Uses AQS sync state to represent run status |
171 |
|
*/ |
203 |
|
* Implements AQS base acquire to succeed if ran or cancelled |
204 |
|
*/ |
205 |
|
protected int tryAcquireShared(int ignore) { |
206 |
< |
return doIsDone()? 1 : -1; |
206 |
> |
return innerIsDone()? 1 : -1; |
207 |
|
} |
208 |
|
|
209 |
|
/** |
215 |
|
return true; |
216 |
|
} |
217 |
|
|
218 |
< |
boolean doIsCancelled() { |
218 |
> |
boolean innerIsCancelled() { |
219 |
|
return getState() == CANCELLED; |
220 |
|
} |
221 |
|
|
222 |
< |
boolean doIsDone() { |
222 |
> |
boolean innerIsDone() { |
223 |
|
return ranOrCancelled(getState()) && runner == null; |
224 |
|
} |
225 |
|
|
226 |
< |
V doGet() throws InterruptedException, ExecutionException { |
226 |
> |
V innerGet() throws InterruptedException, ExecutionException { |
227 |
|
acquireSharedInterruptibly(0); |
228 |
|
if (getState() == CANCELLED) |
229 |
|
throw new CancellationException(); |
232 |
|
return result; |
233 |
|
} |
234 |
|
|
235 |
< |
V doGet(long nanosTimeout) throws InterruptedException, ExecutionException, TimeoutException { |
236 |
< |
if (!acquireSharedTimed(0, nanosTimeout)) |
235 |
> |
V innerGet(long nanosTimeout) throws InterruptedException, ExecutionException, TimeoutException { |
236 |
> |
if (!acquireSharedNanos(0, nanosTimeout)) |
237 |
|
throw new TimeoutException(); |
238 |
|
if (getState() == CANCELLED) |
239 |
|
throw new CancellationException(); |
242 |
|
return result; |
243 |
|
} |
244 |
|
|
245 |
< |
void doSet(V v) { |
245 |
> |
void innerSet(V v) { |
246 |
|
int s = getState(); |
247 |
|
if (ranOrCancelled(s) || !compareAndSetState(s, RAN)) |
248 |
|
return; |
251 |
|
done(); |
252 |
|
} |
253 |
|
|
254 |
< |
void doSetException(Throwable t) { |
254 |
> |
void innerSetException(Throwable t) { |
255 |
|
int s = getState(); |
256 |
|
if (ranOrCancelled(s) || !compareAndSetState(s, RAN)) |
257 |
|
return; |
261 |
|
done(); |
262 |
|
} |
263 |
|
|
264 |
< |
boolean doCancel(boolean mayInterruptIfRunning) { |
264 |
> |
boolean innerCancel(boolean mayInterruptIfRunning) { |
265 |
|
int s = getState(); |
266 |
|
if (ranOrCancelled(s) || !compareAndSetState(s, CANCELLED)) |
267 |
|
return false; |
275 |
|
return true; |
276 |
|
} |
277 |
|
|
278 |
< |
void doRun() { |
278 |
> |
void innerRun() { |
279 |
|
if (!compareAndSetState(0, RUNNING)) |
280 |
|
return; |
281 |
|
try { |
282 |
|
runner = Thread.currentThread(); |
283 |
< |
doSet(callable.call()); |
283 |
> |
innerSet(callable.call()); |
284 |
|
} catch(Throwable ex) { |
285 |
< |
doSetException(ex); |
285 |
> |
innerSetException(ex); |
286 |
|
} |
287 |
|
} |
288 |
|
|
289 |
< |
boolean doRunAndReset() { |
289 |
> |
boolean innerRunAndReset() { |
290 |
|
if (!compareAndSetState(0, RUNNING)) |
291 |
|
return false; |
292 |
|
try { |
295 |
|
runner = null; |
296 |
|
return compareAndSetState(RUNNING, 0); |
297 |
|
} catch(Throwable ex) { |
298 |
< |
doSetException(ex); |
298 |
> |
innerSetException(ex); |
299 |
|
return false; |
300 |
|
} |
301 |
|
} |