You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2012/08/05 11:44:00 UTC
svn commit: r1369543 - in
/ofbiz/trunk/framework/service/src/org/ofbiz/service/job: JobManager.java
JobPoller.java PersistedServiceJob.java
Author: adrianc
Date: Sun Aug 5 09:43:59 2012
New Revision: 1369543
URL: http://svn.apache.org/viewvc?rev=1369543&view=rev
Log:
Moved method used exclusively by PersistedServiceJob from JobManager to PersistedServiceJob. Also added some JavaDocs.
Modified:
ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java
ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java
ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java?rev=1369543&r1=1369542&r2=1369543&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java Sun Aug 5 09:43:59 2012
@@ -53,7 +53,11 @@ import org.ofbiz.service.calendar.Recurr
import org.ofbiz.service.config.ServiceConfigUtil;
/**
- * JobManager
+ * Job manager. The job manager queues jobs. It contains a <code>JobPoller</code> and a
+ * <code>Delegator</code>. Client code can queue a job to be run immediately by calling the
+ * {@link #runJob(Job)} method, or schedule a job to be run later by calling the
+ * {@link #schedule(String, String, String, Map, long, int, int, int, long, int)} method.
+ * Scheduled jobs are persisted in the JobSandbox entity.
*/
public final class JobManager {
@@ -69,6 +73,12 @@ public final class JobManager {
}
}
+ /**
+ * Returns a <code>JobManager</code> instance.
+ * @param delegator
+ * @param enablePoller Enables polling of the JobSandbox entity.
+ * @throws IllegalStateException if the Job Manager is shut down.
+ */
public static JobManager getInstance(Delegator delegator, boolean enablePoller) {
assertIsRunning();
Assert.notNull("delegator", delegator);
@@ -84,31 +94,9 @@ public final class JobManager {
return jm;
}
- /** gets the recurrence info object for a job. */
- public static RecurrenceInfo getRecurrenceInfo(GenericValue job) {
- try {
- if (job != null && !UtilValidate.isEmpty(job.getString("recurrenceInfoId"))) {
- if (job.get("cancelDateTime") != null) {
- // cancel has been flagged, no more recurrence
- return null;
- }
- GenericValue ri = job.getRelatedOne("RecurrenceInfo", false);
- if (ri != null) {
- return new RecurrenceInfo(ri);
- } else {
- return null;
- }
- } else {
- return null;
- }
- } catch (GenericEntityException e) {
- Debug.logError(e, "Problem getting RecurrenceInfo entity from JobSandbox", module);
- } catch (RecurrenceInfoException re) {
- Debug.logError(re, "Problem creating RecurrenceInfo instance: " + re.getMessage(), module);
- }
- return null;
- }
-
+ /**
+ * Shuts down all job managers. This method is called when OFBiz shuts down.
+ */
public static void shutDown() {
isShutDown = true;
for (JobManager jm : registeredManagers.values()) {
@@ -153,7 +141,12 @@ public final class JobManager {
return jp.getPoolState();
}
- public synchronized List<Job> poll() {
+ /**
+ * Scans the JobSandbox entity and returns a list of jobs that are due to run.
+ * Returns an empty list if there are no jobs due to run.
+ * This method is called by the {@link JobPoller} polling thread.
+ */
+ protected synchronized List<Job> poll() {
assertIsRunning();
DispatchContext dctx = getDispatcher().getDispatchContext();
if (dctx == null) {
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java?rev=1369543&r1=1369542&r2=1369543&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java Sun Aug 5 09:43:59 2012
@@ -34,7 +34,7 @@ import org.ofbiz.service.config.ServiceC
import org.apache.commons.lang.math.NumberUtils;
/**
- * JobPoller - Polls for persisted jobs to run.
+ * Job poller. Queues and runs jobs.
*/
public final class JobPoller implements Runnable {
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java?rev=1369543&r1=1369542&r2=1369543&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java Sun Aug 5 09:43:59 2012
@@ -33,6 +33,7 @@ import org.ofbiz.base.util.UtilDateTime;
import org.ofbiz.base.util.UtilGenerics;
import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.service.calendar.RecurrenceInfoException;
import org.ofbiz.service.calendar.TemporalExpression;
import org.ofbiz.service.calendar.TemporalExpressionWorker;
import org.ofbiz.entity.Delegator;
@@ -132,7 +133,7 @@ public class PersistedServiceJob extends
long maxRecurrenceCount = -1;
long currentRecurrenceCount = 0;
TemporalExpression expr = null;
- RecurrenceInfo recurrence = JobManager.getRecurrenceInfo(jobValue);
+ RecurrenceInfo recurrence = getRecurrenceInfo();
if (recurrence != null) {
Debug.logWarning("Persisted Job [" + getJobId() + "] references a RecurrenceInfo, recommend using TemporalExpression instead", module);
currentRecurrenceCount = recurrence.getCurrentCount();
@@ -314,4 +315,20 @@ public class PersistedServiceJob extends
}
return currentRetryCount < maxRetry;
}
+
+ private RecurrenceInfo getRecurrenceInfo() {
+ try {
+ if (UtilValidate.isNotEmpty(jobValue.getString("recurrenceInfoId"))) {
+ GenericValue ri = jobValue.getRelatedOne("RecurrenceInfo", false);
+ if (ri != null) {
+ return new RecurrenceInfo(ri);
+ }
+ }
+ } catch (GenericEntityException e) {
+ Debug.logError(e, "Problem getting RecurrenceInfo entity from JobSandbox", module);
+ } catch (RecurrenceInfoException re) {
+ Debug.logError(re, "Problem creating RecurrenceInfo instance: " + re.getMessage(), module);
+ }
+ return null;
+ }
}