org.opengts.extra.util
Class Cron

java.lang.Object
  extended by org.opengts.extra.util.Cron

public class Cron
extends java.lang.Object

Cron job handling tools


Nested Class Summary
 class Cron.CronJob
          CronJob class
static class Cron.When
          This class determines when a cronjob should be triggered
 
Constructor Summary
Cron()
          Cron scheduler default constructor (with no defined 'crontab' file loaded)
Cron(java.io.File xmlFile)
          Cron scheduler default constructor
 
Method Summary
 void cleanJobList()
          Clears the current CronJob list
static void exec(java.lang.String[] cmdArgs)
          Executes the specified command in a separate process
protected  boolean getAttributeBoolean(org.w3c.dom.Element elem, java.lang.String key, boolean dft)
          Returns the boolean value of the named attribute from the specified element
protected  long getAttributeLong(org.w3c.dom.Element elem, java.lang.String key, long dft)
          Returns the long value of the named attribute from the specified element
protected  java.lang.String getAttributeString(org.w3c.dom.Element elem, java.lang.String key, java.lang.String dft)
          Gets a named attribute from the specified element.
 long getCronIntervalSec()
          Gets the current cron wakeup interval (in seconds).
 java.io.File getCrontabXMLFile()
          Returns the current crontab xml file
protected  org.w3c.dom.Document getDocument(java.io.File xmlFile)
          Creates/returns an XML Document for the specific xml file
 int getJobCount()
          Returns the current number of CronJobs
 java.lang.String getJobDescription(java.lang.String jobName)
          Gets the description of the specified job name (case sensitive match)
protected  java.util.List<Cron.CronJob> getJobList()
          Gets the current CronJob list
 java.lang.String[] getJobNames()
          Gets the current CronJob names
protected  java.lang.String getNodeText(org.w3c.dom.Node root)
          Returns the String text for the specified node
protected  ThreadPool getThreadPool()
          Gets the ThreadPool used to run threaded jobs
 java.util.TimeZone getTimeZone()
          Gets the current TimZone
 boolean hasJobs()
          Returns true if "getJobCount()" is greater than 0
 boolean hasLoadError()
          Returns true if a "load" error has occurred
 boolean load(java.io.File xmlFile)
          Loads the specified crontab xml file
 boolean load(java.io.File xmlFile, boolean checkStopOnError)
          Loads the specified crontab xml file
static void main(java.lang.String[] argv)
          Main entry point
 void runCron()
          Start the Cron process.
 void setCronIntervalSec(long intervSec)
          Sets the cron wakeup interval (in seconds).
 void setCrontabXMLFile(java.io.File xmlFile)
          Sets the crontab xml file to load
 void setTimeZone(java.lang.String tmzStr)
          Sets the current TimeZone
 void setTimeZone(java.util.TimeZone tmz)
          Sets the current TimeZone
static boolean TestRange(java.lang.String range, int value, int type)
          Tests to see if the specified value is within the specified range
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cron

public Cron()
Cron scheduler default constructor (with no defined 'crontab' file loaded)


Cron

public Cron(java.io.File xmlFile)
     throws java.io.FileNotFoundException
Cron scheduler default constructor

Parameters:
xmlFile - The crontab xml file to load
Throws:
java.io.FileNotFoundException
Method Detail

setCrontabXMLFile

public void setCrontabXMLFile(java.io.File xmlFile)
                       throws java.io.FileNotFoundException
Sets the crontab xml file to load

Parameters:
xmlFile - The crontab file to load
Throws:
java.io.FileNotFoundException

getCrontabXMLFile

public java.io.File getCrontabXMLFile()
                               throws java.io.FileNotFoundException
Returns the current crontab xml file

Returns:
the current crontab xml file
Throws:
java.io.FileNotFoundException

setCronIntervalSec

public void setCronIntervalSec(long intervSec)
Sets the cron wakeup interval (in seconds).

Parameters:
intervSec - The cron wakeup interval (in seconds).

getCronIntervalSec

public long getCronIntervalSec()
Gets the current cron wakeup interval (in seconds).

Returns:
The current cron wakeup interval (in seconds).

setTimeZone

