org.apache.turbine.services.schedule
Class JobEntry

java.lang.Object
  extended byorg.apache.torque.om.BaseObject
      extended byorg.apache.turbine.services.schedule.BaseJobEntry
          extended byorg.apache.turbine.services.schedule.JobEntry
All Implemented Interfaces:
java.lang.Comparable, org.apache.torque.om.Persistent, java.io.Serializable

public class JobEntry
extends BaseJobEntry
implements java.lang.Comparable

This is a wrapper for a scheduled job. It is modeled after the Unix scheduler cron. Note: BaseJobEntry is generated by Torque at compile time, and is therefore NOT in CVS.

Version:
$Id: JobEntry.java 534527 2007-05-02 16:10:59Z tv $
Author:
Dave Bryson, Quinton McCombs
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.torque.om.BaseObject
NEW_ID
 
Constructor Summary
JobEntry()
          default constructor
JobEntry(int sec, int min, int hour, int wd, int day_mo, java.lang.String task)
          Constuctor.
 
Method Summary
 void calcRunTime()
          Calculate how long before the next runtime.
 int compareTo(java.lang.Object je)
          Used for ordering Jobentries Note: this comparator imposes orderings that are inconsistent with equals.
 java.lang.String getNextRunAsString()
          Get the next runtime for this job as a String.
 java.util.Date getNextRunDate()
          Gets the next runtime as a date
 long getNextRuntime()
          Get the next runtime for this job as a long.
 boolean isActive()
          Check to see if job is currently active/running
 void setActive(boolean isActive)
          Sets whether the job is running.
 
Methods inherited from class org.apache.turbine.services.schedule.BaseJobEntry
copy, copy, copy, copy, copyInto, copyInto, copyInto, copyInto, getByName, getByPeerName, getByPosition, getDayOfMonth, getEmail, getFieldNames, getHour, getJobId, getMinute, getPeer, getPrimaryKey, getProperty, getSecond, getTableMap, getTask, getWeekDay, save, save, save, setByName, setByPeerName, setByPosition, setDayOfMonth, setEmail, setHour, setJobId, setMinute, setPrimaryKey, setPrimaryKey, setProperty, setSecond, setTask, setWeekDay, toString
 
Methods inherited from class org.apache.torque.om.BaseObject
equals, equals, getLog, hashCode, isModified, isNew, resetModified, setModified, setNew, setPrimaryKey
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JobEntry

public JobEntry()
default constructor


JobEntry

public JobEntry(int sec,
                int min,
                int hour,
                int wd,
                int day_mo,
                java.lang.String task)
         throws TurbineException
Constuctor. Schedule a job to run on a certain point of time.
Example 1: Run the DefaultScheduledJob at 8:00am every 15th of the month -
JobEntry je = new JobEntry(0,0,8,15,"DefaultScheduledJob");
Example 2: Run the DefaultScheduledJob at 8:00am every day -
JobEntry je = new JobEntry(0,0,8,-1,"DefaultScheduledJob");
Example 3: Run the DefaultScheduledJob every 2 hours. -
JobEntry je = new JobEntry(0,120,-1,-1,"DefaultScheduledJob");
Example 4: Run the DefaultScheduledJob every 30 seconds. -
JobEntry je = new JobEntry(30,-1,-1,-1,"DefaultScheduledJob");

Parameters:
sec - Value for entry "seconds".
min - Value for entry "minutes".
hour - Value for entry "hours".
wd - Value for entry "week days".
day_mo - Value for entry "month days".
task - Task to execute.
Throws:
TurbineException - a generic exception.
Method Detail

compareTo

public int compareTo(java.lang.Object je)
Used for ordering Jobentries Note: this comparator imposes orderings that are inconsistent with equals.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
je - The first JobEntry object.
Returns:
An int indicating the result of the comparison.

setActive

public void setActive(boolean isActive)
Sets whether the job is running.

Parameters:
isActive - Whether the job is running.

isActive

public boolean isActive()
Check to see if job is currently active/running

Returns:
true if job is currently geing run by the workerthread, otherwise false

getNextRuntime

public long getNextRuntime()
Get the next runtime for this job as a long.

Returns:
The next run time as a long.

getNextRunDate

public java.util.Date getNextRunDate()
Gets the next runtime as a date

Returns:
Next run date

getNextRunAsString

public java.lang.String getNextRunAsString()
Get the next runtime for this job as a String.

Returns:
The next run time as a String.

calcRunTime

public void calcRunTime()
                 throws TurbineException
Calculate how long before the next runtime.
The runtime determines it's position in the job queue. Here's the logic:
1. Create a date the represents when this job is to run.
2. If this date has expired, them "roll" appropriate date fields forward to the next date.
3. Calculate the diff in time between the current time and the next run time.

Throws:
TurbineException - a generic exception.


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.