Class Chunk<W>

All Implemented Interfaces:
Serializable, Iterable<W>

public class Chunk<W> extends Object implements Iterable<W>, Serializable
Encapsulation of a list of items to be processed and possibly a list of failed items to be skipped. To mark an item as skipped clients should iterate over the chunk using the iterator() method, and if there is a failure call Chunk.ChunkIterator.remove() on the iterator. The skipped items are then available through the chunk.
Dave Syer, Mahmoud Ben Hassine
See Also:
  • Constructor Details

    • Chunk

      public Chunk(W... items)
    • Chunk

      public Chunk(List<? extends W> items)
    • Chunk

      public Chunk(List<? extends W> items, List<SkipWrapper<W>> skips)
  • Method Details

    • of

      public static <W> Chunk<W> of(W... items)
    • add

      public void add(W item)
      Add the item to the chunk.
      item - the item to add
    • addAll

      public void addAll(List<W> items)
      Add all items to the chunk.
      items - the items to add
    • clear

      public void clear()
      Clear the items down to signal that we are done.
    • getItems

      public List<W> getItems()
      a copy of the items to be processed as an unmodifiable list
    • getSkips

      public List<SkipWrapper<W>> getSkips()
      a copy of the skips as an unmodifiable list
    • getErrors

      public List<Exception> getErrors()
      a copy of the anonymous errors as an unmodifiable list
    • skip

      public void skip(Exception e)
      Register an anonymous skip. To skip an individual item, use Chunk.ChunkIterator.remove().
      e - the exception that caused the skip
    • isEmpty

      public boolean isEmpty()
      true if there are no items in the chunk
    • iterator

      public Chunk<W>.ChunkIterator iterator()
      Get an unmodifiable iterator for the underlying items.
      Specified by:
      iterator in interface Iterable<W>
      See Also:
    • size

      public int size()
      the number of items (excluding skips)
    • isEnd

      public boolean isEnd()
      Flag to indicate if the source data is exhausted.
      true if there is no more data to process
    • setEnd

      public void setEnd()
      Set the flag to say that this chunk represents an end of stream (there is no more data to process).
    • isBusy

      public boolean isBusy()
      Query the chunk to see if anyone has registered an interest in keeping a reference to it.
      the busy flag
    • setBusy

      public void setBusy(boolean busy)
      Register an interest in the chunk to prevent it from being cleaned up before the flag is reset to false.
      busy - the flag to set
    • clearSkips

      public void clearSkips()
      Clear only the skips list.
    • getUserData

      public Object getUserData()
    • setUserData

      public void setUserData(Object userData)
    • toString

      public String toString()
      toString in class Object