com.devexperts.qd.util
Class SubscriptionProcessor

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

public abstract class SubscriptionProcessor
extends java.lang.Object

This class is base class for listening QD for subscription availability and rescheduling its processing using Executor. Classes which extends SubscriptionProcessor listen for subscription coming from QD and process incoming subscription in separate thread or threads.

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

SubscriptionProcessor registers SubscriptionListener in all SubscriptionProvider instances when startProcessing(com.devexperts.qd.QDDistributor) 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 SubscriptionProcessor(java.util.concurrent.Executor executor)
          Constructs new subscription processor for the specified executor.
protected SubscriptionProcessor(java.util.concurrent.Executor executor, QDDistributor distributor)
          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 SubscriptionProcessor(Executor) and call startProcessing(QDDistributor) method after construction.
protected SubscriptionProcessor(java.util.concurrent.Executor executor, SubscriptionProvider addedSubscriptionProvider, SubscriptionProvider removedSubscriptionProvider)
          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 SubscriptionProcessor(Executor) and call startProcessing(SubscriptionProvider, SubscriptionProvider) method after construction.
 
Method Summary
protected abstract  void processAddedSubscription(SubscriptionIterator iterator)
          Method for processing incoming added subscription from QD.
protected abstract  void processRemovedSubscription(SubscriptionIterator iterator)
          Method for processing incoming removed subscription from QD.
 void startProcessing(QDDistributor distributor)
          Starts subscription processing for the specified QDDistributor.
 void startProcessing(SubscriptionProvider addedSubscriptionProvider, SubscriptionProvider removedSubscriptionProvider)
          Starts subscription processing for the specified added and removed SubscriptionProvider instances.
 void stopProcessing()
          Stop subscription processing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SubscriptionProcessor

protected SubscriptionProcessor(java.util.concurrent.Executor executor,
                                QDDistributor distributor)
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 SubscriptionProcessor(Executor) and call startProcessing(QDDistributor) method after construction.

Construct new SubscriptionProcessor, register SubscriptionListeners on subscription providers in passed QDDistributors and start processing.

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

SubscriptionProcessor

protected SubscriptionProcessor(java.util.concurrent.Executor executor,
                                SubscriptionProvider addedSubscriptionProvider,
                                SubscriptionProvider removedSubscriptionProvider)
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 SubscriptionProcessor(Executor) and call startProcessing(SubscriptionProvider, SubscriptionProvider) method after construction.

Construct new SubscriptionProcessor, register SubscriptionListeners on passed SubscriptionProviders and start processing. This constructor accepts null for one of the subscription providers.

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

SubscriptionProcessor

protected SubscriptionProcessor(java.util.concurrent.Executor executor)
Constructs new subscription processor for the specified executor.

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

processAddedSubscription

protected abstract void processAddedSubscription(SubscriptionIterator iterator)
Method for processing incoming added subscription from QD. When added subscription is received, SubscriptionProcessor calls this method in Executor thread.


processRemovedSubscription

protected abstract void processRemovedSubscription(SubscriptionIterator iterator)
Method for processing incoming removed subscription from QD. When removed subscription is received, SubscriptionProcessor calls this method in Executor thread.


startProcessing

public void startProcessing(QDDistributor distributor)
Starts subscription processing for the specified QDDistributor. This method is equivalent to the following code: startProcessing(distributor.getAddedSubscriptionProvider(), distributor.getRemovedSubscriptionProvider()). This method or startProcessing(SubscriptionProvider, SubscriptionProvider) may be called at most once after construction.

Throws:
java.lang.NullPointerException - if distributor 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.

startProcessing

public void startProcessing(SubscriptionProvider addedSubscriptionProvider,
                            SubscriptionProvider removedSubscriptionProvider)
Starts subscription processing for the specified added and removed SubscriptionProvider instances. This method accepts null for one of the subscription providers. This method or startProcessing(QDDistributor) may be called at most once after construction.

Throws:
java.lang.NullPointerException - if both SubscriptionProvider arguments are 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()
Stop subscription processing. Unregisters SubscriptionListener instances from SubscriptionProvider instances. Note: client code is responsible for disposing SubscriptionProviders originally passed to SubscriptionProcessor.

Throws:
java.lang.IllegalStateException - if called before startProcessing(QDDistributor) or startProcessing(SubscriptionProvider, SubscriptionProvider).