org.apache.turbine.services.schedule
Class JobEntry

java.lang.Object
  |
  +--org.apache.turbine.om.BaseObject
        |
        +--org.apache.turbine.services.schedule.JobEntry
All Implemented Interfaces:
Persistent, java.io.Serializable

public class JobEntry
extends BaseObject

This is a wrapper for a scheduled job. It is modeled after the Unix scheduler cron.

Version:
$Id$
Author:
Dave Bryson
See Also:
Serialized Form

Field Summary
private static int DAILY
           
private  int day_of_month
          Valid entry ( 1-31 ).
private static int DAY_OF_MONTH
           
private  java.lang.String email
          E-mail address to send notification of job run.
private  int hour
          Valid entry ( 0-23 ).
private  boolean jobIsActive
          indicates if job is currently running
private  java.util.Hashtable jobProp
          Storage for additional properties
private  int minute
          Valid entry ( 0-59 ).
private static int MINUTE
           
private  long runtime
          Next runtime.
private  int second
          Valid entry ( 0-60 ).
private static int SECOND
          schedule types
private  java.lang.String task
          The Task to perform.
private static int WEEK_DAY
           
private  int weekday
          Valid entry ( 1-7 ).
 
Fields inherited from class org.apache.turbine.om.BaseObject
errMsg, is_new, modified, NEW_ID, primaryKey
 
Constructor Summary
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.
The runtime determines it's position in the job queue.
 boolean equals(java.lang.Object je)
          Compare this Job with another.
private  int evaluateJobType()
          What schedule am I on? I know this is kinda ugly! If you can think of a cleaner way to do this, please jump in!
 int getDay_of_month()
          Get the value of day_of_month.
 java.lang.String getEmail()
          Return the e-mail address for notification.
 int getHour()
          Get the value of hour.
 int getMinute()
          Get the value of minute.
 java.lang.String getNextRunAsString()
          Get the next runtime for this job as a String.
 long getNextRuntime()
          Get the next runtime for this job as a long.
 java.util.Hashtable getProperty()
          Get extra job properties
 int getSecond()
          Get the value of second.
 java.lang.String getTask()
          Return the task for this job.
 int getWeekday()
          Get the value of weekday.
 boolean isActive()
          Check to see if job is currently active/running
 void save()
          Self-preservation.
 void setActive(boolean isActive)
          Sets whether the job is running.
 void setDay_of_month(int v)
          Set the value of day_of_month.
 void setEmail(java.lang.String mail)
          The address to send mail notifications to.
 void setHour(int v)
          Set the value of hour.
 void setMinute(int v)
          Set the value of minute.
 void setProperty(java.util.Hashtable prop)
          Set job properties
 void setSecond(int v)
          Set the value of second.
 void setTask(java.lang.String task)
          Set the task name for this job.
 void setWeekday(int v)
          Set the value of weekday.
 
Methods inherited from class org.apache.turbine.om.BaseObject
equals, getByName, getByPeerName, getByPosition, getPrimaryKey, getPrimaryKeyAsBigDecimal, getPrimaryKeyAsInt, getPrimaryKeyAsLong, getPrimaryKeyAsString, hashCode, isModified, isNew, resetModified, setModified, setNew, setPrimaryKey, setPrimaryKey, setPrimaryKey, setPrimaryKey, setPrimaryKey
 
Methods inherited from class java.lang.Object
, clone, finalize, getClass, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

second

private int second
Valid entry ( 0-60 ).

minute

private int minute
Valid entry ( 0-59 ).

hour

private int hour
Valid entry ( 0-23 ).

weekday

private int weekday
Valid entry ( 1-7 ).

day_of_month

private int day_of_month
Valid entry ( 1-31 ).

task

private java.lang.String task
The Task to perform.

runtime

private long runtime
Next runtime.

email

private java.lang.String email
E-mail address to send notification of job run.

jobIsActive

private boolean jobIsActive
indicates if job is currently running

SECOND

private static final int SECOND
schedule types

MINUTE

private static final int MINUTE

WEEK_DAY

private static final int WEEK_DAY

DAY_OF_MONTH

private static final int DAY_OF_MONTH

DAILY

private static final int DAILY

jobProp

private java.util.Hashtable jobProp
Storage for additional properties
Constructor Detail

JobEntry

public JobEntry(int sec,
                int min,
                int hour,
                int wd,
                int day_mo,
                java.lang.String task)
         throws java.lang.Exception
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:
Exception, - a generic exception.
Method Detail

calcRunTime

public void calcRunTime()
                 throws java.lang.Exception
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:
Exception, - a generic exception.

getNextRuntime

public long getNextRuntime()
Get the next runtime for this job as a long.
Returns:
The next run time as a long.

getNextRunAsString

public java.lang.String getNextRunAsString()
Get the next runtime for this job as a String.
Returns:
The next run time as a String.

setEmail

public void setEmail(java.lang.String mail)
The address to send mail notifications to. This just holds the address. The ScheduledJob should handle actually sending the mail.
Parameters:
mail - The email address.

getEmail

public java.lang.String getEmail()
Return the e-mail address for notification.
Returns:
The email address.

getTask

public java.lang.String getTask()
Return the task for this job. A task name is the Class name of the ScheduledJob created by the programmer.
Returns:
A String with the name of the scheduled job.

setTask

public void setTask(java.lang.String task)
Set the task name for this job. A task name is the Class name of the ScheduledJob created by the programmer.
Parameters:
task - A String with the name of the job.

getSecond

public int getSecond()
Get the value of second.
Returns:
Value of second.

setSecond

public void setSecond(int v)
Set the value of second.
Parameters:
v - Value to assign to second.

getMinute

public int getMinute()
Get the value of minute.
Returns:
Value of minute.

setMinute

public void setMinute(int v)
Set the value of minute.
Parameters:
v - Value to assign to minute.

getHour

public int getHour()
Get the value of hour.
Returns:
Value of hour.

setHour

public void setHour(int v)
Set the value of hour.
Parameters:
v - Value to assign to hour.

getWeekday

public int getWeekday()
Get the value of weekday.
Returns:
Value of weekday.

setWeekday

public void setWeekday(int v)
Set the value of weekday.
Parameters:
v - Value to assign to weekday.

getDay_of_month

public int getDay_of_month()
Get the value of day_of_month.
Returns:
Value of day_of_month.

setDay_of_month

public void setDay_of_month(int v)
Set the value of day_of_month.
Parameters:
v - Value to assign to day_of_month.

save

public void save()
          throws java.lang.Exception
Self-preservation.
Overrides:
save in class BaseObject
Throws:
Exception, - a generic exception.

evaluateJobType

private int evaluateJobType()
                     throws java.lang.Exception
What schedule am I on? I know this is kinda ugly! If you can think of a cleaner way to do this, please jump in!
Returns:
A number specifying the type of schedule. See calcRunTime().
Throws:
Exception, - a generic exception.

equals

public boolean equals(java.lang.Object je)
Compare this Job with another.
Overrides:
equals in class BaseObject
Parameters:
je - The JobEntry object to compare to.
Returns:
True if they're the same.

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

setProperty

public void setProperty(java.util.Hashtable prop)
Set job properties

getProperty

public java.util.Hashtable getProperty()
Get extra job properties


Copyright © 1999-2001 Apache Software Foundation. All Rights Reserved.