aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/shell
diff options
context:
space:
mode:
authorGravatar Janak Ramakrishnan <janakr@google.com>2016-08-22 14:09:18 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2016-08-22 14:49:01 +0000
commitb0848314531333d9673db32d9b22b3d413f15175 (patch)
tree2380a5ed9306f0b4ad12ebebe5de878bbaccd0de /src/main/java/com/google/devtools/build/lib/shell
parent9ea163005183c345d955e8a242f76bb3106c012e (diff)
Use guava Uninterruptibles#joinUninterruptibly utility method instead of rolling our own in Consumers.
-- MOS_MIGRATED_REVID=130936036
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/shell')
-rw-r--r--src/main/java/com/google/devtools/build/lib/shell/Consumers.java60
1 files changed, 23 insertions, 37 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/shell/Consumers.java b/src/main/java/com/google/devtools/build/lib/shell/Consumers.java
index 972bfa8004..47515d7d1f 100644
--- a/src/main/java/com/google/devtools/build/lib/shell/Consumers.java
+++ b/src/main/java/com/google/devtools/build/lib/shell/Consumers.java
@@ -13,6 +13,7 @@
// limitations under the License.
package com.google.devtools.build.lib.shell;
+import com.google.common.util.concurrent.Uninterruptibles;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
@@ -221,45 +222,30 @@ class Consumers {
@Override
public void waitForCompletion() throws IOException {
- boolean wasInterrupted = false;
try {
- while (true) {
- try {
- future.get();
- break;
- } catch (InterruptedException ie) {
- wasInterrupted = true;
- // continue waiting
- } catch (ExecutionException ee) {
- // Runnable threw a RuntimeException
- Throwable nested = ee.getCause();
- if (nested instanceof RuntimeException) {
- final RuntimeException re = (RuntimeException) nested;
- // The stream sink classes, unfortunately, tunnel IOExceptions
- // out of run() in a RuntimeException. If that's the case,
- // unpack and re-throw the IOException. Otherwise, re-throw
- // this unexpected RuntimeException
- final Throwable cause = re.getCause();
- if (cause instanceof IOException) {
- throw (IOException) cause;
- } else {
- throw re;
- }
- } else if (nested instanceof OutOfMemoryError) {
- // OutOfMemoryError does not support exception chaining.
- throw (OutOfMemoryError) nested;
- } else if (nested instanceof Error) {
- throw new Error("unhandled Error in worker thread", ee);
- } else {
- throw new RuntimeException("unknown execution problem", ee);
- }
+ Uninterruptibles.getUninterruptibly(future);
+ } catch (ExecutionException ee) {
+ // Runnable threw a RuntimeException
+ Throwable nested = ee.getCause();
+ if (nested instanceof RuntimeException) {
+ final RuntimeException re = (RuntimeException) nested;
+ // The stream sink classes, unfortunately, tunnel IOExceptions
+ // out of run() in a RuntimeException. If that's the case,
+ // unpack and re-throw the IOException. Otherwise, re-throw
+ // this unexpected RuntimeException
+ final Throwable cause = re.getCause();
+ if (cause instanceof IOException) {
+ throw (IOException) cause;
+ } else {
+ throw re;
}
- }
- } finally {
- // Read this for detailed explanation:
- // http://www.ibm.com/developerworks/java/library/j-jtp05236/
- if (wasInterrupted) {
- Thread.currentThread().interrupt(); // preserve interrupted status
+ } else if (nested instanceof OutOfMemoryError) {
+ // OutOfMemoryError does not support exception chaining.
+ throw (OutOfMemoryError) nested;
+ } else if (nested instanceof Error) {
+ throw new Error("unhandled Error in worker thread", ee);
+ } else {
+ throw new RuntimeException("unknown execution problem", ee);
}
}
}