org.apache.jetspeed.scheduler
Class JobEntry

java.lang.Object
  extended by org.apache.jetspeed.scheduler.BaseJobEntry
      extended by org.apache.jetspeed.scheduler.JobEntry
All Implemented Interfaces:
Comparable

public class JobEntry
extends BaseJobEntry
implements Comparable

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

Version:
$Id: JobEntry.java 516448 2007-03-09 16:25:47Z ate $
Author:
Dave Bryson

Field Summary
private static int DAILY
           
private static int DAY_OF_MONTH
           
private  boolean jobIsActive
          indicates if job is currently running
private static int MINUTE
           
private  long runtime
          Next runtime.
private static int SECOND
          schedule types
private static int WEEK_DAY
           
 
Fields inherited from class org.apache.jetspeed.scheduler.BaseJobEntry
dayOfMonth, email, jobHour, jobId, jobMinute, jobSecond, task, weekDay
 
Constructor Summary
JobEntry()
          default constructor
JobEntry(int sec, int min, int hour, int wd, int day_mo, String task)
          Constuctor.
 
Method Summary
 void calcRunTime()
          Calculate how long before the next runtime.
The runtime determines it's position in the job queue.
 int compareTo(Object je)
          Compares one JobEntry to another JobEntry based on the JobId
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!
 String getNextRunAsString()
          Get the next runtime for this job as a String.
 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.jetspeed.scheduler.BaseJobEntry
getDayOfMonth, getEmail, getHour, getJobId, getMinute, getSecond, getTask, getWeekDay, setDayOfMonth, setEmail, setHour, setJobId, setMinute, setSecond, setTask, setWeekDay
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jobIsActive

private boolean jobIsActive
indicates if job is currently running


runtime

private long runtime
Next runtime.


SECOND

private static final int SECOND
schedule types

See Also:
Constant Field Values

MINUTE

private static final int MINUTE
See Also:
Constant Field Values

WEEK_DAY

private static final int WEEK_DAY
See Also:
Constant Field Values

DAY_OF_MONTH

private static final int DAY_OF_MONTH
See Also:
Constant Field Values

DAILY

private static final int DAILY
See Also:
Constant Field Values
Constructor Detail

JobEntry

public JobEntry()
default constructor


JobEntry

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

compareTo

public int compareTo(Object je)
Compares one JobEntry to another JobEntry based on the JobId

Specified by:
compareTo in interface Comparable

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.

getNextRunAsString

public 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 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.
Exception

evaluateJobType

private int evaluateJobType()
                     throws 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.
Exception


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