com.ecyrd.jspwiki.util
Class WikiBackgroundThread

java.lang.Object
  extended by java.lang.Thread
      extended by com.ecyrd.jspwiki.util.WikiBackgroundThread
All Implemented Interfaces:
WikiEventListener, Runnable
Direct Known Subclasses:
RSSThread

public abstract class WikiBackgroundThread
extends Thread
implements WikiEventListener

Abstract Theat class that operates in the background, and listens for the WikiEngineEvent.SHUTDOWN event to determine whether it still needs to run. Subclasses of this method need only implement the method backgroundTask() (instead of the normal Thread.run(), and provide a constructor that passes the WikiEngine and sleep interval.

Version:
$Revision: 1.1 $ $Date: 2006/06/17 23:19:40 $
Author:
Andrew Jaquith

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
WikiBackgroundThread(WikiEngine engine, int sleepInterval)
          Constructs a new instance of this background thread with a specified sleep interval, and adds the thread to the wiki engine's event listeners.
 
Method Summary
 void actionPerformed(WikiEvent event)
          Listens for WikiEngineEvent.SHUTDOWN and, if detected, marks the thread for death.
abstract  void backgroundTask()
          Abstract method that performs the actual work for this background thread;
 void run()
          Runs the background thread's backgroundTask() method at the interval specified by #getSleepInterval.
 void shutdownTask()
          Executes a task after shutdown signal was detected.
 void startupTask()
          Executes a task just after the thread's Thread.run() method starts, but before the backgroundTask() task executes.
 
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
 

Constructor Detail

WikiBackgroundThread

public WikiBackgroundThread(WikiEngine engine,
                            int sleepInterval)
Constructs a new instance of this background thread with a specified sleep interval, and adds the thread to the wiki engine's event listeners.

Parameters:
engine - the wiki engine
sleepInterval - the interval between invocations of the thread's Thread.run() method, in seconds
Method Detail

actionPerformed

public final void actionPerformed(WikiEvent event)
Listens for WikiEngineEvent.SHUTDOWN and, if detected, marks the thread for death.

Specified by:
actionPerformed in interface WikiEventListener
Parameters:
event - the event
See Also:
WikiEventListener.actionPerformed(com.ecyrd.jspwiki.event.WikiEvent)

backgroundTask

public abstract void backgroundTask()
                             throws Exception
Abstract method that performs the actual work for this background thread;

Throws:
Exception

run

public final void run()
Runs the background thread's backgroundTask() method at the interval specified by #getSleepInterval. The thread will initially pause for a full sleep interval before starting, after which it will execute startupTask(). This method will cleanly terminates the thread if the it has previously been marked for death, before which it will execute shutdownTask(). If any of the three methods return an exception, it will be re-thrown as a InternalWikiException.

Specified by:
run in interface Runnable
Overrides:
run in class Thread
See Also:
Thread.run()

shutdownTask

public void shutdownTask()
                  throws Exception
Executes a task after shutdown signal was detected. By default, this method does nothing; override it to implement custom functionality.

Throws:
Exception

startupTask

public void startupTask()
                 throws Exception
Executes a task just after the thread's Thread.run() method starts, but before the backgroundTask() task executes. By default, this method does nothing; override it to implement custom functionality.

Throws:
Exception