📄 crontrigger.java
字号:
protected static final int HOUR = 2; protected static final int DAY_OF_MONTH = 3; protected static final int MONTH = 4; protected static final int DAY_OF_WEEK = 5; protected static final int YEAR = 6; protected static final int ALL_SPEC_INT = 99; // '*' protected static final int NO_SPEC_INT = 98; // '?' protected static final Integer ALL_SPEC = new Integer(ALL_SPEC_INT); protected static final Integer NO_SPEC = new Integer(NO_SPEC_INT); protected static Map monthMap = new HashMap(20); protected static Map dayMap = new HashMap(60); static { monthMap.put("JAN", new Integer(0)); monthMap.put("FEB", new Integer(1)); monthMap.put("MAR", new Integer(2)); monthMap.put("APR", new Integer(3)); monthMap.put("MAY", new Integer(4)); monthMap.put("JUN", new Integer(5)); monthMap.put("JUL", new Integer(6)); monthMap.put("AUG", new Integer(7)); monthMap.put("SEP", new Integer(8)); monthMap.put("OCT", new Integer(9)); monthMap.put("NOV", new Integer(10)); monthMap.put("DEC", new Integer(11)); dayMap.put("SUN", new Integer(1)); dayMap.put("MON", new Integer(2)); dayMap.put("TUE", new Integer(3)); dayMap.put("WED", new Integer(4)); dayMap.put("THU", new Integer(5)); dayMap.put("FRI", new Integer(6)); dayMap.put("SAT", new Integer(7)); } private String cronExpression = null; private Date startTime = null; private Date endTime = null; private Date nextFireTime = null; private Date previousFireTime = null; private TimeZone timeZone = null; protected transient TreeSet seconds; protected transient TreeSet minutes; protected transient TreeSet hours; protected transient TreeSet daysOfMonth; protected transient TreeSet months; protected transient TreeSet daysOfWeek; protected transient TreeSet years; protected transient boolean lastdayOfWeek = false; protected transient int nthdayOfWeek = 0; protected transient boolean lastdayOfMonth = false; protected transient boolean nearestWeekday = false; protected transient boolean calendardayOfWeek = false; protected transient boolean calendardayOfMonth = false; protected transient boolean expressionParsed = false; /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Constructors. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /** * <p> * Create a <code>CronTrigger</code> with no settings. * </p> */ public CronTrigger() { super(); } /** * <p> * Create a <code>CronTrigger</code> with the given name and group. * </p> * * <p> * The start-time will also be set to the current time, and the time zone * will be set the the system's default time zone. * </p> */ public CronTrigger(String name, String group) { super(name, group); setStartTime(new Date()); setTimeZone(TimeZone.getDefault()); } /** * <p> * Create a <code>CronTrigger</code> with the given name, group and * expression. * </p> * * <p> * The start-time will also be set to the current time, and the time zone * will be set the the system's default time zone. * </p> */ public CronTrigger(String name, String group, String cronExpression) throws ParseException { super(name, group); setCronExpression(cronExpression); setStartTime(new Date()); setTimeZone(TimeZone.getDefault()); } /** * <p> * Create a <code>CronTrigger</code> with the given name and group, and * associated with the identified <code>{@link org.quartz.JobDetail}</code>. * </p> * * <p> * The start-time will also be set to the current time, and the time zone * will be set the the system's default time zone. * </p> */ public CronTrigger(String name, String group, String jobName, String jobGroup) { super(name, group, jobName, jobGroup); setStartTime(new Date()); setTimeZone(TimeZone.getDefault()); } /** * <p> * Create a <code>CronTrigger</code> with the given name and group, * associated with the identified <code>{@link org.quartz.JobDetail}</code>, * and with the given "cron" expression. * </p> * * <p> * The start-time will also be set to the current time, and the time zone * will be set the the system's default time zone. * </p> */ public CronTrigger(String name, String group, String jobName, String jobGroup, String cronExpression) throws ParseException { this(name, group, jobName, jobGroup, null, null, cronExpression, TimeZone.getDefault()); } /** * <p> * Create a <code>CronTrigger</code> with the given name and group, * associated with the identified <code>{@link org.quartz.JobDetail}</code>, * and with the given "cron" expression resolved with respect to the <code>TimeZone</code>. * </p> */ public CronTrigger(String name, String group, String jobName, String jobGroup, String cronExpression, TimeZone timeZone) throws ParseException { this(name, group, jobName, jobGroup, null, null, cronExpression, timeZone); } /** * <p> * Create a <code>CronTrigger</code> that will occur at the given time, * until the given end time. * </p> * * <p> * If null, the start-time will also be set to the current time, the time * zone will be set the the system's default. * </p> * * @param startTime * A <code>Date</code> set to the time for the <code>Trigger</code> * to fire. * @param endTime * A <code>Date</code> set to the time for the <code>Trigger</code> * to quit repeat firing. */ public CronTrigger(String name, String group, String jobName, String jobGroup, Date startTime, Date endTime, String cronExpression) throws ParseException { super(name, group, jobName, jobGroup); setCronExpression(cronExpression); if (startTime == null) startTime = new Date(); setStartTime(startTime); if (endTime != null) setEndTime(endTime); setTimeZone(TimeZone.getDefault()); } /** * <p> * Create a <code>CronTrigger</code> with fire time dictated by the * <code>cronExpression</code> resolved with respect to the specified * <code>timeZone</code> occuring from the <code>startTime</code> until * the given <code>endTime</code>. * </p> * * <p> * If null, the start-time will also be set to the current time. If null, * the time zone will be set to the system's default. * </p> * * @param name * of the <code>Trigger</code> * @param group * of the <code>Trigger</code> * @param jobName, * name of the <code>{@link org.quartz.JobDetail}</code> * executed on firetime * @param jobGroup, * group of the <code>{@link org.quartz.JobDetail}</code> * executed on firetime * @param startTime * A <code>Date</code> set to the earliest time for the <code>Trigger</code> * to start firing. * @param endTime * A <code>Date</code> set to the time for the <code>Trigger</code> * to quit repeat firing. * @param cronExpression, * A cron expression dictating the firing sequence of the <code>Trigger</code> * @param timeZone, * Specifies for which time zone the <code>cronExpression</code> * should be interprted, i.e. the expression 0 0 10 * * ?, is * resolved to 10:00 am in this time zone. * @throws ParseException * if the <code>cronExpression</code> is invalid. */ public CronTrigger(String name, String group, String jobName, String jobGroup, Date startTime, Date endTime, String cronExpression, TimeZone timeZone) throws ParseException { super(name, group, jobName, jobGroup); setCronExpression(cronExpression); if (startTime == null) startTime = new Date(); setStartTime(startTime); if (endTime != null) setEndTime(endTime); if (timeZone == null) { setTimeZone(TimeZone.getDefault()); } else { setTimeZone(timeZone); } } /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Interface. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, ClassNotFoundException { stream.defaultReadObject(); try { buildExpression(cronExpression); } catch (Exception ignore) { } // never happens } public void setCronExpression(String cronExpression) throws ParseException { if (cronExpression == null) throw new IllegalArgumentException( "Cron time expression cannot be null"); // Clear out values from last expression... nextFireTime = null; seconds = null; minutes = null; hours = null; daysOfMonth = null; months = null; daysOfWeek = null; years = null; lastdayOfWeek = false; nthdayOfWeek = 0; lastdayOfMonth = false; calendardayOfWeek = false; calendardayOfMonth = false; try { buildExpression(cronExpression.toUpperCase()); } catch(StringIndexOutOfBoundsException sioobe) { throw new ParseException( "Expression string length too short. " + sioobe.toString(), -1); } this.cronExpression = cronExpression; } public String getCronExpression() { return this.cronExpression; } /** * <p> * Get the time at which the <code>CronTrigger</code> should occur. * </p> */ public Date getStartTime() { return this.startTime; } public void setStartTime(Date startTime) { if (startTime == null) throw new IllegalArgumentException("Start time cannot be null"); Date eTime = getEndTime(); if (eTime != null && startTime != null && eTime.before(startTime)) throw new IllegalArgumentException( "End time cannot be before start time"); // round off millisecond... // Note timeZone is not needed here as parameter for // Calendar.getInstance(), // since time zone is implicit when using a Date in the setTime method. Calendar cl = Calendar.getInstance(); cl.setTime(startTime); cl.set(Calendar.MILLISECOND, 0); this.startTime = cl.getTime(); } /** * <p> * Get the time at which the <code>CronTrigger</code> should quit * repeating - even if repeastCount isn't yet satisfied. * </p> * * @see #getFinalFireTime() */ public Date getEndTime() { return this.endTime; } public void setEndTime(Date endTime) { Date sTime = getStartTime(); if (sTime != null && endTime != null && sTime.after(endTime)) throw new IllegalArgumentException( "End time cannot be before start time"); this.endTime = endTime; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -