diff options
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/jobs/JobCron.java')
-rw-r--r-- | pki/base/common/src/com/netscape/cmscore/jobs/JobCron.java | 134 |
1 files changed, 63 insertions, 71 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/jobs/JobCron.java b/pki/base/common/src/com/netscape/cmscore/jobs/JobCron.java index b721097d5..13ef7f256 100644 --- a/pki/base/common/src/com/netscape/cmscore/jobs/JobCron.java +++ b/pki/base/common/src/com/netscape/cmscore/jobs/JobCron.java @@ -17,6 +17,7 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.jobs; + import java.util.Calendar; import java.util.Enumeration; import java.util.StringTokenizer; @@ -27,28 +28,33 @@ import com.netscape.certsrv.base.EBaseException; import com.netscape.certsrv.jobs.IJobCron; import com.netscape.certsrv.logging.ILogger; + /** * class representing one Job cron information + * <p>here, an "item" refers to one of the 5 fields in a cron string; + * "element" refers to any comma-deliminated element in an + * "item"...which includes both numbers and '-' separated ranges. + * A cron string in the configuration takes the following format: + * <i>minute (0-59), + * hour (0-23), + * day of the month (1-31), + * month of the year (1-12), + * day of the week (0-6 with 0=Sunday)</i> * <p> - * here, an "item" refers to one of the 5 fields in a cron string; "element" - * refers to any comma-deliminated element in an "item"...which includes both - * numbers and '-' separated ranges. A cron string in the configuration takes - * the following format: <i>minute (0-59), hour (0-23), day of the month (1-31), - * month of the year (1-12), day of the week (0-6 with 0=Sunday)</i> + * e.g. jobsScheduler.job.rnJob1.cron=30 11,23 * * 1-5 + * In this example, the job "rnJob1" will be executed from Monday + * through Friday, at 11:30am and 11:30pm. * <p> - * e.g. jobsScheduler.job.rnJob1.cron=30 11,23 * * 1-5 In this example, the job - * "rnJob1" will be executed from Monday through Friday, at 11:30am and 11:30pm. - * <p> - * + * * @author cfu * @version $Revision$, $Date$ */ public class JobCron implements IJobCron { /** - * CRON_MINUTE, CRON_HOUR, CRON_DAY_OF_MONTH, CRON_MONTH_OF_YEAR, and - * CRON_DAY_OF_WEEK are to be used in <b>getItem()</b> to retrieve the - * corresponding <b>CronItem</b> + * CRON_MINUTE, CRON_HOUR, CRON_DAY_OF_MONTH, CRON_MONTH_OF_YEAR, + * and CRON_DAY_OF_WEEK are to be used in <b>getItem()</b> to + * retrieve the corresponding <b>CronItem</b> */ public static final String CRON_MINUTE = "minute"; public static final String CRON_HOUR = "hour"; @@ -65,7 +71,8 @@ public class JobCron implements IJobCron { CronItem cMOY = null; CronItem cDOW = null; - public JobCron(String cronString) throws EBaseException { + public JobCron(String cronString) + throws EBaseException { mCronString = cronString; // create all 5 items in the cron @@ -77,8 +84,9 @@ public class JobCron implements IJobCron { cronToVals(mCronString); } - - private void cronToVals(String cronString) throws EBaseException { + + private void cronToVals(String cronString) + throws EBaseException { StringTokenizer st = new StringTokenizer(cronString); String sMinute = null; @@ -93,10 +101,9 @@ public class JobCron implements IJobCron { cMinute.set(sMinute); } } catch (EBaseException e) { - log(ILogger.LL_FAILURE, - CMS.getLogMessage("CMSCORE_JOBS_INVALID_MIN", e.toString())); - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); + log(ILogger.LL_FAILURE, + CMS.getLogMessage("CMSCORE_JOBS_INVALID_MIN", e.toString())); + throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); } try { @@ -105,15 +112,13 @@ public class JobCron implements IJobCron { cHour.set(sHour); } } catch (EBaseException e) { - log(ILogger.LL_FAILURE, CMS.getLogMessage( - "CMSCORE_JOBS_INVALID_HOUR", e.toString())); - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); + log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_JOBS_INVALID_HOUR", e.toString())); + throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); } if (st.hasMoreTokens()) { sDayOMonth = st.nextToken(); - // cDOM.set(sDayOMonth); + // cDOM.set(sDayOMonth); } try { @@ -122,76 +127,62 @@ public class JobCron implements IJobCron { cMOY.set(sMonthOYear); } } catch (EBaseException e) { - log(ILogger.LL_FAILURE, - CMS.getLogMessage("CMSCORE_JOBS_INVALID_MONTH", - e.toString())); - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); + log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_JOBS_INVALID_MONTH", e.toString())); + throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); } if (st.hasMoreTokens()) { sDayOWeek = st.nextToken(); - // cDOW.set(sDayOWeek); + // cDOW.set(sDayOWeek); } /** - * day-of-month or day-of-week, or both? if only one of them is '*', the - * non '*' one prevails, the '*' one will remain empty (no elements) + * day-of-month or day-of-week, or both? + * if only one of them is '*', the non '*' one prevails, + * the '*' one will remain empty (no elements) */ // day-of-week - if ((sDayOMonth != null) && sDayOMonth.equals(CronItem.ALL) - && (sDayOWeek != null) && !sDayOWeek.equals(CronItem.ALL)) { + if ((sDayOMonth!= null) && sDayOMonth.equals(CronItem.ALL) && (sDayOWeek!= null) && !sDayOWeek.equals(CronItem.ALL)) { try { cDOW.set(sDayOWeek); } catch (EBaseException e) { - log(ILogger.LL_FAILURE, - CMS.getLogMessage("CMSCORE_JOBS_INVALID_DAY_OF_WEEK", - e.toString())); - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); + log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_JOBS_INVALID_DAY_OF_WEEK", e.toString())); + throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); } - } else if ((sDayOMonth != null) && !sDayOMonth.equals(CronItem.ALL) - && (sDayOWeek != null) && sDayOWeek.equals(CronItem.ALL)) { + } else + if ((sDayOMonth!= null) && !sDayOMonth.equals(CronItem.ALL) && (sDayOWeek!= null) && sDayOWeek.equals(CronItem.ALL)) { try { cDOM.set(sDayOMonth); } catch (EBaseException e) { - log(ILogger.LL_FAILURE, CMS.getLogMessage( - "CMSCORE_JOBS_INVALID_DAY_OF_MONTH", e.toString())); - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); + log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_JOBS_INVALID_DAY_OF_MONTH", e.toString())); + throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); } } else { // if both '*', every day, if neither is '*', do both try { - if (sDayOWeek != null) { + if (sDayOWeek!= null) { cDOW.set(sDayOWeek); } } catch (EBaseException e) { - log(ILogger.LL_FAILURE, - CMS.getLogMessage("CMSCORE_JOBS_INVALID_DAY_OF_WEEK", - e.toString())); - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); + log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_JOBS_INVALID_DAY_OF_WEEK", e.toString())); + throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); } try { if (sDayOMonth != null) { cDOM.set(sDayOMonth); } } catch (EBaseException e) { - log(ILogger.LL_FAILURE, CMS.getLogMessage( - "CMSCORE_JOBS_INVALID_DAY_OF_MONTH", e.toString())); - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); + log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_JOBS_INVALID_DAY_OF_MONTH", e.toString())); + throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); } } } /** * retrieves the cron item - * - * @param item name of the item. must be one of the <b>CRON_*</b> strings - * defined in this class - * @return an instance of the CronItem class which represents the requested - * cron item + * @param item name of the item. must be one of the <b>CRON_*</b> + * strings defined in this class + * @return an instance of the CronItem class which represents the + * requested cron item */ public CronItem getItem(String item) { if (item.equals(CRON_MINUTE)) { @@ -213,11 +204,10 @@ public class JobCron implements IJobCron { /** * Does the element fit any element in the item - * * @param element the element of "now" in cron format * @param item the item consists of a vector of elements - * @return boolean (true/false) on whether the element is one of the - * elements in the item + * @return boolean (true/false) on whether the element is one of + * the elements in the item */ boolean isElement(int element, Vector item) { // loop through all of the elements of an item @@ -230,8 +220,8 @@ public class JobCron implements IJobCron { return true; } } else { // is a range - if ((element >= cElement.getBegin()) - && (element <= cElement.getEnd())) { + if ((element >= cElement.getBegin()) && + (element <= cElement.getEnd())) { return true; } } @@ -241,10 +231,11 @@ public class JobCron implements IJobCron { } /** - * convert the day of the week representation from Calendar to cron - * + * convert the day of the week representation from Calendar to + * cron * @param time the Calendar value represents a moment of time - * @return an integer value that represents a cron Day-Of-Week element + * @return an integer value that represents a cron Day-Of-Week + * element */ public int DOW_cal2cron(Calendar time) { int calDow = time.get(Calendar.DAY_OF_WEEK); @@ -289,9 +280,9 @@ public class JobCron implements IJobCron { /** * convert the month of year representation from Calendar to cron - * * @param time the Calendar value represents a moment of time - * @return an integer value that represents a cron Month-Of-Year element + * @return an integer value that represents a cron Month-Of-Year + * element */ public int MOY_cal2cron(Calendar time) { int calMoy = time.get(Calendar.MONTH); @@ -360,6 +351,7 @@ public class JobCron implements IJobCron { protected void log(int level, String msg) { if (mLogger == null) return; - mLogger.log(ILogger.EV_SYSTEM, ILogger.S_OTHER, level, msg); + mLogger.log(ILogger.EV_SYSTEM, ILogger.S_OTHER, + level, msg); } } |