ca.cbc.sportwire
Class DocQueue

java.lang.Object
  |
  +--ca.cbc.sportwire.DocQueue
All Implemented Interfaces:
java.lang.Runnable, WireFeederProperties

public class DocQueue
extends java.lang.Object
implements WireFeederProperties, java.lang.Runnable

FIFO DocQueue manages the received document text blocks, spawning processes to translate each to a DOM and stash it into the database. The number of worker processes can be tuned to balance speed with memory/CPU resources.

Properties:

Created: Wed Nov 14 12:18:35 2001

 $Log: DocQueue.java,v $
 Revision 1.10  2002/04/10 04:33:41  garym
 fixed CDATA bug in TSN; implemented external HTML filter

 Revision 1.9  2002/04/04 01:46:08  garym
 Skeletal translation of TSN to SportsML

 Revision 1.8  2002/03/23 19:46:41  garym
 lockup of the ESPN socket is driving me crazy

 Revision 1.7  2002/02/27 19:41:51  garym
 misc bugfixes to ESPN handling

 Revision 1.6  2002/02/25 18:47:24  garym
 Support for ESPN XML WireClient

 Revision 1.5  2001/11/21 01:18:44  garym
 Added log4j property file ; moved connection into the doc handler

 Revision 1.4  2001/11/20 18:35:35  garym
 Added XMLDBMS support (initial sketch)

 Revision 1.3  2001/11/15 04:49:31  garym
 removed ^Q in the XML and keep active until the queue is exhausted

 Revision 1.2  2001/11/14 20:26:44  garym
 implement dochandler interface

 Revision 1.1  2001/11/14 19:51:47  garym
 Implement the document queue; feed selected by properties


 

Version:
$Id: DocQueue.java,v 1.10 2002/04/10 04:33:41 garym Exp $
Author:
Gary Lawrence Murphy
See Also:
QueueElement

Field Summary
private static DocQueue _instance
           
(package private) static org.apache.log4j.Category cat
          Set up a reporting category in Log4J
private static int NUM_THREADS
           
private  java.util.LinkedList queue
           
private  boolean running
           
 
Fields inherited from interface ca.cbc.sportwire.WireFeederProperties
CONFIGFILE_DEFAULT, CONFIGFILE_PROPERTY, DEFAULT_FILENAME_XPATH, DEFAULT_SAX_DRIVER_CLASS, DEFAULT_XML_PATH, DEFAULT_XMLRPC_PORT, DOCHANDLER_DEFAULT, DOCHANDLER_PROPERTY, DOCWORKERS_DEFAULT, DOCWORKERS_PROPERTY, DTD_PATH_PROPERTY, FEED_REGEX_PROPERTY, FEEDCLASS_DEFAULT, FEEDCLASS_PROPERTY, FEEDFILTER_DEFAULT, FEEDFILTER_PROPERTY, FILENAME_XPATH_PROPERTY, IGNOREFILE_PROPERTY, LOGFILE_DEFAULT, LOGFILE_PROPERTY, MAP_PATH_PROPERTY, SAX_CLASS_PROPERTY, WATCHDOG_IDLE_DEFAULT, WATCHDOG_IDLE_PROPERTY, XML_PATH_PROPERTY, XMLRPC_PORT_PROPERTY, XSL_PATH_PROPERTY
 
Constructor Summary
DocQueue()
          DocQueue constructor sets the default number of worker threads as specified by DOCWORKERS_PROPERTY
DocQueue(int threads)
          DocQueue constructor sets the run-flag to true and fires up the worker threads.
 
Method Summary
private static java.lang.String docTag(java.lang.Object doc)
           
static DocQueue getInstance()
          getInstance returns the singleton instance; if you ever need a Sportwire with multiple queues, you'll need to modify/override this method.
 boolean isRunning()
          access the run-state flag.
private  void processDocument(QueueElement doc)
           
 void queueDoc(QueueElement doc)
          queueDoc adds an object to the end of the queue and notifies any waiting worker threads.
 void run()
          run implements a worker thread to process QueueElement objects off the queue; we'll throw a cast exception if the item is not a queue element.
 void setRunning(boolean v)
          If set to false, the worker process thread will stop on the next iteration
 int size()
          size: returns the current size of the underlying queue container.
private static int threadProp()
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

cat

static org.apache.log4j.Category cat
Set up a reporting category in Log4J

NUM_THREADS

private static final int NUM_THREADS

queue

private java.util.LinkedList queue

running

private boolean running

_instance

private static DocQueue _instance
Constructor Detail

DocQueue

public DocQueue()
DocQueue constructor sets the default number of worker threads as specified by DOCWORKERS_PROPERTY

DocQueue

public DocQueue(int threads)
DocQueue constructor sets the run-flag to true and fires up the worker threads.
Parameters:
threads - an int count of worker threads
Method Detail

isRunning

public boolean isRunning()
access the run-state flag.
Returns:
boolean value of running.

setRunning

public void setRunning(boolean v)
If set to false, the worker process thread will stop on the next iteration
Parameters:
v - Value to assign to running.

threadProp

private static int threadProp()

size

public int size()
size: returns the current size of the underlying queue container.
Returns:
an int value

queueDoc

public void queueDoc(QueueElement doc)
queueDoc adds an object to the end of the queue and notifies any waiting worker threads.
Parameters:
doc - an Object value

getInstance

public static DocQueue getInstance()
getInstance returns the singleton instance; if you ever need a Sportwire with multiple queues, you'll need to modify/override this method.
Returns:
the DocQueue object.

docTag

private static java.lang.String docTag(java.lang.Object doc)

processDocument

private void processDocument(QueueElement doc)

run

public void run()
run implements a worker thread to process QueueElement objects off the queue; we'll throw a cast exception if the item is not a queue element. The thread will extract the document handler and document contents from the QueueElement and pass the latter to the former's processDocument method. If the processing returns a non-null QueueElement, the new element is requeued.
Specified by:
run in interface java.lang.Runnable