add tryWait for FutureCompletion
@@ -54,11 +54,7 @@ public class FutureCompletion extends Completion {
return;
}
- try {
- wait(timeout);
- } catch (InterruptedException e) {
- throw new CloudRuntimeException(e);
- }
+ doWait(timeout);
if (!done) {
this.timeout = true;
@@ -69,6 +65,28 @@ public class FutureCompletion extends Completion {
}
}
+ public synchronized boolean tryWait(long timeout) {
+ if (done) {
+ return done;
+ }
+
+ doWait(timeout);
+
+ if (!done) {
+ this.timeout = true;
+ }
+
+ return done;
+ }
+
+ private void doWait(long timeout) {
+ try {
+ wait(timeout);
+ } catch (InterruptedException e) {
+ throw new CloudRuntimeException(e);
+ }
+ }
+
public synchronized void await() {
if (done) {
return;
