com.devexperts.qd.util
Class DataProcessor

java.lang.Object
  extended by com.devexperts.qd.util.DataProcessor

public abstract class DataProcessor
extends java.lang.Object

This class is base class for listening QD for data availability and rescheduling its processing using Executor. Classes that extend DataProcessor listen for data coming from QD and process incoming data in separate thread or threads.

Executor may be single thread or thread pool executor. One Executor may be shared by different data processors. It is guaranteed that new data processing handler will not be called until previous has completed its work.

DataProcessor registers DataListener in DataProvider when startProcessing(DataProvider) startProcessing} method is called. Class client is responsible to call stopProcessing when processing is not required any more.

This class is thread-safe and lock-free. Change carefully.


Constructor Summary
protected DataProcessor(java.util.concurrent.Executor executor)
          Constructs new data processor for the specified executor.
protected DataProcessor(java.util.concurrent.Executor executor, DataProvider... dataProviders)
          Deprecated. Usage of this method can lead to NullPointerException or other problems in extending code, because this method starts processing and leaks this pointer to other threads (submits it to executor} right from inside constructor. Derived classes that initialize their fields (including final ones) in constructor may see default, non-initialized values of those fields. Use DataProcessor(Executor) and call startProcessing(DataProvider) method after construction. Use CompositeDataProvider class if you need support for multiple data providers.
 
Method Summary
protected abstract  void processData(RecordSource source)
          Method for processing incoming data from QD.
 void startProcessing(DataProvider provider)
          Starts data processing for the specified DataProvider.
 void stopProcessing()
          Stops data processing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataProcessor

protected DataProcessor(java.util.concurrent.Executor executor,
                        DataProvider... dataProviders)
Deprecated. Usage of this method can lead to NullPointerException or other problems in extending code, because this method starts processing and leaks this pointer to other threads (submits it to executor} right from inside constructor. Derived classes that initialize their fields (including final ones) in constructor may see default, non-initialized values of those fields. Use DataProcessor(Executor) and call startProcessing(DataProvider) method after construction. Use CompositeDataProvider class if you need support for multiple data providers.

Construct new DataProcessor, register DataListeners on passed DataProviders and start processing.

Throws:
java.lang.NullPointerException - if executor is null.

DataProcessor

protected DataProcessor(java.util.concurrent.Executor executor)
Constructs new data processor for the specified executor.

Throws:
java.lang.NullPointerException - if executor is null.
Method Detail

processData

protected abstract void processData(RecordSource source)
Method for processing incoming data from QD. When data is received, DataProcessor calls this method in Executor thread.


startProcessing

public void startProcessing(DataProvider provider)
Starts data processing for the specified DataProvider. This method may be called at most once after construction.

Throws:
java.lang.NullPointerException - if provider is null.
java.lang.IllegalStateException - if called multiple times. It is checked weakly to ensure fail-fast error detection behaviour. There is no strict thread-safe guarantee for this exception to be thrown if this method is called concurrently from multiple threads.

stopProcessing

public void stopProcessing()
Stops data processing. Unregisters DataListener on DataProvider. This method may be called only after startProcessing(DataProvider). Note: client code is responsible for disposing DataProvider originally passed to DataProcessor.

Throws:
java.lang.IllegalStateException - if called before startProcessing(DataProvider).