From 171aaece4f23709d33d180cf36eb3af5e454b0c9 Mon Sep 17 00:00:00 2001 From: Ade Lee Date: Thu, 8 Dec 2011 21:15:59 -0500 Subject: Revert "Formatting" This reverts commit 32150d3ee32f8ac27118af7c792794b538c78a2f. --- .../src/com/netscape/cmscore/jobs/CronItem.java | 74 ++++---- .../src/com/netscape/cmscore/jobs/CronRange.java | 36 ++-- .../src/com/netscape/cmscore/jobs/JobCron.java | 134 +++++++------ .../com/netscape/cmscore/jobs/JobsScheduler.java | 207 +++++++++++---------- 4 files changed, 222 insertions(+), 229 deletions(-) (limited to 'pki/base/common/src/com/netscape/cmscore/jobs') diff --git a/pki/base/common/src/com/netscape/cmscore/jobs/CronItem.java b/pki/base/common/src/com/netscape/cmscore/jobs/CronItem.java index 48756aeb9..fda9069b3 100644 --- a/pki/base/common/src/com/netscape/cmscore/jobs/CronItem.java +++ b/pki/base/common/src/com/netscape/cmscore/jobs/CronItem.java @@ -17,6 +17,7 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.jobs; + import java.util.StringTokenizer; import java.util.Vector; @@ -24,15 +25,15 @@ import com.netscape.certsrv.apps.CMS; import com.netscape.certsrv.base.EBaseException; import com.netscape.certsrv.logging.ILogger; + /** * class representing one Job cron item - *

- * 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. + *

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. *

* for each of the 5 cron fields, it's represented as a CronItem - * + * * @author cfu * @version $Revision$, $Date$ */ @@ -48,22 +49,22 @@ public class CronItem { // store all elements in a field. // elements can either be numbers or ranges (CronRange) protected Vector mElements = new Vector(); - + public CronItem(int min, int max) { mMin = min; mMax = max; } - + /** * parses and sets a string cron item - * - * @param sItem the string representing an item of a cron string. item can - * be potentially comma separated with ranges specified with '-'s + * @param sItem the string representing an item of a cron string. + * item can be potentially comma separated with ranges specified + * with '-'s */ public void set(String sItem) throws EBaseException { - + if (sItem.equals(ALL)) { - // System.out.println("CronItem set(): item is ALL"); + // System.out.println("CronItem set(): item is ALL"); CronRange cr = new CronRange(); cr.setBegin(mMin); @@ -89,10 +90,8 @@ public class CronItem { } catch (NumberFormatException e) { // throw ... log(ILogger.LL_FAILURE, - CMS.getLogMessage("CMSCORE_JOBS_INVALID_TOKEN", - tok, e.toString())); - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); + CMS.getLogMessage("CMSCORE_JOBS_INVALID_TOKEN", tok, e.toString())); + throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); } String sEnd = tok.substring(r + 1, tok.length()); @@ -101,10 +100,8 @@ public class CronItem { } catch (NumberFormatException e) { // throw ... log(ILogger.LL_FAILURE, - CMS.getLogMessage("CMSCORE_JOBS_INVALID_TOKEN", - tok, e.toString())); - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); + CMS.getLogMessage("CMSCORE_JOBS_INVALID_TOKEN", tok, e.toString())); + throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); } // got both begin and end for range CronRange cr = new CronRange(); @@ -114,12 +111,12 @@ public class CronItem { // check range if (!cr.isValidRange(mMin, mMax)) { // throw... - log(ILogger.LL_FAILURE, CMS.getLogMessage( - "CMSCORE_JOBS_INVALID_RANGE", tok)); - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); + log(ILogger.LL_FAILURE, + CMS.getLogMessage("CMSCORE_JOBS_INVALID_RANGE", + tok)); + throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); } - // System.out.println("CronItem set(): adding a range"); + // System.out.println("CronItem set(): adding a range"); mElements.addElement(cr); } else { // number element, begin and end are the same @@ -132,20 +129,17 @@ public class CronItem { // check range if (!cr.isValidRange(mMin, mMax)) { // throw... - log(ILogger.LL_FAILURE, CMS.getLogMessage( - "CMSCORE_JOBS_INVALID_MIN_MAX_RANGE", - Integer.toString(mMin), - Integer.toString(mMax))); - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); + log(ILogger.LL_FAILURE, + CMS.getLogMessage("CMSCORE_JOBS_INVALID_MIN_MAX_RANGE", Integer.toString(mMin), Integer.toString(mMax))); + throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); } - // System.out.println("CronItem set(): adding a number"); + // System.out.println("CronItem set(): adding a number"); mElements.addElement(cr); } catch (NumberFormatException e) { // throw... - log(ILogger.LL_FAILURE, "invalid item in cron: " + tok); - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); + log(ILogger.LL_FAILURE, + "invalid item in cron: " + tok); + throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_JOB_CRON")); } } } @@ -153,9 +147,8 @@ public class CronItem { } /** - * get the vector stuffed with elements where each element is represented as - * CronRange - * + * get the vector stuffed with elements where each element is + * represented as CronRange * @return a vector of CronRanges */ public Vector getElements() { @@ -168,7 +161,8 @@ public class CronItem { protected void log(int level, String msg) { if (mLogger == null) return; - mLogger.log(ILogger.EV_SYSTEM, ILogger.S_OTHER, level, - "jobs/CronItem: " + msg); + mLogger.log(ILogger.EV_SYSTEM, ILogger.S_OTHER, + level, "jobs/CronItem: " + msg); } } + diff --git a/pki/base/common/src/com/netscape/cmscore/jobs/CronRange.java b/pki/base/common/src/com/netscape/cmscore/jobs/CronRange.java index 0536276ed..59293ee1b 100644 --- a/pki/base/common/src/com/netscape/cmscore/jobs/CronRange.java +++ b/pki/base/common/src/com/netscape/cmscore/jobs/CronRange.java @@ -17,24 +17,27 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.jobs; + + + /** * class representing one Job cron element + *

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. *

- * 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. - *

- * an Element can contain either an integer number or a range specified as - * CronRange. In case of integer numbers, begin and end are of the same value - * + * an Element can contain either an integer number or a range + * specified as CronRange. In case of integer numbers, begin + * and end are of the same value + * * @author cfu * @version $Revision$, $Date$ */ public class CronRange { int mBegin = 0; int mEnd = 0; - - public CronRange() { + + public CronRange () { } /** @@ -43,7 +46,7 @@ public class CronRange { public void setBegin(int i) { mBegin = i; } - + /** * gets the lower boundary value of the range */ @@ -66,16 +69,17 @@ public class CronRange { } /** - * checks to see if the lower and higher boundary values are within the - * min/max. - * + * checks to see if the lower and higher boundary values are + * within the min/max. * @param min the minimum value one can specify in this field * @param max the maximum value one can specify in this field - * @return a boolean (true/false) on whether the begin/end values are within - * the min/max passed in the params + * @return a boolean (true/false) on whether the begin/end values + * are within the min/max passed in the params */ public boolean isValidRange(int min, int max) { - if ((mEnd < mBegin) || (mBegin < min) || (mEnd > max)) + if ((mEnd < mBegin) || + (mBegin < min) || + (mEnd > max)) return false; else return true; 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 + *

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: + * 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) *

- * 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: 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) + * 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. *

- * 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. - *

- * + * * @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 getItem() to retrieve the - * corresponding CronItem + * CRON_MINUTE, CRON_HOUR, CRON_DAY_OF_MONTH, CRON_MONTH_OF_YEAR, + * and CRON_DAY_OF_WEEK are to be used in getItem() to + * retrieve the corresponding CronItem */ 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 CRON_* 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 CRON_* + * 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); } } diff --git a/pki/base/common/src/com/netscape/cmscore/jobs/JobsScheduler.java b/pki/base/common/src/com/netscape/cmscore/jobs/JobsScheduler.java index 0788ff8ef..5d1d3668c 100644 --- a/pki/base/common/src/com/netscape/cmscore/jobs/JobsScheduler.java +++ b/pki/base/common/src/com/netscape/cmscore/jobs/JobsScheduler.java @@ -17,6 +17,7 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.jobs; + import java.util.Calendar; import java.util.Enumeration; import java.util.Hashtable; @@ -34,21 +35,24 @@ import com.netscape.certsrv.jobs.JobPlugin; import com.netscape.certsrv.logging.ILogger; import com.netscape.cmscore.util.Debug; + /** - * This is a daemon thread that handles scheduled jobs like cron would do with - * different jobs. This daemon wakes up at a pre-configured interval to see if - * there is any job to be done, if so, a thread is created to execute the - * job(s). + * This is a daemon thread that handles scheduled jobs like cron would + * do with different jobs. This daemon wakes up at a pre-configured + * interval to see + * if there is any job to be done, if so, a thread is created to execute + * the job(s). *

- * The interval jobsScheduler.interval in the configuration is specified - * as number of minutes. If not set, the default is 1 minute. Note that the cron - * specification for each job CAN NOT be finer than the granularity of the - * Scheduler daemon interval. For example, if the daemon interval is set to 5 - * minute, a job cron for every minute at 7am on each Tuesday (e.g. * 7 * * 2) - * will result in the execution of the job thread only once every 5 minutes - * during that hour. The inteval value is recommended at 1 minute, setting it - * otherwise has the potential of forever missing the beat. Use with - * caution. + * The interval jobsScheduler.interval in the configuration is + * specified as number of minutes. If not set, the default is 1 minute. + * Note that the cron specification for each job CAN NOT be finer than + * the granularity of the Scheduler daemon interval. For example, if + * the daemon interval is set to 5 minute, a job cron for every minute + * at 7am on each Tuesday (e.g. * 7 * * 2) will result in the + * execution of the job thread only once every 5 minutes during that + * hour. The inteval value is recommended at 1 minute, setting it + * otherwise has the potential of forever missing the beat. Use + * with caution. * * @author cfu * @see JobCron @@ -89,19 +93,19 @@ public class JobsScheduler implements Runnable, IJobsScheduler { } /** - * read from the config file all implementations of Jobs, register and - * initialize them + * read from the config file all implementations of Jobs, + * register and initialize them *

* the config params have the following formats: * jobScheduler.impl.[implementation name].class=[package name] * jobScheduler.job.[job name].pluginName=[implementation name] - * jobScheduler.job.[job name].cron=[crontab format] jobScheduler.job.[job - * name].[any job specific params]=[values] + * jobScheduler.job.[job name].cron=[crontab format] + * jobScheduler.job.[job name].[any job specific params]=[values] * * @param config jobsScheduler configStore */ public void init(ISubsystem owner, IConfigStore config) - throws EBaseException, EJobsException { + throws EBaseException, EJobsException { mLogger = CMS.getLogger(); // read in config parameters and set variables @@ -137,13 +141,15 @@ public class JobsScheduler implements Runnable, IJobsScheduler { while (jobs.hasMoreElements()) { String jobName = (String) jobs.nextElement(); String implName = c.getString(jobName + "." + PROP_PLUGIN); - JobPlugin plugin = (JobPlugin) mJobPlugins.get(implName); + JobPlugin plugin = + (JobPlugin) mJobPlugins.get(implName); if (plugin == null) { - log(ILogger.LL_FAILURE, CMS.getLogMessage( - "CMSCORE_JOBS_CLASS_NOT_FOUND", implName)); - throw new EJobsException(CMS.getUserMessage( - "CMS_JOB_PLUGIN_NOT_FOUND", implName)); + log(ILogger.LL_FAILURE, + CMS.getLogMessage("CMSCORE_JOBS_CLASS_NOT_FOUND", + implName)); + throw new + EJobsException(CMS.getUserMessage("CMS_JOB_PLUGIN_NOT_FOUND", implName)); } String classPath = plugin.getClassPath(); @@ -151,7 +157,8 @@ public class JobsScheduler implements Runnable, IJobsScheduler { IJob job = null; try { - job = (IJob) Class.forName(classPath).newInstance(); + job = (IJob) + Class.forName(classPath).newInstance(); IConfigStore jconfig = c.getSubStore(jobName); job.init(this, jobName, implName, jconfig); @@ -161,31 +168,23 @@ public class JobsScheduler implements Runnable, IJobsScheduler { } catch (ClassNotFoundException e) { String errMsg = "JobsScheduler:: init()-" + e.toString(); - log(ILogger.LL_FAILURE, - CMS.getLogMessage("CMSCORE_JOBS_INIT_ERROR", - e.toString())); - throw new EJobsException(CMS.getUserMessage( - "CMS_JOB_LOAD_CLASS_FAILED", classPath)); + log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_JOBS_INIT_ERROR", e.toString())); + throw new + EJobsException(CMS.getUserMessage("CMS_JOB_LOAD_CLASS_FAILED", classPath)); } catch (IllegalAccessException e) { String errMsg = "JobsScheduler:: init()-" + e.toString(); - log(ILogger.LL_FAILURE, - CMS.getLogMessage("CMSCORE_JOBS_INIT_ERROR", - e.toString())); - throw new EJobsException(CMS.getUserMessage( - "CMS_JOB_LOAD_CLASS_FAILED", classPath)); + log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_JOBS_INIT_ERROR", e.toString())); + throw new + EJobsException(CMS.getUserMessage("CMS_JOB_LOAD_CLASS_FAILED", classPath)); } catch (InstantiationException e) { String errMsg = "JobsScheduler: init()-" + e.toString(); - log(ILogger.LL_FAILURE, - CMS.getLogMessage("CMSCORE_JOBS_INIT_ERROR", - e.toString())); - throw new EJobsException(CMS.getUserMessage( - "CMS_JOB_LOAD_CLASS_FAILED", classPath)); + log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_JOBS_INIT_ERROR", e.toString())); + throw new + EJobsException(CMS.getUserMessage("CMS_JOB_LOAD_CLASS_FAILED", classPath)); } catch (EBaseException e) { - log(ILogger.LL_FAILURE, - CMS.getLogMessage("CMSCORE_JOBS_INIT_ERROR", - e.toString())); + log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_JOBS_INIT_ERROR", e.toString())); throw e; } } @@ -206,10 +205,12 @@ public class JobsScheduler implements Runnable, IJobsScheduler { } /** - * when wake up: . execute the scheduled job(s) * if job still running from - * previous interval, skip it . figure out when is the next wakeup time - * (every interval). If current wakup time runs over the interval, skip the - * missed interval(s) . sleep till the next wakeup time + * when wake up: + * . execute the scheduled job(s) + * * if job still running from previous interval, skip it + * . figure out when is the next wakeup time (every interval). If + * current wakup time runs over the interval, skip the missed interval(s) + * . sleep till the next wakeup time */ public void run() { long wokeupTime = 0; @@ -228,8 +229,9 @@ public class JobsScheduler implements Runnable, IJobsScheduler { // possible to be at exactly second 1, millisecond 0, // just let it skip to next second, fine. duration = (60 - second) * 1000 + 1000 - milliSec; - log(ILogger.LL_INFO, "adjustment for cron behavior: sleep for " - + duration + " milliseconds"); + log(ILogger.LL_INFO, + "adjustment for cron behavior: sleep for " + + duration + " milliseconds"); } else { // when is the next wakeup time for the JobsScheduler? @@ -266,13 +268,14 @@ public class JobsScheduler implements Runnable, IJobsScheduler { // get time now cal = Calendar.getInstance(); - + /** - * Get the current time outside the jobs while loop to make sure - * that the rightful jobs are run -- milliseconds from the epoch + * Get the current time outside the jobs while loop + * to make sure that the rightful jobs are run + * -- milliseconds from the epoch */ wokeupTime = cal.getTime().getTime(); - + IJob job = null; for (Enumeration e = mJobs.elements(); e.hasMoreElements();) { @@ -293,29 +296,28 @@ public class JobsScheduler implements Runnable, IJobsScheduler { // start the job thread if necessary if (isShowTime(job, cal) == true) { - // log(ILogger.LL_INFO, "show time for: "+job.getId()); + // log(ILogger.LL_INFO, "show time for: "+job.getId()); // if previous thread still alive, skip Thread jthread = (Thread) mJobThreads.get(job.getId()); if ((jthread == null) || (!jthread.isAlive())) { - Thread jobThread = new Thread((Runnable) job, - job.getId()); + Thread jobThread = new Thread((Runnable) job, job.getId()); jobThread.start(); // put into job thread control mJobThreads.put(job.getId(), jobThread); } else { // previous thread still alive, log it - log(ILogger.LL_INFO, "Job " + job.getId() - + " still running...skipping this round"); + log(ILogger.LL_INFO, "Job " + job.getId() + + " still running...skipping this round"); } } } // for } } - + public IJobCron createJobCron(String cs) throws EBaseException { return new JobCron(cs); } @@ -335,8 +337,9 @@ public class JobsScheduler implements Runnable, IJobsScheduler { /** * is it the right month? */ - Vector moy = jcron.getItem(JobCron.CRON_MONTH_OF_YEAR).getElements(); - + Vector moy = + jcron.getItem(JobCron.CRON_MONTH_OF_YEAR).getElements(); + int cronMoy = jcron.MOY_cal2cron(now); if (jcron.isElement(cronMoy, moy) == false) { @@ -357,8 +360,8 @@ public class JobsScheduler implements Runnable, IJobsScheduler { int cronDow = jcron.DOW_cal2cron(now); - if ((jcron.isElement(cronDow, dow) == false) - && (jcron.isElement(now.get(Calendar.DAY_OF_MONTH), dom) == false)) { + if ((jcron.isElement(cronDow, dow) == false) && + (jcron.isElement(now.get(Calendar.DAY_OF_MONTH), dom) == false)) { return false; } // is the right date! @@ -381,25 +384,23 @@ public class JobsScheduler implements Runnable, IJobsScheduler { if (jcron.isElement(now.get(Calendar.MINUTE), minute) == false) { return false; } - // is the right minute! We're on! + // is the right minute! We're on! return true; } /** * Retrieves id (name) of this subsystem. - * * @return name of the Jobs Scheduler subsystem */ public String getId() { return (mId); } - + /** * Sets id string to this subsystem. *

- * Use with caution. Should not do it when sharing with others - * + * Use with caution. Should not do it when sharing with others * @param id name to be applied to an Jobs Scheduler subsystem */ public void setId(String id) throws EBaseException { @@ -420,14 +421,13 @@ public class JobsScheduler implements Runnable, IJobsScheduler { * registers the administration servlet with the administration subsystem. */ public void startup() throws EBaseException { - // remove, already logged from S_ADMIN - // String infoMsg = - // "Jobs Scheduler subsystem administration Servlet registered"; - // log(ILogger.LL_INFO, infoMsg); + //remove, already logged from S_ADMIN + //String infoMsg = "Jobs Scheduler subsystem administration Servlet registered"; + //log(ILogger.LL_INFO, infoMsg); } /** - * shuts down Jobs one by one. + * shuts down Jobs one by one. *

*/ public void shutdown() { @@ -438,23 +438,23 @@ public class JobsScheduler implements Runnable, IJobsScheduler { Enumeration enums = mJobThreads.keys(); while (enums.hasMoreElements()) { - String id = (String) enums.nextElement(); - Thread currthread = (Thread) mJobThreads.get(id); - // if (currthread != null) - // currthread.destroy(); + String id = (String)enums.nextElement(); + Thread currthread = (Thread)mJobThreads.get(id); + //if (currthread != null) + // currthread.destroy(); } mJobThreads.clear(); mJobThreads = null; - // if (mScheduleThread != null) - // mScheduleThread.destroy(); + //if (mScheduleThread != null) + // mScheduleThread.destroy(); } /** * Returns the root configuration storage of this system. *

- * + * * @return configuration store of this subsystem */ public IConfigStore getConfigStore() { @@ -462,28 +462,29 @@ public class JobsScheduler implements Runnable, IJobsScheduler { } /** - * Gets configuration parameters for the given job plugin. - * + * Gets configuration parameters for the given + * job plugin. * @param implName Name of the job plugin. * @return Hashtable of required parameters. */ - public String[] getConfigParams(String implName) throws EJobsException { + public String[] getConfigParams(String implName) + throws EJobsException { if (Debug.ON) Debug.trace("in getCofigParams()"); - // is this a registered implname? + // is this a registered implname? JobPlugin plugin = (JobPlugin) mJobPlugins.get(implName); if (plugin == null) { - log(ILogger.LL_FAILURE, - CMS.getLogMessage("CMSCORE_JOBS_CLASS_NOT_FOUND", implName)); + log(ILogger.LL_FAILURE, + CMS.getLogMessage("CMSCORE_JOBS_CLASS_NOT_FOUND", implName)); if (Debug.ON) Debug.trace("Job plugin " + implName + " not found."); - throw new EJobsException(CMS.getUserMessage( - "CMS_JOB_PLUGIN_NOT_FOUND", implName)); + throw new EJobsException(CMS.getUserMessage("CMS_JOB_PLUGIN_NOT_FOUND", + implName)); } - // XXX can find an instance of this plugin in existing + // XXX can find an instance of this plugin in existing // auth manager instantces to avoid instantiation just for this. // a temporary instance @@ -493,31 +494,32 @@ public class JobsScheduler implements Runnable, IJobsScheduler { if (Debug.ON) Debug.trace("className = " + className); try { - jobInst = (IJob) Class.forName(className).newInstance(); + jobInst = (IJob) + Class.forName(className).newInstance(); if (Debug.ON) Debug.trace("class instantiated"); return (jobInst.getConfigParams()); } catch (InstantiationException e) { - log(ILogger.LL_FAILURE, - CMS.getLogMessage("CMSCORE_JOBS_CREATE_NEW", e.toString())); + log(ILogger.LL_FAILURE, + CMS.getLogMessage("CMSCORE_JOBS_CREATE_NEW", e.toString())); if (Debug.ON) Debug.trace("class NOT instantiated: " + e.toString()); - throw new EJobsException(CMS.getUserMessage( - "CMS_JOB_LOAD_CLASS_FAILED", className)); + throw new + EJobsException(CMS.getUserMessage("CMS_JOB_LOAD_CLASS_FAILED", className)); } catch (ClassNotFoundException e) { - log(ILogger.LL_FAILURE, - CMS.getLogMessage("CMSCORE_JOBS_CREATE_NEW", e.toString())); + log(ILogger.LL_FAILURE, + CMS.getLogMessage("CMSCORE_JOBS_CREATE_NEW", e.toString())); if (Debug.ON) Debug.trace("class NOT instantiated: " + e.toString()); - throw new EJobsException(CMS.getUserMessage( - "CMS_JOB_LOAD_CLASS_FAILED", className)); + throw new + EJobsException(CMS.getUserMessage("CMS_JOB_LOAD_CLASS_FAILED", className)); } catch (IllegalAccessException e) { - log(ILogger.LL_FAILURE, - CMS.getLogMessage("CMSCORE_JOBS_CREATE_NEW", e.toString())); + log(ILogger.LL_FAILURE, + CMS.getLogMessage("CMSCORE_JOBS_CREATE_NEW", e.toString())); if (Debug.ON) Debug.trace("class NOT instantiated: " + e.toString()); - throw new EJobsException(CMS.getUserMessage( - "CMS_JOB_LOAD_CLASS_FAILED", className)); + throw new + EJobsException(CMS.getUserMessage("CMS_JOB_LOAD_CLASS_FAILED", className)); } } @@ -531,7 +533,8 @@ public class JobsScheduler implements Runnable, IJobsScheduler { public 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); } public Hashtable getJobPlugins() { -- cgit