Class CronSchedule

java.lang.Object
com.codename1.backend.CronSchedule

public final class CronSchedule extends Object

When a cron job fires: six sets of allowed values, held as bit masks.

The build parses every literal @Scheduled(cron = ...) expression and writes the masks into the entry point it generates, so a server never parses one and a malformed one never reaches a server. parse(String, String) exists for the other case -- an expression read from configuration, which only exists at start-up -- and implements the same grammar; the plugin's tests hold the two to agreeing on every expression they know.

The grammar is Spring's six fields: second, minute, hour, day of month, month, day of week. Each is * (or ? for the two day fields), a value, a range a-b, a step *``/n or a-b/n or a/n, or a comma-separated list of those. Months and days take their three-letter English names; Sunday is 0 or 7. L as the day of month is the last day of the month. The macros @yearly, @annually, @monthly, @weekly, @daily, @midnight and @hourly stand for their usual expressions.

When both day fields are restricted a day must match BOTH, which is Spring's rule rather than Unix cron's either-or.

  • Constructor Summary

    Constructors
    Constructor
    Description
    CronSchedule(long seconds, long minutes, long hours, long daysOfMonth, long months, long daysOfWeek, boolean lastDayOfMonth, String zone, String expression)
    The masks the build computed.
  • Method Summary

    Modifier and Type
    Method
    Description
    The expression this was made from, for a listing.
    The zone it is read in.
    static String
    macro(String text)
    The expansion of a macro, or null.
    long
    next(long afterMillis)
    The first time strictly after afterMillis this fires, as epoch milliseconds, or -1 if it never does (the 30th of February).
    parse(String expression, String zone)
    Parses an expression at run time, for one that came from configuration.
    static int
    Milliseconds east of UTC for "UTC", "Z", "GMT" or "+hh:mm"; MIN_VALUE otherwise.
    Returns a string representation of the object.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • CronSchedule

      public CronSchedule(long seconds, long minutes, long hours, long daysOfMonth, long months, long daysOfWeek, boolean lastDayOfMonth, String zone, String expression)

      The masks the build computed. Called by generated code.

      Parameters
      • zone: @param zone a zone ID, a fixed offset such as +02:00, or null or empty for UTC
  • Method Details

    • getExpression

      public String getExpression()
      The expression this was made from, for a listing.
    • getZone

      public String getZone()
      The zone it is read in.
    • parse

      public static CronSchedule parse(String expression, String zone)

      Parses an expression at run time, for one that came from configuration.

      Throws
      • IllegalArgumentException: naming what is wrong
    • macro

      public static String macro(String text)
      The expansion of a macro, or null.
    • parseFixedOffset

      public static int parseFixedOffset(String zone)
      Milliseconds east of UTC for "UTC", "Z", "GMT" or "+hh:mm"; MIN_VALUE otherwise.
    • next

      public long next(long afterMillis)
      The first time strictly after afterMillis this fires, as epoch milliseconds, or -1 if it never does (the 30th of February).
    • toString

      public String toString()
      Description copied from class: Object
      Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
      Overrides:
      toString in class Object