com.github.ltsopensource.spring.quartz.QuartzJobRunnerDispatcher Maven / Gradle / Ivy
The newest version!
package com.github.ltsopensource.spring.quartz;
import com.github.ltsopensource.core.domain.Action;
import com.github.ltsopensource.core.domain.Job;
import com.github.ltsopensource.tasktracker.Result;
import com.github.ltsopensource.tasktracker.runner.JobContext;
import com.github.ltsopensource.tasktracker.runner.JobRunner;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* @author Robert HG ([email protected]) on 3/16/16.
*/
class QuartzJobRunnerDispatcher implements JobRunner {
private ConcurrentMap JOB_MAP = new ConcurrentHashMap();
public QuartzJobRunnerDispatcher(List quartzJobContexts) {
for (QuartzJobContext quartzJobContext : quartzJobContexts) {
String name = quartzJobContext.getName();
JOB_MAP.put(name, quartzJobContext);
}
}
@Override
public Result run(JobContext jobContext) throws Throwable {
Job job = jobContext.getJob();
String taskId = job.getTaskId();
QuartzJobContext quartzJobContext = JOB_MAP.get(taskId);
if (quartzJobContext == null) {
return new Result(Action.EXECUTE_FAILED, "Can't find the taskId[" + taskId + "]'s QuartzCronJob");
}
quartzJobContext.getJobExecution().execute(quartzJobContext, job);
return new Result(Action.EXECUTE_SUCCESS);
}
}