diff --git a/src/main/java/altk/comm/engine/Broadcast.java b/src/main/java/altk/comm/engine/Broadcast.java index 62b835c..1805183 100644 --- a/src/main/java/altk/comm/engine/Broadcast.java +++ b/src/main/java/altk/comm/engine/Broadcast.java @@ -27,6 +27,7 @@ import org.json.simple.JSONObject; import com.opencsv.CSVWriter; import altk.comm.engine.Job.CommJobStatus; +import altk.comm.engine.Job.JobStatus; import altk.comm.engine.exception.BroadcastError; import altk.comm.engine.exception.BroadcastException; import altk.comm.engine.exception.EngineException; @@ -94,7 +95,7 @@ public abstract class Broadcast private Queue readyQueue; /** Count of items in scheduler */ private int scheduledJobs; - /** Instantaneous number of jobs being serviced by service provider */ + /** Instantaneous number of jobs being serviced by service provider and JobStatus not final */ private int serviceActivityCount; @@ -1233,7 +1234,7 @@ public abstract class Broadcast return 1; } - protected void updateServiceActivityCount(int increment) + private void updateServiceActivityCount(int increment) { synchronized (readyQueue) { @@ -1272,58 +1273,9 @@ public abstract class Broadcast report.initBase(job, broadcastId, launchRecordId, activityRecordIdParamName, jobReportRootNodeName); report.init(job); postback.queueReport(report.toString()); - if (job.statusIsFinal()) updateServiceActivityCount(-1); } } - /** - * Logs completedJobCount, readyQueue.size(), - * active job count, and total. - * Job statistics are collected by length of readyQueue, completedJobCount, - */ - private void logJobCount(String title) - { - if (postback == null) { - myLogger.debug(title + ": postback = null"); - myLogger.debug(String.format("%s: state %s, completed: %d, active: %d, ready: %d, scheduled: %d, total jobs: %d, remaining: %d, postQueue: ", - title, - state, - getCompletedJobCount(), - getActiveJobCount(), - readyQueue.size(), - scheduledJobs, - jobsTotal, - getRemainingJobCount() - )); - return; - } - if (postback.postQueue == null) { - myLogger.debug(title + ": postback.postQueue = null"); - myLogger.debug(String.format("%s: state %s, completed: %d, active: %d, ready: %d, scheduled: %d, total jobs: %d, remaining: %d, postQueue: ", - title, - state, - getCompletedJobCount(), - getActiveJobCount(), - readyQueue.size(), - scheduledJobs, - jobsTotal, - getRemainingJobCount() - )); - return; - } - myLogger.debug(String.format("%s: state %s, completed: %d, active: %d, ready: %d, scheduled %d, total jobs: %d, remaining: %d, postQueue: %d", - title, - state, - getCompletedJobCount(), - getActiveJobCount(), - readyQueue.size(), - scheduledJobs, - jobsTotal, - getRemainingJobCount(), - postback.postQueue.size() - )); - } - /** * Number of jobs to be completed. * @return @@ -1532,5 +1484,21 @@ public abstract class Broadcast protected void childAddConfigJSON(JSONObject dataMap) { } + + public boolean setJobStatus(Job job, JobStatus status) { + if (job.statusIsFinal()) { + myLogger.warn("Forbidden ttempt to overwrite a final job status '" + job.jobStatus + "' with '" + status + "'", new Exception("info")); + return false; + } + job.setStatus(status); + if (status.isFinal()) updateServiceActivityCount(-1); + return true; + } + + public boolean setJobStatus(Job job, JobStatus status, String errorText) { + if (!setJobStatus(job, status)) return false; + job.setErrorText(errorText); + return true; + } } diff --git a/src/main/java/altk/comm/engine/CommEngine.java b/src/main/java/altk/comm/engine/CommEngine.java index 2ab632a..f8e4d02 100644 --- a/src/main/java/altk/comm/engine/CommEngine.java +++ b/src/main/java/altk/comm/engine/CommEngine.java @@ -108,7 +108,7 @@ public abstract class CommEngine extends HttpServlet // Check for resume if (broadcast.daily_start.length() > 0) { - if (timeOfDay.equals(broadcast.daily_start)) broadcast.resume("clock", null); + if (timeOfDay.equals(broadcast.daily_start)) broadcast.resume(Broadcast.ACTION_BY_CLOCK); } } diff --git a/src/main/java/altk/comm/engine/Job.java b/src/main/java/altk/comm/engine/Job.java index 79d4aef..dd2098c 100644 --- a/src/main/java/altk/comm/engine/Job.java +++ b/src/main/java/altk/comm/engine/Job.java @@ -1,7 +1,5 @@ package altk.comm.engine; -import altk.comm.engine.Job.CommJobStatus; - /** * Derived classes may add more class attributes, e.g. list of phone numbers, call status. * @author Yuk-Ming @@ -15,11 +13,9 @@ public class Job */ public interface JobStatus { + public boolean isFinal(); } - /** - * Base JobStatus values common to all CommEngine's. - */ static public enum CommJobStatus implements JobStatus { SUCCESS, @@ -39,6 +35,11 @@ public class Job FAILED, NOT_FOUND, PAYMENT_REQUIRED; + + @Override + public boolean isFinal() { + return true; + } } public Recipient recipient; @@ -55,17 +56,16 @@ public class Job jobStatus = null; } - public void setStatus(JobStatus jobStatus) + void setStatus(JobStatus jobStatus) { this.jobStatus = jobStatus; } - public void setStatus(JobStatus jobStatus, String errorText) - { - this.jobStatus = jobStatus; - this.errorText = errorText; - } - + void setErrorText(String errorText) + { + this.errorText = errorText; + } + /** * * @return error in text form. @@ -87,14 +87,8 @@ public class Job /** * Derived class must augment this method to handle its own JobStatus */ - protected boolean statusIsFinal() { - if (jobStatus instanceof CommJobStatus) - { - return true; - } - throw new IllegalArgumentException("Job status is not a CommJobStatus"); + final protected boolean statusIsFinal() { + return jobStatus != null && jobStatus.isFinal(); } - - }