com.healthmarketscience.rmiio
Class AbstractCloseableIOIterator<DataType>

java.lang.Object
  extended by com.healthmarketscience.rmiio.AbstractCloseableIOIterator<DataType>
All Implemented Interfaces:
CloseableIOIterator<DataType>, IOIterator<DataType>, Closeable
Direct Known Subclasses:
ConverterIOIterator, IOIteratorPipe.Source, LineIterator

public abstract class AbstractCloseableIOIterator<DataType>
extends Object
implements CloseableIOIterator<DataType>

Convenience base class for CloseableIOIterator implementations, especially suited for use as the local iterator for a RemoteIteratorServer instance. This implementation manages the closing of the local resources through three separate mechanisms. The close() method will be called:

This three-pronged attack provides a pretty strong guarantee that the local resources will be closed at some point in time. Note that the implementation of the close() method will call the closeImpl() method at most once. Extraneous invocations will be ignored.

Author:
James Ahlborn

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.healthmarketscience.rmiio.CloseableIOIterator
CloseableIOIterator.Adapter<DataType>
 
Constructor Summary
AbstractCloseableIOIterator()
           
 
Method Summary
 void close()
           
protected abstract  void closeImpl()
          Does the actual closing of the local resources.
 DataType next()
          Returns the next element in the iteration.
protected abstract  DataType nextImpl()
          Does the actual work of the next() method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.healthmarketscience.rmiio.IOIterator
hasNext
 

Constructor Detail

AbstractCloseableIOIterator

public AbstractCloseableIOIterator()
Method Detail

next

public final DataType next()
                    throws IOException
Description copied from interface: IOIterator
Returns the next element in the iteration.

Specified by:
next in interface IOIterator<DataType>
Throws:
IOException

close

public final void close()
Specified by:
close in interface Closeable

nextImpl

protected abstract DataType nextImpl()
                              throws IOException
Does the actual work of the next() method. Will only be called if IOIterator.hasNext() is currently returning true.

Throws:
IOException

closeImpl

protected abstract void closeImpl()
Does the actual closing of the local resources. Will be called at most once by the close() method regardless of how many times that method is invoked.

Note, this method does not throw IOException because it can be called in a variety of different scenarios and throwing an IOException would be useless in many of them (and often, failure to close is merely a nuisance, not a cause for failure).



Copyright © 2006–2016 Health Market Science. All rights reserved.