Package htsjdk.samtools.util
Class AsyncBufferedIterator<T>
- java.lang.Object
-
- htsjdk.samtools.util.AsyncBufferedIterator<T>
-
- All Implemented Interfaces:
CloseableIterator<T>
,Closeable
,AutoCloseable
,Iterator<T>
public class AsyncBufferedIterator<T> extends Object implements CloseableIterator<T>
Iterator that uses a dedicated background thread to perform read-ahead to improve throughput at the expense of increased latency. This iterator will block until the background thread has read a full buffer of records. Note that this implementation is not synchronized. If multiple threads access an instance concurrently, it must be synchronized externally.
-
-
Constructor Summary
Constructors Constructor Description AsyncBufferedIterator(Iterator<T> iterator, int bufferSize)
Creates a new iterator that traverses the given iterator on a background threadAsyncBufferedIterator(Iterator<T> iterator, int bufferSize, int bufferCount)
Creates a new iterator that traverses the given iterator on a background threadAsyncBufferedIterator(Iterator<T> iterator, int bufferSize, int bufferCount, String threadName)
Creates a new iterator that traverses the given iterator on a background thread
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Should be implemented to close/release any underlying resources.protected String
getThreadNamePrefix()
boolean
hasNext()
T
next()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface htsjdk.samtools.util.CloseableIterator
stream, toList
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
Constructor Detail
-
AsyncBufferedIterator
public AsyncBufferedIterator(Iterator<T> iterator, int bufferSize)
Creates a new iterator that traverses the given iterator on a background thread- Parameters:
iterator
- iterator to traversebufferSize
- size of read-ahead buffer. A larger size will increase both throughput and latency. Double buffering is used so the maximum number of records on which read-ahead is performed is twice this.
-
AsyncBufferedIterator
public AsyncBufferedIterator(Iterator<T> iterator, int bufferSize, int bufferCount)
Creates a new iterator that traverses the given iterator on a background thread- Parameters:
iterator
- iterator to traversebufferSize
- size of each read-ahead buffer. A larger size will increase both throughput and latency.bufferCount
- number of read-ahead buffers
-
AsyncBufferedIterator
public AsyncBufferedIterator(Iterator<T> iterator, int bufferSize, int bufferCount, String threadName)
Creates a new iterator that traverses the given iterator on a background thread- Parameters:
iterator
- iterator to traversebufferSize
- size of each read-ahead buffer. A larger size will increase both throughput and latency.bufferCount
- number of read-ahead buffersthreadName
- background thread name. A name will be automatically generated if this parameter is null.
-
-
Method Detail
-
getThreadNamePrefix
protected String getThreadNamePrefix()
-
close
public void close()
Description copied from interface:CloseableIterator
Should be implemented to close/release any underlying resources.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceCloseableIterator<T>
-
-