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
public abstract class AbstractAsyncWriter<T> extends Object implements Closeable
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 callswrite(T)
andclose()
. NOTE: Any exception thrown by the underlying Writer will be propagated back to the caller during the next available call towrite(T)
orclose()
. After the exception has been thrown to the caller, it is not safe to attempt further operations on the instance.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_QUEUE_SIZE
-
Constructor Summary
Constructors Modifier Constructor Description 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 Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
close()
Attempts to finish draining the queue and then calls synchronouslyClose() to allow implementation to do any one time clean up.protected abstract String
getThreadNamePrefix()
Returns the prefix to use when naming threads.protected abstract void
synchronouslyClose()
protected abstract void
synchronouslyWrite(T item)
void
write(T item)
Public method for sub-classes or ultimately consumers to put an item into the queue to be written out.
-
-
-
Field Detail
-
DEFAULT_QUEUE_SIZE
public static final int DEFAULT_QUEUE_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getThreadNamePrefix
protected abstract String getThreadNamePrefix()
Returns the prefix to use when naming threads.
-
synchronouslyWrite
protected abstract void synchronouslyWrite(T item)
-
synchronouslyClose
protected abstract void synchronouslyClose()
-
write
public void write(T item)
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
-
-