com.healthmarketscience.rmiio
Class AbstractCloseableIOIterator<DataType>
java.lang.Object
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:
- by the
next() method when the IOIterator.hasNext() method starts
returning false
- when the close method is called directly (duh)
- if used with a RemoteIteratorServer, when the server is shutdown
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
|
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 |
AbstractCloseableIOIterator
public AbstractCloseableIOIterator()
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.