GridGain™ 4.3.1e
Enterprise "Big Data" Edition

org.gridgain.grid.lang.utils
Class GridCloseableIteratorAdapter<T>

java.lang.Object
  extended by org.gridgain.grid.lang.GridIteratorAdapter<T>
      extended by org.gridgain.grid.lang.utils.GridCloseableIteratorAdapter<T>
All Implemented Interfaces:
Serializable, Iterable<T>, Iterator<T>, GridCloseableIterator<T>, GridIterator<T>, GridSerializableIterator<T>

public abstract class GridCloseableIteratorAdapter<T>
extends GridIteratorAdapter<T>
implements GridCloseableIterator<T>

Convenient adapter for closeable iterator.

See Also:
Serialized Form
 

Constructor Summary
GridCloseableIteratorAdapter()
           
 
Method Summary
protected  void checkClosed()
          Throws NoSuchElementException if iterator has been closed.
 void close()
          Closes the iterator and frees all the resources held by the iterator.
 boolean hasNextX()
          This method is the same as Iterator.hasNext(), but allows for failure with exception.
 boolean isClosed()
          Checks if iterator has been closed.
 T nextX()
          This method is the same as Iterator.next(), but allows for failure with exception.
protected  void onClose()
          Invoked on iterator close.
protected abstract  boolean onHasNext()
           
protected abstract  T onNext()
           
protected  void onRemove()
          Called on remove from iterator.
 void removeX()
          This method is the same as Iterator.remove(), but allows for failure with exception.
 
Methods inherited from class org.gridgain.grid.lang.GridIteratorAdapter
hasNext, iterator, next, remove
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.lang.Iterable
iterator
 
Methods inherited from interface java.util.Iterator
hasNext, next, remove
 

Constructor Detail

GridCloseableIteratorAdapter

public GridCloseableIteratorAdapter()
Method Detail

nextX

public final T nextX()
              throws GridException
This method is the same as Iterator.next(), but allows for failure with exception. Often iterators are used to iterate through values that have not or have partially been received from remote nodes, and need to account for possible network failures, rather than throwing NoSuchElementException runtime exception.s

Specified by:
nextX in interface GridIterator<T>
Throws:
GridException - If no more elements can be returned due to some failure, like a network error for example.
Returns:
True if iterator contains more elements.
See Also:
Iterator.next()

onNext

protected abstract T onNext()
                     throws GridException
Throws:
GridException - If failed.
NoSuchElementException - If no element found.
Returns:
Next element.

hasNextX

public final boolean hasNextX()
                       throws GridException
This method is the same as Iterator.hasNext(), but allows for failure with exception. Often iterators are used to iterate through values that have not or have partially been received from remote nodes, and need to account for possible network failures, rather than just returning false out of Iterator.hasNext() method.

Specified by:
hasNextX in interface GridIterator<T>
Throws:
GridException - If no more elements can be returned due to some failure, like a network error for example.
Returns:
True if iterator contains more elements.
See Also:
Iterator.hasNext()

onHasNext

protected abstract boolean onHasNext()
                              throws GridException
Throws:
GridException - If failed.
Returns:
True if iterator has next element.

removeX

public final void removeX()
                   throws GridException
This method is the same as Iterator.remove(), but allows for failure with exception.

Specified by:
removeX in interface GridIterator<T>
Throws:
GridException - If failed.

onRemove

protected void onRemove()
                 throws GridException
Called on remove from iterator.

Throws:
GridException - If failed.

close

public final void close()
                 throws GridException
Closes the iterator and frees all the resources held by the iterator. Iterator can not be used any more after calling this method.

Specified by:
close in interface GridCloseableIterator<T>
Throws:
GridException - In case of error.

isClosed

public boolean isClosed()
Checks if iterator has been closed.

Specified by:
isClosed in interface GridCloseableIterator<T>
Returns:
True if iterator has been closed.

onClose

protected void onClose()
                throws GridException
Invoked on iterator close.

Throws:
GridException - If closing failed.

checkClosed

protected final void checkClosed()
                          throws NoSuchElementException
Throws NoSuchElementException if iterator has been closed.

Throws:
NoSuchElementException - If iterator has already been closed.

GridGain™ 4.3.1e
Enterprise "Big Data" Edition

GridGain - In-Memory Big Data
Enterprise "Big Data" Edition, ver. 4.3.1e.10112012
2012 Copyright © GridGain Systems
Follow us:   Follow GridGain on Github Join GridGain User Group Follow GridGain on Twitter Follow GridGain on Vimeo