dk.netarkivet.harvester.datamodel
Class Schedule

java.lang.Object
  extended by dk.netarkivet.harvester.datamodel.Schedule
All Implemented Interfaces:
Named, java.io.Serializable
Direct Known Subclasses:
RepeatingSchedule, TimedSchedule

public abstract class Schedule
extends java.lang.Object
implements java.io.Serializable, Named

This class implements a schedule that can be either repeating or timed, depending on the subclass. A schedule is a combination of a frequency, defining how often this schedule and at which points in time will trigger an event , plus information about when to start and when to stop triggering events. Methods are provided to check when the first event should happen, and to calculate the next events from the previous event time.

See Also:
Serialized Form

Field Summary
protected  java.lang.String comments
          Any comments added by the user.
(package private)  long edition
          Edition is used by the DAO to keep track of changes.
protected  Frequency frequency
          Frequency of runs, possibly with a time it should happen at.
protected  java.lang.String name
          Human readable name for the schedule.
protected  java.util.Date startDate
          first run of job: date, time (hour:min:sec).
 
Constructor Summary
protected Schedule(java.util.Date startDate, Frequency frequency, java.lang.String name, java.lang.String comments)
          Create a new schedule starting at a specific time and going on for an undefined time.
 
Method Summary
 boolean equals(java.lang.Object o)
          Autogenerated equals.
 java.lang.String getComments()
          Returns any user-entered comments about this schedule.
 long getEdition()
          Get the edition number.
 java.util.Date getFirstEvent(java.util.Date now)
          Return the date at which the first event will happen.
 Frequency getFrequency()
          Get the frequency defining how often and when this schedule should be run.
(package private)  long getID()
          Get the ID of this schedule.
static Schedule getInstance(java.util.Date startDate, java.util.Date endDate, Frequency freq, java.lang.String name, java.lang.String comments)
          Get a new Schedule instance for a schedule that runs over a certain period.
static Schedule getInstance(java.util.Date startDate, int repeats, Frequency freq, java.lang.String name, java.lang.String comments)
          Get a new Schedule instance for a schedule that runs a certain number of times.
 java.lang.String getName()
          Get the name of this schedule.
abstract  java.util.Date getNextEvent(java.util.Date lastEvent, int numPreviousEvents)
          Return the date at which the next event will happen.
 java.util.Date getStartDate()
          Get the first possible date this schedule is allowed to run.
 int hashCode()
          Autogenerated hashcode method.
(package private)  boolean hasID()
          Check if this schedule has an ID set yet (doesn't happen until the DBDAO persists it).
 void setComments(java.lang.String comments)
          Set the comments for the schedule.
 void setEdition(long theEdition)
          Set the edition number.
(package private)  void setID(long id)
          Set the ID of this schedule.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
Human readable name for the schedule.


comments

protected java.lang.String comments
Any comments added by the user.


startDate

protected java.util.Date startDate
first run of job: date, time (hour:min:sec). May be null, meaning at any time


frequency

protected Frequency frequency
Frequency of runs, possibly with a time it should happen at.


edition

long edition
Edition is used by the DAO to keep track of changes.

Constructor Detail

Schedule

protected Schedule(java.util.Date startDate,
                   Frequency frequency,
                   java.lang.String name,
                   java.lang.String comments)
Create a new schedule starting at a specific time and going on for an undefined time.

Parameters:
startDate - Time at which the schedule starts happening (though not necessarily the time of the first event). May be null, meaning at any time.
frequency - How frequently the events should happen
name - The unique name of this schedule.
comments - Comments entered by the user
Throws:
ArgumentNotValid - if frequency, name or comments is null, or name is ""
Method Detail

getInstance

public static Schedule getInstance(java.util.Date startDate,
                                   java.util.Date endDate,
                                   Frequency freq,
                                   java.lang.String name,
                                   java.lang.String comments)
Get a new Schedule instance for a schedule that runs over a certain period.

Parameters:
startDate - The first date an event is allowed to happen. May be null, meaning at any time.
endDate - The last date an event is allowed to happen. May be null meaning continue forever.
freq - How frequently the events should happen.
name - The name of this schedule.
comments - Comments entered by the user
Returns:
A new Schedule.
Throws:
ArgumentNotValid - if frequency, name or comments is null, or name is ""

getInstance

public static Schedule getInstance(java.util.Date startDate,
                                   int repeats,
                                   Frequency freq,
                                   java.lang.String name,
                                   java.lang.String comments)
Get a new Schedule instance for a schedule that runs a certain number of times.

Parameters:
startDate - The first date an event is allowed to happen. May be null, meaning at any time.
repeats - How many events should happen on this schedule.
freq - How frequently the events should happen.
name - The name of this schedule.
comments - Comments entered by the user
Returns:
A new Schedule.
Throws:
ArgumentNotValid - if frequency, name or comments is null, or name is "" or repeats is 0 or negative

getFirstEvent

public java.util.Date getFirstEvent(java.util.Date now)
Return the date at which the first event will happen.

Parameters:
now - The first time it can happen. Will be normalized to only second precision, milliseconds are set to 0.
Returns:
The date of the first event to happen after startDate.
Throws:
ArgumentNotValid - if now is null

getNextEvent

public abstract java.util.Date getNextEvent(java.util.Date lastEvent,
                                            int numPreviousEvents)
Return the date at which the next event will happen.

Parameters:
lastEvent - The time at which the previous event happened.
numPreviousEvents - How many events have previously happened.
Returns:
The date of the next event to happen or null for no more events.
Throws:
ArgumentNotValid - if numPreviousEvents is negative

getName

public java.lang.String getName()
Get the name of this schedule.

Specified by:
getName in interface Named
Returns:
The name

getStartDate

public java.util.Date getStartDate()
Get the first possible date this schedule is allowed to run.

Returns:
The first possible date or null for any time

getFrequency

public Frequency getFrequency()
Get the frequency defining how often and when this schedule should be run.

Returns:
The frequency

equals

public boolean equals(java.lang.Object o)
Autogenerated equals.

Overrides:
equals in class java.lang.Object
Parameters:
o - The object to compare with
Returns:
Whether objects are equal

hashCode

public int hashCode()
Autogenerated hashcode method.

Overrides:
hashCode in class java.lang.Object
Returns:
the hashcode

getComments

public java.lang.String getComments()
Returns any user-entered comments about this schedule.

Specified by:
getComments in interface Named
Returns:
A string of free-form comments.

setComments

public void setComments(java.lang.String comments)
Set the comments for the schedule.

Parameters:
comments - The new comments

getEdition

public long getEdition()
Get the edition number.

Returns:
The edition number

setEdition

public void setEdition(long theEdition)
Set the edition number.

Parameters:
theEdition - The new edition

getID

long getID()
Get the ID of this schedule. Only for use by DBDAO

Returns:
the ID of this schedule

setID

void setID(long id)
Set the ID of this schedule. Only for use by DBDAO

Parameters:
id - the new ID of this schedule

hasID

boolean hasID()
Check if this schedule has an ID set yet (doesn't happen until the DBDAO persists it).

Returns:
true if this schedule has an ID set yet