Class Schedule
- java.lang.Object
-
- dk.netarkivet.harvester.datamodel.Schedule
-
- All Implemented Interfaces:
Named
,Serializable
- Direct Known Subclasses:
RepeatingSchedule
,TimedSchedule
public abstract class Schedule extends Object implements 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
Fields Modifier and Type Field Description protected String
comments
Any comments added by the user.protected Frequency
frequency
Frequency of runs, possibly with a time it should happen at.protected String
name
Human readable name for the schedule.protected Date
startDate
first run of job: date, time (hour:min:sec).
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
Autogenerated equals.String
getComments()
Returns any user-entered comments about this schedule.long
getEdition()
Get the edition number.Date
getFirstEvent(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.static Schedule
getInstance(Date startDate, int repeats, Frequency freq, String name, String comments)
Get a new Schedule instance for a schedule that runs a certain number of times.static Schedule
getInstance(Date startDate, Date endDate, Frequency freq, String name, String comments)
Get a new Schedule instance for a schedule that runs over a certain period.String
getName()
Get the name of this schedule.abstract Date
getNextEvent(Date lastEvent, int numPreviousEvents)
Return the date at which the next event will happen.Date
getStartDate()
Get the first possible date this schedule is allowed to run.int
hashCode()
Autogenerated hashcode method.void
setComments(String comments)
Set the comments for the schedule.void
setEdition(long theEdition)
Set the edition number.
-
-
-
Field Detail
-
name
protected String name
Human readable name for the schedule.
-
comments
protected String comments
Any comments added by the user.
-
startDate
protected 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.
-
-
Constructor Detail
-
Schedule
protected Schedule(Date startDate, Frequency frequency, String name, 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 happenname
- 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(Date startDate, Date endDate, Frequency freq, String name, 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(Date startDate, int repeats, Frequency freq, String name, 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 Date getFirstEvent(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 Date getNextEvent(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 String getName()
Get the name of this schedule.
-
getStartDate
public 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(Object o)
Autogenerated equals.
-
hashCode
public int hashCode()
Autogenerated hashcode method.
-
getComments
public String getComments()
Returns any user-entered comments about this schedule.- Specified by:
getComments
in interfaceNamed
- Returns:
- A string of free-form comments.
-
setComments
public void setComments(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
-
-