org.apache.ignite.internal.util

## Class GridCloseableIteratorAdapterEx<T>

- java.lang.Object
- - org.apache.ignite.internal.util.lang.GridIteratorAdapter<T>
  - - org.apache.ignite.internal.util.GridCloseableIteratorAdapterEx<T>

All Implemented Interfaces:
  Serializable, AutoCloseable, Iterable<T>, Iterator<T>, GridSerializableIterator<T>, GridCloseableIterator<T>, GridIterator<T>, IgniteSpiCloseableIterator<T>

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

Adapter for closeable iterator that can be safely closed concurrently.

See Also:
  Serialized Form

### Constructor Summary

Constructors
Constructor and Description
`GridCloseableIteratorAdapterEx()`

### Method Summary

Methods
`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.apache.ignite.internal.util.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

#### GridCloseableIteratorAdapterEx

    public GridCloseableIteratorAdapterEx()

### Method Detail

#### nextX

    public final T nextX()
                  throws IgniteCheckedException

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>`
Returns:
  `True` if iterator contains more elements.
Throws:
  `IgniteCheckedException` - If no more elements can be returned due to some failure, like a network error for example.
See Also:
  `Iterator.next()`

#### onNext

    protected abstract T onNext()
                         throws IgniteCheckedException

Returns:
  Next element.
Throws:
  `IgniteCheckedException` - If failed.
  `NoSuchElementException` - If no element found.

#### hasNextX

    public final boolean hasNextX()
                           throws IgniteCheckedException

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>`
Returns:
  `True` if iterator contains more elements.
Throws:
  `IgniteCheckedException` - If no more elements can be returned due to some failure, like a network error for example.
See Also:
  `Iterator.hasNext()`

#### onHasNext

    protected abstract boolean onHasNext()
                                  throws IgniteCheckedException

Returns:
  `True` if iterator has next element.
Throws:
  `IgniteCheckedException` - If failed.

#### removeX

    public final void removeX()
                       throws IgniteCheckedException

This method is the same as `Iterator.remove()`, but allows for failure with exception.

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

#### onRemove

    protected void onRemove()
                     throws IgniteCheckedException

Called on remove from iterator.

Throws:
  `IgniteCheckedException` - If failed.

#### close

    public final void close()
                     throws IgniteCheckedException

Closes the iterator and frees all the resources held by the iterator. Iterator can not be used any more after calling this method.

The method is invoked automatically on objects managed by the `try-with-resources` statement.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `GridCloseableIterator<T>`
Specified by:
  `close` in interface `IgniteSpiCloseableIterator<T>`
Throws:
  `IgniteCheckedException` - In case of error.

#### onClose

    protected void onClose()
                    throws IgniteCheckedException

Invoked on iterator close.

Throws:
  `IgniteCheckedException` - If closing failed.

#### isClosed

    public boolean isClosed()

Checks if iterator has been closed.

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

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.7.0
Release Date | : August 1 2016