Expresso 5-6

com.jcorporate.expresso.services.crontab
Class CrontabEntry

java.lang.Object
  extended bycom.jcorporate.expresso.services.crontab.CrontabEntry
All Implemented Interfaces:
Comparable, Serializable

public class CrontabEntry
extends Object
implements Comparable, Serializable

CrontabEntry represents a repeatable 'action' that can take place at a given date and time.

A crontab entry's sort order creates differences between Comparable and equals(). the objects are compared by the execution time. They are tested for equality by testing time AND the listeners

Author:
Mike Dubman
See Also:
Serialized Form

Field Summary
protected  long alarmTime
          When is the next time for the alarm
protected static Object counterLock
           
protected  long counterValue
          Unique id for sorting.
protected  int dayOfMonth
          day of month for the crontab
protected  int dayOfWeek
          day of week for the crontab
protected static long globalCounter
           
protected  int hour
          Hours for the crontab
protected  boolean isRelative
          Is the crontab a 'relative' time?
protected  boolean isRepetitive
          Is the crontab a repetitive job
protected  String jobNumber
          Job Number for this CrontabEntry's associated JobQueue entry
protected  String label
          Label for the crontab
protected  CrontabListenerI listener
          The listener of the crontab
protected  int minute
          The minutes for the crontab
protected  int month
          month for the crontab
static int TIME_UNUSED
          Constant that represents a 'time' value that is unused.
protected  int year
          year for the crontab
 
Constructor Summary
CrontabEntry(Date date, CrontabListenerI listener)
          Constructs a Crontab Entry class.
CrontabEntry(int delay, boolean isRepetitive, CrontabListenerI listener)
          Construct a new crontab entry with a given delay
CrontabEntry(int minute, int hour, int dayOfMonth, int month, int dayOfWeek, int year, CrontabListenerI listener)
          Construct a Crontab entry.
CrontabEntry(int minute, int hour, int dayOfMonth, int month, int dayOfWeek, int year, String jobLabel, CrontabListenerI listener)
          Construct a Crontab entry.
 
Method Summary
protected  void adjustExecutionTime(Calendar now, Calendar alarm)
          Adjusts the execution time so that the next execution time is proper ie.. all cron rules should be followed and the next cron execution should be greater than now.
 int compareTo(Object obj)
          Standard comparison operator.
 boolean equals(Object obj)
          Returns true if the two alarm times of the comparing crontab entries are equal.
 long getAlarmTime()
          Get the alarm time in system time.
 long getCounter()
          Retrieve an incrementing id value unique across crontab instances
 int getDayOfMonth()
          Retrieve the day of month setting
 int getDayOfWeek()
          Return day of week setting
 int getHour()
          Retrieve hour setting
 String getJobNumber()
          Return Job Number for this CrontabEntry's associated JobQueue entry
 String getLabel()
          Retrieve the label of the entry
 CrontabListenerI getListener()
          Retrieve the listener for the crontab.
 int getMinute()
          Retrieve the minutes of the entry
 int getMonth()
          Return the month value of the entry
 int getYear()
          Return the year value of the entry
 boolean isIsRelative()
          Return isRelative value
 boolean isIsRepetitive()
          Retrieve the isRepetitive value
protected  void setCounterValue()
          Sets the counter so that order is guaranteed
 void setJobNumber(String s)
          Set Job Number for this CrontabEntry's associated JobQueue entry
 String toString()
          Returns the class as a string.
 void updateEntryTime()
          Set the new/latest time.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TIME_UNUSED

public static final int TIME_UNUSED
Constant that represents a 'time' value that is unused.

See Also:
Constant Field Values

globalCounter

protected static long globalCounter

counterLock

protected static Object counterLock

listener

protected transient CrontabListenerI listener
The listener of the crontab


label

protected String label
Label for the crontab


isRelative

protected boolean isRelative
Is the crontab a 'relative' time?


isRepetitive

protected boolean isRepetitive
Is the crontab a repetitive job


dayOfMonth

protected int dayOfMonth
day of month for the crontab


dayOfWeek

protected int dayOfWeek
day of week for the crontab


hour

protected int hour
Hours for the crontab


minute

protected int minute
The minutes for the crontab


month

protected int month
month for the crontab


year

protected int year
year for the crontab


alarmTime

protected long alarmTime
When is the next time for the alarm


counterValue

protected long counterValue
Unique id for sorting.


jobNumber

protected String jobNumber
Job Number for this CrontabEntry's associated JobQueue entry

Constructor Detail

CrontabEntry

public CrontabEntry(Date date,
                    CrontabListenerI listener)
             throws CronException
