public abstract class DDMThreadedReader extends java.lang.Object implements DDMReadCallback
DDMReadCallback
you can use when you want multiple
threads to simultaneously process data being read out of the same file and connection. The data is read by the main thread,
but the conversion is done by one or more processing threads. Subclass this class and implement the
process()
method to read record data off-thread from the main I/O thread.
This gives the performance advantage of streaming data from the server in parallel with processing said data.
It is important to note that using more than one thread will likely cause the records to be processed out-of-order.Constructor and Description |
---|
DDMThreadedReader(DDMRecordFormat format,
DDMFile file,
int numThreads)
Constructs a multi-threaded reader to process data being read from the specified file
using the specified record format.
|
Modifier and Type | Method and Description |
---|---|
void |
endOfFile(DDMCallbackEvent event)
Do not call this method directly; it is implemented for DDMConnection to call.
|
boolean |
isDone()
Indicates if end-of-file has been reached and our threads have been shutdown.
|
void |
newRecord(DDMCallbackEvent event,
DDMDataBuffer buffer)
Do not call this method directly; it is implemented for DDMConnection to call.
|
abstract void |
process(DDMRecordFormat format,
DDMDataBuffer dataBuffer)
Override this method with your own record processing logic.
|
void |
recordNotFound(DDMCallbackEvent event)
Do not call this method directly; it is implemented for DDMConnection to call.
|
public DDMThreadedReader(DDMRecordFormat format, DDMFile file, int numThreads)
format
- The record format to copy and give to each thread for it to pass to process()
.file
- The file being read.numThreads
- The number of threads to use. This number is capped by the number of buffers in the file object, so
that each thread always has at least one buffer to process, to avoid contention. Having more than one buffer per thread is fine.public final void newRecord(DDMCallbackEvent event, DDMDataBuffer buffer)
newRecord
in interface DDMReadCallback
public final void recordNotFound(DDMCallbackEvent event)
recordNotFound
in interface DDMReadCallback
public final void endOfFile(DDMCallbackEvent event)
endOfFile
in interface DDMReadCallback
public final boolean isDone()
public abstract void process(DDMRecordFormat format, DDMDataBuffer dataBuffer)