org.jclouds.collect
Class PagedIterable<E>

java.lang.Object
  extended by com.google.common.collect.FluentIterable<IterableWithMarker<E>>
      extended by org.jclouds.collect.PagedIterable<E>
All Implemented Interfaces:
Iterable<IterableWithMarker<E>>

@Beta
public abstract class PagedIterable<E>
extends com.google.common.collect.FluentIterable<IterableWithMarker<E>>

Extends FluentIterable allowing you to lazily advance through sequence of pages in a resultset. Typically used in apis that return only a certain number of records at a time. Simplest usage is to employ the concat() convenience function, and one of the methods from FluentIterable.

    // pull in new pages until it we see something interesting.
     Optional firstInterestingBlob = blobstore
         .list(// options //)
         .concat()
         .firstMatch(isInterestingBlob());
 
For those seeking manual control of page advances, don't use concat, and instead look at the value of IterableWithMarker#nextToken.
 PagedIterator blobs = blobstore.list(...).iterator();
 while (blobs.hasNext()) {
     IterableWithMarker page = blobs.next();
     ProcessedResults results = process(page);
     if (results.shouldBeBookmarked() && page.nextMarker().isPresent()) {
         saveBookmark(page.nextMarker().get());
     }
 }
 

Author:
Adrian Cole

Constructor Summary
PagedIterable()
           
 
Method Summary
 com.google.common.collect.FluentIterable<E> concat()
          Combines all the pages into a single unmodifiable iterable.
 
Methods inherited from class com.google.common.collect.FluentIterable
allMatch, anyMatch, contains, copyInto, cycle, filter, filter, first, firstMatch, from, from, get, index, isEmpty, last, limit, size, skip, toArray, toImmutableList, toImmutableSet, toImmutableSortedSet, toList, toMap, toSet, toSortedImmutableList, toSortedList, toSortedSet, toString, transform, transformAndConcat, uniqueIndex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.lang.Iterable
iterator
 

Constructor Detail

PagedIterable

public PagedIterable()
Method Detail

concat

public com.google.common.collect.FluentIterable<E> concat()
Combines all the pages into a single unmodifiable iterable. ex.
 FluentIterable blobs = blobstore.list(...).concat();
 for (StorageMetadata blob : blobs) {
     process(blob);
 }
 

See Also:
Iterators.concat(java.util.Iterator, java.util.Iterator)


Copyright © 2009-2013 jclouds. All Rights Reserved.