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