EMMA Coverage Report (generated Wed Jun 22 19:47:49 EDT 2011)
[all classes][org.jclouds.blobstore.strategy.internal]

COVERAGE SUMMARY FOR SOURCE FILE [ConcatenateContainerLists.java]

nameclass, %method, %block, %line, %
ConcatenateContainerLists.java100% (1/1)100% (2/2)74%  (49/66)81%  (13/16)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ConcatenateContainerLists100% (1/1)100% (2/2)74%  (49/66)81%  (13/16)
execute (String, ListContainerOptions): Iterable 100% (1/1)72%  (43/60)77%  (10/13)
ConcatenateContainerLists (BlobStore): void 100% (1/1)100% (6/6)100% (3/3)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.blobstore.strategy.internal;
20 
21import java.util.List;
22 
23import javax.inject.Singleton;
24 
25import org.jclouds.blobstore.BlobStore;
26import org.jclouds.blobstore.domain.PageSet;
27import org.jclouds.blobstore.domain.StorageMetadata;
28import org.jclouds.blobstore.internal.BlobRuntimeException;
29import org.jclouds.blobstore.options.ListContainerOptions;
30import org.jclouds.blobstore.options.ListContainerOptions.ImmutableListContainerOptions;
31import org.jclouds.blobstore.strategy.ListContainerStrategy;
32 
33import com.google.common.base.Throwables;
34import com.google.common.collect.Iterables;
35import com.google.common.collect.Lists;
36import com.google.inject.Inject;
37 
38/**
39 * Retrieves all metadata in the blobstore by the most efficient means possible.
40 * 
41 * @author Adrian Cole
42 */
43@Singleton
44public class ConcatenateContainerLists implements ListContainerStrategy {
45 
46   protected final BlobStore connection;
47 
48   @Inject
49   public ConcatenateContainerLists(BlobStore connection) {
50      this.connection = connection;
51   }
52 
53   @Override
54   public Iterable<? extends StorageMetadata> execute(String container, ListContainerOptions options) {
55      try {
56         boolean truncated = true;
57         List<PageSet<? extends StorageMetadata>> listings = Lists.newArrayList();
58         while (truncated) {
59            PageSet<? extends StorageMetadata> listing = connection.list(container, options);
60            truncated = listing.getNextMarker() != null;
61            if (truncated) {
62               options = options instanceof ImmutableListContainerOptions ? options.clone()
63                        .afterMarker(listing.getNextMarker()) : options.afterMarker(listing
64                        .getNextMarker());
65            }
66            listings.add(listing);
67         }
68         return Iterables.concat(listings);
69      } catch (Exception e) {
70         Throwables.propagateIfPossible(e, BlobRuntimeException.class);
71         throw new BlobRuntimeException("Error getting resource metadata in container: "
72                  + container, e);
73      }
74   }
75}

[all classes][org.jclouds.blobstore.strategy.internal]
EMMA 2.0.5312 (C) Vladimir Roubtsov