import com.topcoder.util.scheduler.scheduling.Job;
import com.topcoder.util.scheduler.scheduling.ScheduledJobRunner;
import com.topcoder.util.scheduler.scheduling.ScheduledEnable;
import com.topcoder.util.file.fieldconfig.NodeList;
// The CustomJobRunner will be instantiated by the Job Scheduling component to run.
// Its run method will be called.
// This class must be thread-safe.
public class CustomJobRunner implements ScheduledJobRunner {
private boolean running = false;
private Boolean success = null;
private Job job = null;
public CustomJobRunner() {}
public boolean isDone() {
synchronized (this) {
return this.success != null;
}
}
public void close() {
}
public String getStatus() {
synchronized (this) {
if (success == null) {
return running ? ScheduledEnable.RUNNING : ScheduledEnable.NOT_STARTED;
} else {
return success.booleanValue() ? ScheduledEnable.SUCCESSFUL : ScheduledEnable.FAILED
}
}
}
public NodeList getMessageData() {
return null;
}
public String getRunningStatus() {
return getStatus();
}
public void setJob(Job job) {
this.job = job;
}
public Job getJob() {
return this.job;
}
public void run() {
synchronized (this) {
running = true;
}
try {
// TODO: .. do the business logic
synchronized (this ) {
running = false;
success = Boolean.TRUE;
}
} catch (Exception ex) {
synchronized (this ) {
running = false;
success = Boolean.FALSE;
}
}
}
}
Job Scheduling Component