diff options
author | 2017-07-07 07:50:56 -0400 | |
---|---|---|
committer | 2017-07-07 13:37:26 -0400 | |
commit | 110484e6b1b8b60cf27ca53355dd7c690c308e11 (patch) | |
tree | a88f9ae06f00ef0adf8ba99e93d56533c60214e3 /src/main/java/com | |
parent | 70f84252a0f1669564ef3c92c4adeda9b5a22f50 (diff) |
remote: Add a SingleSourceBuilder to the Chunker.
Prepare the Chunker for an upcoming refactoring, where it will no longer
support multiple input sources and digest filtering.
RELNOTES: None.
PiperOrigin-RevId: 161189759
Diffstat (limited to 'src/main/java/com')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/remote/Chunker.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/remote/Chunker.java b/src/main/java/com/google/devtools/build/lib/remote/Chunker.java index 6b068bbaf2..d880f3f7c1 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/Chunker.java +++ b/src/main/java/com/google/devtools/build/lib/remote/Chunker.java @@ -14,6 +14,9 @@ package com.google.devtools.build.lib.remote; +import static com.google.devtools.build.lib.util.Preconditions.checkArgument; +import static com.google.devtools.build.lib.util.Preconditions.checkState; + import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; @@ -255,9 +258,53 @@ public final class Chunker { } /** + * Creates a Chunker from a single input source. + * + * <p>As we phase out usages of multiple input sources, this will soon completely replace the + * multiple inputs Builder. + */ + public static final class SingleSourceBuilder { + private Item item; + private int chunkSize = getDefaultChunkSize(); + + public SingleSourceBuilder chunkSize(int chunkSize) { + checkArgument(chunkSize > 0, "chunkSize must be gt 0."); + this.chunkSize = chunkSize; + return this; + } + + public SingleSourceBuilder input(byte[] blob) { + item = toItem(blob); + return this; + } + + public SingleSourceBuilder input(Path file) { + item = toItem(file); + return this; + } + + public SingleSourceBuilder input(ActionInput input, ActionInputFileCache inputCache, + Path execRoot) { + item = toItem(input, inputCache, execRoot); + return this; + } + + public Digest getDigest() throws IOException { + checkState(item != null, "Need to specify an input source first."); + return item.getDigest(); + } + + public Chunker build() throws IOException { + checkState(item != null, "No input source provided."); + return new Chunker(item, chunkSize); + } + } + + /** * Create a Chunker from multiple input sources. The order of the sources provided to the Builder * will be the same order they will be chunked by. */ + @Deprecated public static final class Builder { private final ImmutableList.Builder<Item> items = ImmutableList.builder(); private Set<Digest> digests = null; |