[104] | 1 | package test.rewolucja.scheduling; |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | import java.util.concurrent.ConcurrentHashMap; |
---|
| 5 | |
---|
| 6 | import org.apache.commons.logging.Log; |
---|
| 7 | import org.apache.commons.logging.LogFactory; |
---|
| 8 | |
---|
| 9 | import schedframe.scheduling.Job; |
---|
| 10 | import schedframe.scheduling.JobInterface; |
---|
| 11 | import schedframe.scheduling.Task; |
---|
| 12 | import schedframe.scheduling.TaskInterface; |
---|
| 13 | |
---|
| 14 | public abstract class AbstractJobRegistry extends ConcurrentHashMap<String, Job> implements JobRegistryInterface { |
---|
| 15 | |
---|
| 16 | private static final long serialVersionUID = 8409060063583755824L; |
---|
| 17 | |
---|
| 18 | private static Log log = LogFactory.getLog(AbstractJobRegistry.class); |
---|
| 19 | |
---|
| 20 | protected AbstractJobRegistry(){ |
---|
| 21 | //log.warn("Methods from JobRegistry interface are not implemented."); |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | public boolean addJob(JobInterface<?> job) { |
---|
| 25 | try { |
---|
| 26 | super.put(job.getId(), (Job) job); |
---|
| 27 | } catch (NoSuchFieldException e) { |
---|
| 28 | log.error(e.getMessage()); |
---|
| 29 | return false; |
---|
| 30 | } |
---|
| 31 | return true; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | public boolean addTask(TaskInterface<?> task) { |
---|
| 35 | if(super.containsKey(task.getJobId())){ |
---|
| 36 | super.get(task.getJobId()).add((Task)task); |
---|
| 37 | return true; |
---|
| 38 | } else { |
---|
| 39 | return false; |
---|
| 40 | } |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | public JobInterface<?> getJobInfo(String jobID) { |
---|
| 44 | return super.get(jobID); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | public TaskInterface<?> getTaskInfo(String jobID, String taskId) { |
---|
| 48 | Task task = null; |
---|
| 49 | Job job = super.get(jobID); |
---|
| 50 | |
---|
| 51 | if(job == null) |
---|
| 52 | return null; |
---|
| 53 | |
---|
| 54 | try { |
---|
| 55 | task = job.getTask(taskId); |
---|
| 56 | } catch (NoSuchFieldException e) { |
---|
| 57 | log.error(e.getMessage()); |
---|
| 58 | } |
---|
| 59 | return task; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | /*public List<JobInterface<?>> getActiveJobs() { |
---|
| 63 | log.error("getActiveJobs() not implemented."); |
---|
| 64 | return null; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | public List<TaskInterface<?>> getActiveTasks() { |
---|
| 68 | log.error("getActiveTasks() not implemented."); |
---|
| 69 | return null; |
---|
| 70 | }*/ |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | } |
---|