ca.cbc.sportwire.util
Class PeriodicData

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--ca.cbc.sportwire.util.PeriodicData
All Implemented Interfaces:
java.lang.Runnable, Stoppable
Direct Known Subclasses:
DBCacheBean, Lineup, TTLCacheMap

public abstract class PeriodicData
extends java.lang.Thread
implements Stoppable

PeriodicData.java: Base class for all periodically refreshed or expired data times. These objects have a timer thread which will invoke a refresh() method to rebuild or re-populate the object state.

This might be easier with the java.util.TimerTask class, except that we needed a means to free unscheduled events and there's no mention in the TimerTask pages if the cancel actually deletes the object; we'll leave this as an exercise for later.

Created: Wed Jan 2 13:37:13 2002
 $Log: PeriodicData.java,v $
 Revision 1.8  2002/02/13 19:18:08  garym
 fixed postgres workaround on numeric

 Revision 1.7  2002/02/11 07:09:25  garym
 TTL will now test for Stoppable instead of Periodic

 Revision 1.6  2002/01/24 19:49:25  garym
 added path search and debug statements

 Revision 1.5  2002/01/18 03:09:28  garym
 Extended unit tests for TTLCacheMap; implemented email unit test reports

 Revision 1.4  2002/01/16 23:09:25  garym
 Implemented the JDBC pool support and sql property beans

 Revision 1.3  2002/01/15 08:28:50  garym
 implemented MRU cache for the JDOMFile objects

 Revision 1.2  2002/01/14 21:51:46  garym
 bug fixes in topics and config files migration to Extended Properties

 Revision 1.1  2002/01/04 18:37:20  garym
 PeriodicData moved into sportwire.util package

 Revision 1.1  2002/01/03 03:36:25  garym
 Abstracted periodic-refresh data cache objects


 

Version:
$Id: PeriodicData.java,v 1.8 2002/02/13 19:18:08 garym Exp $
Author:
Gary Lawrence Murphy

Field Summary
(package private) static org.apache.log4j.Category cat
          Set up a reporting category in Log4J
private  int interval
           
private  boolean running
           
 
Fields inherited from class java.lang.Thread
contextClassLoader, daemon, eetop, group, inheritableThreadLocals, inheritedAccessControlContext, MAX_PRIORITY, MIN_PRIORITY, name, NORM_PRIORITY, priority, single_step, stillborn, stopThreadPermission, target, threadInitNumber, threadLocals, threadQ, userDaemon
 
Constructor Summary
PeriodicData()
          PeriodicData base constructor does nothing.
PeriodicData(int seconds)
          PeriodicData constructor accepting the interval as an integer seconds value
PeriodicData(java.lang.String secProp)
          PeriodicData constructor requires the string representation of the refresh rate; the refresh rate is typically provided by calling this constructor from a subclass with the refresh taken from a properties object such as super( properties.getProperty("refresh.sec", "30").
 
Method Summary
 void bump()
          bump: can be used to nudge any waiting access methods.
 boolean isRunning()
          Detect if the object is still live.
protected abstract  void refresh()
          refresh: abstract method invoked by the timer.
 void run()
          run implements the refresh timer; if the running flag is true, the refresh is run, then the thread pauses for interval seconds.
 void setInterval(int sec)
          setInterval: set the refresh interval for the periodic data item.
 void setRunning(boolean v)
          setRunning: can be set to false to terminate the thread.
 
Methods inherited from class java.lang.Thread
, activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, exit, getContextClassLoader, getName, getPriority, getThreadGroup, init, interrupt, interrupt0, interrupted, isAlive, isDaemon, isInterrupted, isInterrupted, join, join, join, nextThreadNum, registerNatives, resume, resume0, setContextClassLoader, setDaemon, setName, setPriority, setPriority0, sleep, sleep, start, stop, stop, stop0, suspend, suspend0, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cat

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

interval

private int interval

running

private boolean running
Constructor Detail

PeriodicData

public PeriodicData()
PeriodicData base constructor does nothing.

PeriodicData

public PeriodicData(java.lang.String secProp)
PeriodicData constructor requires the string representation of the refresh rate; the refresh rate is typically provided by calling this constructor from a subclass with the refresh taken from a properties object such as super( properties.getProperty("refresh.sec", "30"). Note: the constructor does not start the thread method. This allows subclasses to do more setup before the first refresh is called.
Parameters:
secProp - a String value

PeriodicData

public PeriodicData(int seconds)
PeriodicData constructor accepting the interval as an integer seconds value
Parameters:
seconds - an int value
Method Detail

refresh

protected abstract void refresh()
refresh: abstract method invoked by the timer.

setInterval

public void setInterval(int sec)
setInterval: set the refresh interval for the periodic data item.
Parameters:
sec - an int value

isRunning

public boolean isRunning()
Detect if the object is still live. Used internally to stop the refresh thread.
Specified by:
isRunning in interface Stoppable
Returns:
boolean value of running.

setRunning

public void setRunning(boolean v)
setRunning: can be set to false to terminate the thread.
Specified by:
setRunning in interface Stoppable
Parameters:
v - Value to assign to running.

bump

public void bump()
bump: can be used to nudge any waiting access methods. just locks the object and calls notifyAll()

run

public void run()
run implements the refresh timer; if the running flag is true, the refresh is run, then the thread pauses for interval seconds.
Overrides:
run in class java.lang.Thread