mirror of https://github.com/apache/jclouds.git
Merge pull request #597 from andrewgaul/simplify-transient-blobstore
Simplify transient blobstore logic
This commit is contained in:
commit
09e8ff1d8e
|
@ -27,8 +27,6 @@ import static com.google.common.collect.Iterables.filter;
|
||||||
import static com.google.common.collect.Iterables.find;
|
import static com.google.common.collect.Iterables.find;
|
||||||
import static com.google.common.collect.Iterables.size;
|
import static com.google.common.collect.Iterables.size;
|
||||||
import static com.google.common.collect.Iterables.transform;
|
import static com.google.common.collect.Iterables.transform;
|
||||||
import static com.google.common.collect.Lists.newArrayList;
|
|
||||||
import static com.google.common.collect.Lists.partition;
|
|
||||||
import static com.google.common.collect.Maps.newHashMap;
|
import static com.google.common.collect.Maps.newHashMap;
|
||||||
import static com.google.common.collect.Sets.filter;
|
import static com.google.common.collect.Sets.filter;
|
||||||
import static com.google.common.collect.Sets.newTreeSet;
|
import static com.google.common.collect.Sets.newTreeSet;
|
||||||
|
@ -179,13 +177,10 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
final String finalMarker = options.getMarker();
|
final String finalMarker = options.getMarker();
|
||||||
StorageMetadata lastMarkerMetadata = find(contents, new Predicate<StorageMetadata>() {
|
StorageMetadata lastMarkerMetadata = find(contents, new Predicate<StorageMetadata>() {
|
||||||
public boolean apply(StorageMetadata metadata) {
|
public boolean apply(StorageMetadata metadata) {
|
||||||
return metadata.getName().compareTo(finalMarker) >= 0;
|
return metadata.getName().compareTo(finalMarker) > 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
contents = contents.tailSet(lastMarkerMetadata);
|
contents = contents.tailSet(lastMarkerMetadata);
|
||||||
if (finalMarker.equals(lastMarkerMetadata.getName())) {
|
|
||||||
contents.remove(lastMarkerMetadata);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final String prefix = options.getDir();
|
final String prefix = options.getDir();
|
||||||
|
@ -198,26 +193,23 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
String marker = null;
|
String marker = null;
|
||||||
Integer maxResults = options.getMaxResults() != null ? options.getMaxResults() : 1000;
|
int maxResults = options.getMaxResults() != null ? options.getMaxResults() : 1000;
|
||||||
if (contents.size() > 0) {
|
if (!contents.isEmpty()) {
|
||||||
SortedSet<StorageMetadata> contentsSlice = firstSliceOfSize(contents, maxResults);
|
StorageMetadata lastElement = contents.last();
|
||||||
if (!contentsSlice.contains(contents.last())) {
|
contents = newTreeSet(Iterables.limit(contents, maxResults));
|
||||||
|
if (!contents.contains(lastElement)) {
|
||||||
// Partial listing
|
// Partial listing
|
||||||
marker = contentsSlice.last().getName();
|
marker = contents.last().getName();
|
||||||
} else {
|
|
||||||
marker = null;
|
|
||||||
}
|
}
|
||||||
contents = contentsSlice;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final String delimiter = options.isRecursive() ? null : "/";
|
final String delimiter = options.isRecursive() ? null : "/";
|
||||||
if (delimiter != null) {
|
if (delimiter != null) {
|
||||||
SortedSet<String> commonPrefixes = null;
|
SortedSet<String> commonPrefixes = newTreeSet(
|
||||||
Iterable<String> iterable = transform(contents, new CommonPrefixes(prefix != null ? prefix : null, delimiter));
|
transform(contents, new CommonPrefixes(prefix, delimiter)));
|
||||||
commonPrefixes = iterable != null ? newTreeSet(iterable) : new TreeSet<String>();
|
|
||||||
commonPrefixes.remove(CommonPrefixes.NO_PREFIX);
|
commonPrefixes.remove(CommonPrefixes.NO_PREFIX);
|
||||||
|
|
||||||
contents = newTreeSet(filter(contents, new DelimiterFilter(prefix != null ? prefix : null, delimiter)));
|
contents = newTreeSet(filter(contents, new DelimiterFilter(prefix, delimiter)));
|
||||||
|
|
||||||
Iterables.<StorageMetadata> addAll(contents, transform(commonPrefixes,
|
Iterables.<StorageMetadata> addAll(contents, transform(commonPrefixes,
|
||||||
new Function<String, StorageMetadata>() {
|
new Function<String, StorageMetadata>() {
|
||||||
|
@ -443,11 +435,6 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends Comparable<?>> SortedSet<T> firstSliceOfSize(Iterable<T> elements, int size) {
|
|
||||||
List<List<T>> slices = partition(newArrayList(elements), size);
|
|
||||||
return newTreeSet(slices.get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HttpResponseException returnResponseException(int code) {
|
public static HttpResponseException returnResponseException(int code) {
|
||||||
HttpResponse response = null;
|
HttpResponse response = null;
|
||||||
response = new HttpResponse(code, null, null);
|
response = new HttpResponse(code, null, null);
|
||||||
|
|
Loading…
Reference in New Issue