com.ibm.jtopenlite.ddm
Class DDMThreadedReader

java.lang.Object
  extended by com.ibm.jtopenlite.ddm.DDMThreadedReader
All Implemented Interfaces:
DDMReadCallback

public abstract class DDMThreadedReader
extends Object
implements DDMReadCallback

A special kind of 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 Summary
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.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DDMThreadedReader

public 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.

Parameters:
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.
Method Detail

newRecord

public final void newRecord(DDMCallbackEvent event,
                            DDMDataBuffer buffer)
Do not call this method directly; it is implemented for DDMConnection to call.

Specified by:
newRecord in interface DDMReadCallback

recordNotFound

public final void recordNotFound(DDMCallbackEvent event)
Do not call this method directly; it is implemented for DDMConnection to call.

Specified by:
recordNotFound in interface DDMReadCallback

endOfFile

public final void endOfFile(DDMCallbackEvent event)
Do not call this method directly; it is implemented for DDMConnection to call.

Specified by:
endOfFile in interface DDMReadCallback

isDone

public final boolean isDone()
Indicates if end-of-file has been reached and our threads have been shutdown.


process

public abstract void process(DDMRecordFormat format,
                             DDMDataBuffer dataBuffer)
Override this method with your own record processing logic.