Skip to content

Commit

Permalink
Refactor storage batches to use StorageBatchRequest and BatchResult
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Apr 22, 2016
1 parent e213176 commit 30fee0a
Show file tree
Hide file tree
Showing 18 changed files with 1,144 additions and 1,078 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@
import com.google.cloud.storage.Storage.BucketTargetOption;
import com.google.cloud.storage.spi.StorageRpc;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -609,19 +608,28 @@ public Blob get(String blob, BlobGetOption... options) {
* @throws StorageException upon failure
*/
public List<Blob> get(String blobName1, String blobName2, String... blobNames) {
BatchRequest.Builder batch = BatchRequest.builder();
batch.get(name(), blobName1);
batch.get(name(), blobName2);
for (String name : blobNames) {
batch.get(name(), name);
}
List<Blob> blobs = new ArrayList<>(blobNames.length);
BatchResponse response = storage.submit(batch.build());
for (BatchResponse.Result<Blob> result : response.gets()) {
BlobInfo blobInfo = result.get();
blobs.add(blobInfo != null ? new Blob(storage, new BlobInfo.BuilderImpl(blobInfo)) : null);
}
return Collections.unmodifiableList(blobs);
List<BlobId> blobIds = Lists.newArrayListWithCapacity(blobNames.length + 2);
blobIds.add(BlobId.of(name(), blobName1));
blobIds.add(BlobId.of(name(), blobName2));
for (String blobName : blobNames) {
blobIds.add(BlobId.of(name(), blobName));
}
return storage.get(blobIds);
}

/**
* Returns a list of requested blobs in this bucket. Blobs that do not exist are null.
*
* @param blobNames blobs to get
* @return an immutable list of {@code Blob} objects
* @throws StorageException upon failure
*/
public List<Blob> get(Iterable<String> blobNames) {
ImmutableList.Builder<BlobId> builder = ImmutableList.builder();
for (String blobName : blobNames) {
builder.add(BlobId.of(name(), blobName));
}
return storage.get(builder.build());
}

/**
Expand Down
Loading

0 comments on commit 30fee0a

Please sign in to comment.