Package htsjdk.samtools.util
Class AbstractAsyncWriter<T>
java.lang.Object
htsjdk.samtools.util.AbstractAsyncWriter<T>
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
AsyncFastqWriter
,AsyncVariantContextWriter
Abstract class that is designed to be extended and specialized to provide an asynchronous
wrapper around any kind of Writer class that takes an object and writes it out somehow.
NOTE: Objects of subclasses of this class are not intended to be shared between threads.
In particular there must be only one thread that calls
write(T)
and close()
.
NOTE: Any exception thrown by the underlying Writer will be propagated back to the caller
during the next available call to write(T)
or close()
. After the exception
has been thrown to the caller, it is not safe to attempt further operations on the instance.-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractAsyncWriter
(int queueSize) Creates an AbstractAsyncWriter that will use the provided WriterRunnable to consume from the internal queue and write records into the synchronous writer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Attempts to finish draining the queue and then calls synchronouslyClose() to allow implementation to do any one time clean up.protected abstract String
Returns the prefix to use when naming threads.protected abstract void
protected abstract void
synchronouslyWrite
(T item) void
Public method for sub-classes or ultimately consumers to put an item into the queue to be written out.
-
Field Details
-
DEFAULT_QUEUE_SIZE
public static final int DEFAULT_QUEUE_SIZE- See Also:
-
-
Constructor Details
-
AbstractAsyncWriter
protected AbstractAsyncWriter(int queueSize) Creates an AbstractAsyncWriter that will use the provided WriterRunnable to consume from the internal queue and write records into the synchronous writer.
-
-
Method Details
-
getThreadNamePrefix
Returns the prefix to use when naming threads. -
synchronouslyWrite
-
synchronouslyClose
protected abstract void synchronouslyClose() -
write
Public method for sub-classes or ultimately consumers to put an item into the queue to be written out. -
close
public void close()Attempts to finish draining the queue and then calls synchronouslyClose() to allow implementation to do any one time clean up.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-