use of build.buildfarm.common.TreeIterator.DirectoryEntry in project bazel-buildfarm by bazelbuild.
the class ShardInstance method getTreeFuture.
@Override
protected ListenableFuture<Tree> getTreeFuture(String reason, Digest inputRoot, ExecutorService service, RequestMetadata requestMetadata) {
SettableFuture<Void> future = SettableFuture.create();
Tree.Builder tree = Tree.newBuilder().setRootDigest(inputRoot);
Set<Digest> digests = Sets.newConcurrentHashSet();
Queue<Digest> remaining = new ConcurrentLinkedQueue();
remaining.offer(inputRoot);
Context ctx = Context.current();
TreeCallback callback = new TreeCallback(future) {
@Override
protected void onDirectory(Digest digest, Directory directory) {
tree.putDirectories(digest.getHash(), directory);
for (DirectoryNode childNode : directory.getDirectoriesList()) {
Digest child = childNode.getDigest();
if (digests.add(child)) {
remaining.offer(child);
}
}
}
@Override
boolean next() {
Digest nextDigest = remaining.poll();
if (!future.isDone() && nextDigest != null) {
ctx.run(() -> addCallback(transform(expectDirectory(reason, nextDigest, requestMetadata), directory -> new DirectoryEntry(nextDigest, directory), service), this, service));
return true;
}
return false;
}
};
callback.next();
return transform(future, (result) -> tree.build(), service);
}
use of build.buildfarm.common.TreeIterator.DirectoryEntry in project bazel-buildfarm by bazelbuild.
the class AbstractServerInstance method getTree.
@Override
public String getTree(Digest rootDigest, int pageSize, String pageToken, Tree.Builder tree) {
tree.setRootDigest(rootDigest);
if (pageSize == 0) {
pageSize = getTreeDefaultPageSize();
}
if (pageSize >= 0 && pageSize > getTreeMaxPageSize()) {
pageSize = getTreeMaxPageSize();
}
TokenizableIterator<DirectoryEntry> iter = createTreeIterator("getTree", rootDigest, pageToken);
while (iter.hasNext() && pageSize != 0) {
DirectoryEntry entry = iter.next();
Directory directory = entry.getDirectory();
// portion present and omit the rest.
if (directory != null) {
tree.putDirectories(entry.getDigest().getHash(), directory);
if (pageSize > 0) {
pageSize--;
}
}
}
return iter.toNextPageToken();
}
use of build.buildfarm.common.TreeIterator.DirectoryEntry in project bazel-buildfarm by bazelbuild.
the class AbstractServerInstance method getTreeFuture.
protected ListenableFuture<Tree> getTreeFuture(String reason, Digest inputRoot, ExecutorService service, RequestMetadata requestMetadata) {
return listeningDecorator(service).submit(() -> {
Tree.Builder tree = Tree.newBuilder().setRootDigest(inputRoot);
TokenizableIterator<DirectoryEntry> iterator = createTreeIterator(reason, inputRoot, /* pageToken=*/
"");
while (iterator.hasNext()) {
DirectoryEntry entry = iterator.next();
Directory directory = entry.getDirectory();
if (directory != null) {
tree.putDirectories(entry.getDigest().getHash(), directory);
}
}
return tree.build();
});
}
Aggregations