aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/concurrent/ForkJoinQuiescingExecutor.java
diff options
context:
space:
mode:
authorGravatar Nathan Harmata <nharmata@google.com>2016-09-20 16:32:01 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2016-09-21 07:06:40 +0000
commit07f6fcf8a88791aef887b05c79b907760b989ea9 (patch)
treed180cc46574a250bfcee7bd9d222123c13cd65ef /src/main/java/com/google/devtools/build/lib/concurrent/ForkJoinQuiescingExecutor.java
parentcc867d4b7a2a42188ba5ef5114dad2c2fab60351 (diff)
Introduce a Builder for ForkJoinQuiescingExecutor.
-- MOS_MIGRATED_REVID=133714902
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/concurrent/ForkJoinQuiescingExecutor.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/concurrent/ForkJoinQuiescingExecutor.java63
1 files changed, 61 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/concurrent/ForkJoinQuiescingExecutor.java b/src/main/java/com/google/devtools/build/lib/concurrent/ForkJoinQuiescingExecutor.java
index 45132a1cb7..b012ac18ef 100644
--- a/src/main/java/com/google/devtools/build/lib/concurrent/ForkJoinQuiescingExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/concurrent/ForkJoinQuiescingExecutor.java
@@ -13,6 +13,7 @@
// limitations under the License.
package com.google.devtools.build.lib.concurrent;
+import com.google.devtools.build.lib.util.Preconditions;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
@@ -23,15 +24,73 @@ import java.util.concurrent.ForkJoinTask;
// maintaining AQV.remainingTasks.
public class ForkJoinQuiescingExecutor extends AbstractQueueVisitor {
- public ForkJoinQuiescingExecutor(ForkJoinPool forkJoinPool, ErrorClassifier errorClassifier) {
+ private ForkJoinQuiescingExecutor(
+ ForkJoinPool forkJoinPool, ErrorClassifier errorClassifier, boolean shutdownOnCompletion) {
super(
/*concurrent=*/ true,
forkJoinPool,
- /*shutdownOnCompletion=*/ true,
+ shutdownOnCompletion,
/*failFastOnException=*/ true,
errorClassifier);
}
+ /** Builder for {@link ForkJoinQuiescingExecutor}. */
+ public static class Builder {
+ private ForkJoinPool forkJoinPool = null;
+ private boolean owned = false;
+ private ErrorClassifier errorClassifier = ErrorClassifier.DEFAULT;
+
+ private Builder() {
+ }
+
+ /**
+ * Sets the {@link ForkJoinPool} that will be used by the to-be-built
+ * {@link ForkJoinQuiescingExecutor}. The given {@link ForkJoinPool} will _not_ be shut down on
+ * completion of the {@link ForkJoinQuiescingExecutor}.
+ */
+ public Builder withoutOwnershipOf(ForkJoinPool forkJoinPool) {
+ Preconditions.checkState(this.forkJoinPool == null);
+ this.forkJoinPool = forkJoinPool;
+ this.owned = false;
+ return this;
+ }
+
+ /**
+ * Sets the {@link ForkJoinPool} that will be used by the to-be-built
+ * {@link ForkJoinQuiescingExecutor}. The given {@link ForkJoinPool} will be shut down on
+ * completion of the {@link ForkJoinQuiescingExecutor}.
+ */
+ public Builder withOwnershipOf(ForkJoinPool forkJoinPool) {
+ Preconditions.checkState(this.forkJoinPool == null);
+ this.forkJoinPool = forkJoinPool;
+ this.owned = true;
+ return this;
+ }
+
+ /**
+ * Sets the {@link ErrorClassifier} that will be used by the to-be-built
+ * {@link ForkJoinQuiescingExecutor}.
+ */
+ public Builder setErrorClassifier(ErrorClassifier errorClassifier) {
+ this.errorClassifier = errorClassifier;
+ return this;
+ }
+
+ /**
+ * Returns a fresh {@link ForkJoinQuiescingExecutor} using the previously given options.
+ */
+ public ForkJoinQuiescingExecutor build() {
+ Preconditions.checkNotNull(forkJoinPool);
+ return new ForkJoinQuiescingExecutor(
+ forkJoinPool, errorClassifier, /*shutdownOnCompletion=*/ owned);
+ }
+ }
+
+ /** Returns a fresh {@link Builder}. */
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
@Override
protected void executeRunnable(Runnable runnable) {
if (ForkJoinTask.inForkJoinPool()) {