Constructs a Crontab Entry class.

Parameters:
date - The date to execute the crontab listener
listener - The class to execute when the alarm 'rings'
Throws:
CronException - upon error

CrontabEntry

public CrontabEntry(int delay,
                    boolean isRepetitive,
                    CrontabListenerI listener)
Construct a new crontab entry with a given delay

Parameters:
delay - the job until the number of minutes in the next hour
isRepetitive - set if the job should be executed every X amount of time
listener - the interface to notify when the cron 'rings'
Throws:
IllegalArgumentException - if the delay is less than 1

CrontabEntry

public CrontabEntry(int minute,
                    int hour,
                    int dayOfMonth,
                    int month,
                    int dayOfWeek,
                    int year,
                    CrontabListenerI listener)
             throws CronException
Construct a Crontab entry.

Parameters:
minute - Minute of the hour to execute
hour - Hour of the day to execute
dayOfMonth - The day of the month to execute
month - The month of the year to execute
dayOfWeek - The day of the week to execute
year - to execute OR TIME_UNUSED if this is a repetative crontab entry
listener - The class that gets called when the crontab 'rings'
Throws:
CronException - upon error

CrontabEntry

public CrontabEntry(int minute,
                    int hour,
                    int dayOfMonth,
                    int month,
                    int dayOfWeek,
                    int year,
                    String jobLabel,
                    CrontabListenerI listener)
             throws CronException
Construct a Crontab entry.

Parameters:
minute - Minute of the hour to execute
hour - Hour of the day to execute
dayOfMonth - The day of the month to execute
month - The month of the year to execute
dayOfWeek - The day of the week to execute
year - to execute OR TIME_UNUSED if this is a repetative crontab entry
jobLabel - - The label of the crontab entry.
listener - The class that gets called when the crontab 'rings'
Throws:
CronException - upon error
Method Detail

getAlarmTime

public long getAlarmTime()
Get the alarm time in system time.

Returns:
long integer.

getCounter

public long getCounter()
Retrieve an incrementing id value unique across crontab instances

Returns:
long value.

getDayOfMonth

public int getDayOfMonth()
Retrieve the day of month setting

Returns:
integer

getDayOfWeek

public int getDayOfWeek()
Return day of week setting

Returns:
integer

getHour

public int getHour()
Retrieve hour setting

Returns:
integer

isIsRelative

public boolean isIsRelative()
Return isRelative value

Returns:
boolean

isIsRepetitive

public boolean isIsRepetitive()
Retrieve the isRepetitive value

Returns:
boolean

getLabel

public String getLabel()
Retrieve the label of the entry

Returns:
java.lang.String

getListener

public CrontabListenerI getListener()
Retrieve the listener for the crontab.

Returns:

getMinute

public int getMinute()
Retrieve the minutes of the entry

Returns:
integer

getMonth

public int getMonth()
Return the month value of the entry

Returns:
integer

getYear

public int getYear()
Return the year value of the entry

Returns:
integer

compareTo

public int compareTo(Object obj)
Standard comparison operator. Checks against the alarm entry time.

compareTo and equals behave differently. compareTo only sorts by alarm time. Equals checks alarm times and listeners

Specified by:
compareTo in interface Comparable
Parameters:
obj - The object to compare against.
Returns:
integer as per standard Object.compareTo values
See Also:
Comparable.compareTo(java.lang.Object)

equals

public boolean equals(Object obj)
Returns true if the two alarm times of the comparing crontab entries are equal.

Parameters:
obj - The CrontabEntry to compare against.
Returns:
true if the two objects are equal

toString

public String toString()
Returns the class as a string. Useful for debugging purposes

Returns:
a String representing this class.

updateEntryTime

public void updateEntryTime()
Set the new/latest time. For example, if it's a repeatable and the last alarm time is passed, then we calculate the next one.


setCounterValue

protected void setCounterValue()
Sets the counter so that order is guaranteed


adjustExecutionTime

protected void adjustExecutionTime(Calendar now,
                                   Calendar alarm)
Adjusts the execution time so that the next execution time is proper ie.. all cron rules should be followed and the next cron execution should be greater than now.

Parameters:
now - 'now' calendar instance
alarm - the next instance that the calendar should execute.

getJobNumber

public String getJobNumber()
Return Job Number for this CrontabEntry's associated JobQueue entry

Returns:
Job Number for this CrontabEntry's associated JobQueue entry

setJobNumber

public void setJobNumber(String s)
Set Job Number for this CrontabEntry's associated JobQueue entry

Parameters:
s - Job Number for this CrontabEntry's associated JobQueue entry

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.