org.opensubsystems.core.util
Class AsyncProcessor

java.lang.Object
  extended by java.lang.Thread
      extended by org.opensubsystems.core.util.AsyncProcessor
All Implemented Interfaces:
java.lang.Runnable

public class AsyncProcessor
extends java.lang.Thread

Thread used to asynchronously process items added to the queue. The items are processesed in the order as the are added to the queue and the thread blocks if the queue is empty. The class, which wants to perform async data processing will usually inline derive new class and define method processIte. This class cannot be abstract so that we can do the in place overriding using anonymous classes.

Version:
$Id: AsyncProcessor.java,v 1.4 2007/01/07 06:14:00 bastafidli Exp $
Author:
Miro Halas
Code reviewer:
Miro Halas
Code reviewed:
1.2 2004/12/18 06:18:25 bastafidli

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  boolean m_bKeepRunning
          By setting this flag to false we can stop the thread.
protected  SynchronizedQueue m_syncQueue
          Synchronized queue use to keep data which should be processed asynchroneously.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AsyncProcessor(java.lang.String strName)
          Default constructor
 
Method Summary
 void processItemLater(java.lang.Object objItem)
          Add item to the queue to be processed later.
protected  void processItemNow(java.lang.Object objItem)
          Process item which was placed into the queue in processItemLater.
 void run()
          Method called during thread execution.
 void stopProcessing()
          Stop processing done by this thread as soon as possible
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_syncQueue

protected SynchronizedQueue m_syncQueue
Synchronized queue use to keep data which should be processed asynchroneously. It is also used to block the thread if there is nothing to process.


m_bKeepRunning

protected boolean m_bKeepRunning
By setting this flag to false we can stop the thread.

Constructor Detail

AsyncProcessor

public AsyncProcessor(java.lang.String strName)
Default constructor

Parameters:
strName - - name of this processor
Method Detail

run

public void run()
Method called during thread execution.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

stopProcessing

public void stopProcessing()
Stop processing done by this thread as soon as possible


processItemLater

public void processItemLater(java.lang.Object objItem)
Add item to the queue to be processed later. This method is called synchroneously, the item is put into the queue, the calling thread returns then the item is taken out of the queue by this thread and overriden processItemNow method is called to process it.

Parameters:
objItem - - item to process, this might be null if null was put into the queue

processItemNow

protected void processItemNow(java.lang.Object objItem)
                       throws OSSException
Process item which was placed into the queue in processItemLater. This method is called asynchroneously, the item is put into the queue, the calling thread returns then the item is taken out of the queue by this thread and this method is called to process it. This method cannot be abstract so that we can do the in place overriding of the class.

Parameters:
objItem - - item to process, this might be null if null was put into the queue
Throws:
OSSException - - an error has occured


Copyright © 2003 - 2006 OpenSubsystems s.r.o.