public void setTimeZone(java.lang.String tmzStr)
Sets the current TimeZone

Parameters:
tmzStr - The TimeZone (String representation)

setTimeZone

public void setTimeZone(java.util.TimeZone tmz)
Sets the current TimeZone

Parameters:
tmz - The TimeZone

getTimeZone

public java.util.TimeZone getTimeZone()
Gets the current TimZone

Returns:
The current TimeZone

getThreadPool

protected ThreadPool getThreadPool()
Gets the ThreadPool used to run threaded jobs

Returns:
The ThreadPool used to run threaded jobs

getJobList

protected java.util.List<Cron.CronJob> getJobList()
Gets the current CronJob list

Returns:
The current CronJob list

cleanJobList

public void cleanJobList()
Clears the current CronJob list


getJobCount

public int getJobCount()
Returns the current number of CronJobs

Returns:
the current number of CronJobs

hasJobs

public boolean hasJobs()
Returns true if "getJobCount()" is greater than 0

Returns:
True if this Cron instance contains at least one job.

getJobNames

public java.lang.String[] getJobNames()
Gets the current CronJob names

Returns:
The current CronJob names

getJobDescription

public java.lang.String getJobDescription(java.lang.String jobName)
Gets the description of the specified job name (case sensitive match)

Returns:
The description of the specified job name

runCron

public void runCron()
             throws java.io.IOException
Start the Cron process. This method blocks forever, or until an error occurs (whichever comes first)

Throws:
java.io.IOException

hasLoadError

public boolean hasLoadError()
Returns true if a "load" error has occurred


load

public boolean load(java.io.File xmlFile)
             throws java.io.IOException
Loads the specified crontab xml file

Parameters:
xmlFile - The crontab xml file to load
Returns:
True if jobs were found, false otherwise
Throws:
java.io.IOException

load

public boolean load(java.io.File xmlFile,
                    boolean checkStopOnError)
             throws java.io.IOException
Loads the specified crontab xml file

Parameters:
xmlFile - The crontab xml file to load
Returns:
True if jobs were found, false otherwise
Throws:
java.io.IOException

getDocument

protected org.w3c.dom.Document getDocument(java.io.File xmlFile)
Creates/returns an XML Document for the specific xml file

Parameters:
xmlFile - The XML file

getNodeText

protected java.lang.String getNodeText(org.w3c.dom.Node root)
Returns the String text for the specified node

Parameters:
root - The node for which the node text will be returned

getAttributeString

protected java.lang.String getAttributeString(org.w3c.dom.Element elem,
                                              java.lang.String key,
                                              java.lang.String dft)
Gets a named attribute from the specified element.

Parameters:
elem - The element from which the attribute value will be returned
key - The name of the attribute
dft - The default value to return if the named attribute doesn't exist
Returns:
The value of the named attribute, or the default value if the attribute does not exist.

getAttributeBoolean

protected boolean getAttributeBoolean(org.w3c.dom.Element elem,
                                      java.lang.String key,
                                      boolean dft)
Returns the boolean value of the named attribute from the specified element

Parameters:
elem - The element from which the attribute value will be returned
key - The name of the attribute
dft - The default boolean value to return if the named attribute doesn't exist
Returns:
The boolean value of the named attribute, or the default value if the attribute does not exist.

getAttributeLong

protected long getAttributeLong(org.w3c.dom.Element elem,
                                java.lang.String key,
                                long dft)
Returns the long value of the named attribute from the specified element

Parameters:
elem - The element from which the attribute value will be returned
key - The name of the attribute
dft - The default long value to return if the named attribute doesn't exist
Returns:
The long value of the named attribute, or the default value if the attribute does not exist.

exec

public static void exec(java.lang.String[] cmdArgs)
Executes the specified command in a separate process

Parameters:
cmdArgs - The command and arguments to execute

TestRange

public static boolean TestRange(java.lang.String range,
                                int value,
                                int type)
Tests to see if the specified value is within the specified range

Parameters:
range - The valid range (String representation)
value - The value tested for inclusion in the range
type - The type of range test to perform
Returns:
True if the value is within the specified range

main

public static void main(java.lang.String[] argv)
Main entry point

Parameters:
argv - The command line arguments