Class Frequency

java.lang.Object
rife.scheduler.Frequency

public class Frequency extends Object
Defines the frequency at which a task should execute.

This is inspired by the standard unix crontab frequency specification.

A number of frequently used frequencies are available as static constants, a DSL is provided to build the most features of frequency specification, or a textual specification can be provided that will be parsed.

Since:
1.0
  • Field Details

    • MINUTELY

      public static final Frequency MINUTELY
      Schedule every minute.
      Since:
      1.0
    • HOURLY

      public static final Frequency HOURLY
      Schedule every hour on the hour.
      Since:
      1.0
    • DAILY

      public static final Frequency DAILY
      Schedule every day at midnight.
      Since:
      1.0
    • MONDAYS

      public static final Frequency MONDAYS
      Schedule every monday at midnight.
      Since:
      1.0
    • TUESDAYS

      public static final Frequency TUESDAYS
      Schedule every tuesday at midnight.
      Since:
      1.0
    • WEDNESDAYS

      public static final Frequency WEDNESDAYS
      Schedule every wednesday at midnight.
      Since:
      1.0
    • THURSDAYS

      public static final Frequency THURSDAYS
      Schedule every thursday at midnight.
      Since:
      1.0
    • FRIDAYS

      public static final Frequency FRIDAYS
      Schedule every friday at midnight.
      Since:
      1.0
    • SATURDAYS

      public static final Frequency SATURDAYS
      Schedule every saturday at midnight.
      Since:
      1.0
    • SUNDAYS

      public static final Frequency SUNDAYS
      Schedule every sunday at midnight.
      Since:
      1.0
    • MONTHLY

      public static final Frequency MONTHLY
      Schedule every month on the first day at midnight.
      Since:
      1.0
    • QUARTERLY

      public static final Frequency QUARTERLY
      Schedule every quarter on the first day at midnight.
      Since:
      1.0
    • YEARLY

      public static final Frequency YEARLY
      Schedule every year on the first day at midnight.
      Since:
      1.0
  • Constructor Details

    • Frequency

      public Frequency()
      Creates a new frequency instance that will schedule every minute.
      Since:
      1.0
    • Frequency

      public Frequency(String specification) throws FrequencyException
      Creates a new frequency instance from the provided crontab specification.
      Parameters:
      specification - the specification string that will be parsed
      Throws:
      FrequencyException - when an error occurs during the parsing
      Since:
      1.0
  • Method Details

    • at

      public Frequency at(int hour, int minute)
      Schedule at a specific time.
      Parameters:
      hour - the hour to schedule, 24-hours, 0-based
      minute - the time to schedule
      Returns:
      this frequency instance
      Since:
      1.0
    • on

      public Frequency on(Month month, int date)
      Schedule on a specific day.
      Parameters:
      month - the month to schedule
      date - the day of the month to schedule, 1-based
      Returns:
      this frequency instance
      Since:
      1.0
    • everyMinute

      public Frequency everyMinute()
      Schedule every minute of the hour.
      Returns:
      this frequency instance
      Since:
      1.0
    • everyMinute

      public Frequency everyMinute(int step)
      Schedule every n-th minute of the hour

      For instance a step of 10 will schedule on minutes 0, 10, 20, 30, 40, and 50.

      Parameters:
      step - the step to use to skip over the minutes
      Returns:
      this frequency instance
      Since:
      1.0
    • atMinute

      public Frequency atMinute(int minute)
      Schedule at a specific minute of the hour.
      Parameters:
      minute - to minute in the hour to schedule
      Returns:
      this frequency instance
      Since:
      1.0
    • atMinutes

      public Frequency atMinutes(int... minutes)
      Schedule at specific minutes of the hour.
      Parameters:
      minutes - the minutes in the hour to schedule
      Returns:
      this frequency instance
      Since:
      1.0
    • duringMinutes

      public Frequency duringMinutes(int first, int last)
      Schedule every minute of the hour in a range.
      Parameters:
      first - the first minute in the range
      last - the last minute in the range, included
      Returns:
      this frequency instance
      Since:
      1.0
    • everyHour

      public Frequency everyHour()
      Schedule every hour of the day.
      Returns:
      this frequency instance
      Since:
      1.0
    • everyHour

      public Frequency everyHour(int step)
      Schedule every n-th hour of the day

      For instance a step of 6 will schedule on hours 0, 6, 12, 18, and 24.

      Parameters:
      step - the step to use to skip over the hours
      Returns:
      this frequency instance
      Since:
      1.0
    • atHour

      public Frequency atHour(int hour)
      Schedule at a specific hour of the day.
      Parameters:
      hour - to hour in the day to schedule
      Returns:
      this frequency instance
      Since:
      1.0
    • atHours

      public Frequency atHours(int... hours)
      Schedule at specific hours of the day.
      Parameters:
      hours - the hours in the day to schedule
      Returns:
      this frequency instance
      Since:
      1.0
    • duringHours

      public Frequency duringHours(int first, int last)
      Schedule every hour of the day in a range.
      Parameters:
      first - the first hour in the range
      last - the last hour in the range, included
      Returns:
      this frequency instance
      Since:
      1.0
    • everyDate

      public Frequency everyDate()
      Schedule every day of the month.
      Returns:
      this frequency instance
      Since:
      1.0
    • everyDate

      public Frequency everyDate(int step)
      Schedule every n-th day of the month

      For instance a step of 12 will schedule on day 1, 13, and 25.

      Parameters:
      step - the step to use to skip over the days
      Returns:
      this frequency instance
      Since:
      1.0
    • onDate

      public Frequency onDate(int date)
      Schedule on a specific day of the month, 1-based.
      Parameters:
      date - to day in the month to schedule
      Returns:
      this frequency instance
      Since:
      1.0
    • onDates

      public Frequency onDates(int... dates)
      Schedule on specific days of the month, 1-based.
      Parameters:
      dates - the days in the month to schedule
      Returns:
      this frequency instance
      Since:
      1.0
    • duringDates

      public Frequency duringDates(int first, int last)
      Schedule every day of the month in a range, 1-based.
      Parameters:
      first - the first day in the range
      last - the last day in the range, included
      Returns:
      this frequency instance
      Since:
      1.0
    • everyMonth

      public Frequency everyMonth()
      Schedule every month of the year.
      Returns:
      this frequency instance
      Since:
      1.0
    • everyMonth

      public Frequency everyMonth(int step)
      Schedule every n-th month of the year

      For instance a step of 3 will schedule on months 1, 4, 7, and 10.

      Parameters:
      step - the step to use to skip over the months
      Returns:
      this frequency instance
      Since:
      1.0
    • in

      public Frequency in(Month month)
      Schedule in a specific month of the year.
      Parameters:
      month - to month of the year to schedule
      Returns:
      this frequency instance
      Since:
      1.0
    • in

      public Frequency in(Month... months)
      Schedule in specific months of the year.
      Parameters:
      months - to months of the year to schedule
      Returns:
      this frequency instance
      Since:
      1.0
    • between

      public Frequency between(Month first, Month last)
      Schedule every month of the year.
      Parameters:
      first - the first month in the range
      last - the last month in the range, included
      Returns:
      this frequency instance
      Since:
      1.0
    • everyWeekday

      public Frequency everyWeekday()
      Schedule every day of the week.
      Returns:
      this frequency instance
      Since:
      1.0
    • everyWeekday

      public Frequency everyWeekday(int step)
      Schedule every n-th day of the week

      For instance a step of 2 will schedule on day 1, 3, 5 and 7.

      Parameters:
      step - the step to use to skip over the days
      Returns:
      this frequency instance
      Since:
      1.0
    • on

      public Frequency on(DayOfWeek weekday)
      Schedule on a specific day of the week.
      Parameters:
      weekday - to day of the week to schedule
      Returns:
      this frequency instance
      Since:
      1.0
    • on

      public Frequency on(DayOfWeek... weekdays)
      Schedule on a specific days of the week.
      Parameters:
      weekdays - to days of the week to schedule
      Returns:
      this frequency instance
      Since:
      1.0
    • between

      public Frequency between(DayOfWeek first, DayOfWeek last)
      Schedule every day of the week in a range.
      Parameters:
      first - the first day in the range
      last - the last day in the range, included
      Returns:
      this frequency instance
      Since:
      1.0
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • reset

      public void reset()
      Reset the frequency to be scheduler every minute.
      Since:
      1.0
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object