Browse Source

Count active jobs only over dispatched jobs whose status is not final.

tags/1.0.31
ymlam 2 years ago
parent
commit
2b3295588b
3 changed files with 34 additions and 72 deletions
  1. +19
    -51
      src/main/java/altk/comm/engine/Broadcast.java
  2. +1
    -1
      src/main/java/altk/comm/engine/CommEngine.java
  3. +14
    -20
      src/main/java/altk/comm/engine/Job.java

+ 19
- 51
src/main/java/altk/comm/engine/Broadcast.java View File

@@ -27,6 +27,7 @@ import org.json.simple.JSONObject;
import com.opencsv.CSVWriter; import com.opencsv.CSVWriter;


import altk.comm.engine.Job.CommJobStatus; import altk.comm.engine.Job.CommJobStatus;
import altk.comm.engine.Job.JobStatus;
import altk.comm.engine.exception.BroadcastError; import altk.comm.engine.exception.BroadcastError;
import altk.comm.engine.exception.BroadcastException; import altk.comm.engine.exception.BroadcastException;
import altk.comm.engine.exception.EngineException; import altk.comm.engine.exception.EngineException;
@@ -94,7 +95,7 @@ public abstract class Broadcast
private Queue<Job> readyQueue; private Queue<Job> readyQueue;
/** Count of items in scheduler */ /** Count of items in scheduler */
private int scheduledJobs; 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; private int serviceActivityCount;


@@ -1233,7 +1234,7 @@ public abstract class Broadcast
return 1; return 1;
} }
protected void updateServiceActivityCount(int increment)
private void updateServiceActivityCount(int increment)
{ {
synchronized (readyQueue) synchronized (readyQueue)
{ {
@@ -1272,58 +1273,9 @@ public abstract class Broadcast
report.initBase(job, broadcastId, launchRecordId, activityRecordIdParamName, jobReportRootNodeName); report.initBase(job, broadcastId, launchRecordId, activityRecordIdParamName, jobReportRootNodeName);
report.init(job); report.init(job);
postback.queueReport(report.toString()); 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. * Number of jobs to be completed.
* @return * @return
@@ -1532,5 +1484,21 @@ public abstract class Broadcast


protected void childAddConfigJSON(JSONObject dataMap) { 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;
}


} }

+ 1
- 1
src/main/java/altk/comm/engine/CommEngine.java View File

@@ -108,7 +108,7 @@ public abstract class CommEngine extends HttpServlet
// Check for resume // Check for resume
if (broadcast.daily_start.length() > 0) 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);
} }
} }




+ 14
- 20
src/main/java/altk/comm/engine/Job.java View File

@@ -1,7 +1,5 @@
package altk.comm.engine; 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. * Derived classes may add more class attributes, e.g. list of phone numbers, call status.
* @author Yuk-Ming * @author Yuk-Ming
@@ -15,11 +13,9 @@ public class Job
*/ */
public interface JobStatus public interface JobStatus
{ {
public boolean isFinal();
} }


/**
* Base JobStatus values common to all CommEngine's.
*/
static public enum CommJobStatus implements JobStatus static public enum CommJobStatus implements JobStatus
{ {
SUCCESS, SUCCESS,
@@ -39,6 +35,11 @@ public class Job
FAILED, FAILED,
NOT_FOUND, NOT_FOUND,
PAYMENT_REQUIRED; PAYMENT_REQUIRED;

@Override
public boolean isFinal() {
return true;
}
} }


public Recipient recipient; public Recipient recipient;
@@ -55,17 +56,16 @@ public class Job
jobStatus = null; jobStatus = null;
} }
public void setStatus(JobStatus jobStatus)
void setStatus(JobStatus jobStatus)
{ {
this.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. * @return error in text form.
@@ -87,14 +87,8 @@ public class Job
/** /**
* Derived class must augment this method to handle its own JobStatus * 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();
} }




} }

Loading…
Cancel
Save