Package wt.impact

Class WTChunkedIterator<T extends Persistable>

java.lang.Object
wt.impact.WTChunkedIterator<T>
All Implemented Interfaces:
AutoCloseable, Iterator<T>

public class WTChunkedIterator<T extends Persistable> extends Object implements Iterator<T>, AutoCloseable
WTCollection iterator that inflates and deflates object references in chunks. This iterator keeps memory usage low when iterating over large, deflated collections.

This iterator can only be used in the method server.

It is recommended that this iterator be used as resource in a try-with-resources block to ensure that inflated references are deflated if iteration terminates.

Examples:

 WTCollection objects;
     :
 // objects collection is created and populated with deflated references
     :
 try (WTChunkedIterator partIter = new WTChunkedIterator(objects, 1000, WTPart.class)) {
     while ( partIter.hasNext() ) {
         WTPart part = partIter.next();
             :
     }
 }
 // All references in the collection that were originally deflated will be 
 // automatically deflated when the try-with-resources block exits.
 // All references in the collection that were originally inflated will remain so.
     :
 
If a try-with-resources block is not used then close() should be called when the iterator is no longer needed:
 WTCollection objects;
     :
 // objects collection is populated with deflated references
     :
 WTChunkedIterator partIter = new WTChunkedIterator(objects, 1000, WTPart.class);
 while ( partIter.hasNext() ) {
    WTPart part = partIter.next();
             :
 }
 partIter.close(); // Deflate references.
     :
 


Supported API: true

Extendable: false
  • Constructor Details

    • WTChunkedIterator

      public WTChunkedIterator(WTCollection collection, int chunkSize)
      Construct a new WTChunkedIterator for all Persistable classes. Inflates objects in chunks to keep memory usage low.

      This iterator can only be used in the method server.

      Supported API: true

      Parameters:
      collection - Collection of deflated object references.
      chunkSize - Number of references that are inflated in a chunk.
    • WTChunkedIterator

      public WTChunkedIterator(WTCollection collection, int chunkSize, Class<T> filter)
      Construct a new WTChunkedIterator for a filter class and all sub-classes. Inflates objects in chunks to keep memory usage low.

      This iterator can only be used in the method server.

      Supported API: true

      Parameters:
      collection - Collection of deflated object references.
      chunkSize - Number of references that are inflated in a chunk.
      filter - Object class filter.
    • WTChunkedIterator

      public WTChunkedIterator(WTCollection collection, int chunkSize, Class<T> filter, boolean includeSubclasses)
      Construct a new WTChunkedIterator for a filter class. Inflates objects in chunks to keep memory usage low.

      This iterator can only be used in the method server.

      Supported API: true

      Parameters:
      collection - Collection of deflated object references.
      chunkSize - Number of references that are inflated in a chunk.
      filter - Object class filter.
      includeSubclasses - True to iterated over the filter objects and all of its sub-classes, or false to iterated over only the filter objects.
  • Method Details

    • close

      public void close()
      Deflate references and clear chunk collections. Called automatically if iterator is a resource in a try-with-resources block.

      Supported API: true
      Specified by:
      close in interface AutoCloseable
    • hasNext

      public boolean hasNext()


      Supported API: true
      Specified by:
      hasNext in interface Iterator<T extends Persistable>
      Throws:
      WTRuntimeException
    • next

      public T next()
      Returns the next Persistable object in the collection. Objects will be inflated and deflated in chunks within next() calls.

      Supported API: true
      Specified by:
      next in interface Iterator<T extends Persistable>
      Throws:
      NoSuchElementException