source: DCWoRMS/branches/coolemall/src/schedframe/scheduling/manager/tasks/AbstractJobRegistry.java @ 1151

Revision 1151, 1.9 KB checked in by wojtekp, 12 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package schedframe.scheduling.manager.tasks;
2
3
4import java.util.ArrayList;
5import java.util.List;
6import java.util.concurrent.ConcurrentHashMap;
7
8import schedframe.scheduling.tasks.Job;
9import schedframe.scheduling.tasks.JobInterface;
10import schedframe.scheduling.tasks.Task;
11import schedframe.scheduling.tasks.TaskInterface;
12
13
14public abstract class AbstractJobRegistry /*extends ConcurrentHashMap<String, Job>*/ implements JobRegistry, Cloneable{
15       
16        private static final long serialVersionUID = 8409060063583755824L;
17
18       
19        protected static final ConcurrentHashMap<String, JobInterface<?>> jobs = new ConcurrentHashMap<String, JobInterface<?>>();
20       
21        protected AbstractJobRegistry(){
22        }
23       
24        public boolean addJob(JobInterface<?> job) {
25                jobs.put(job.getId(), job);
26                return true;
27        }
28
29        public boolean addTask(TaskInterface<?> task) {
30                if(jobs.containsKey(task.getJobId())){
31                        getJob(task.getJobId()).add((Task)task);
32                        return true;
33                } else {
34                        return false;
35                }
36        }
37
38        public JobInterface<?> getJobInfo(String jobId) {
39                return jobs.get(jobId);
40        }
41
42        public TaskInterface<?> getTaskInfo(String jobId, String taskId) {
43                Task task = null;
44                Job job = getJob(jobId);
45               
46                if(job == null)
47                        return null;
48               
49                try {
50                        task = job.getTask(taskId);
51                } catch (NoSuchFieldException e) {
52                }
53                return task;
54        }
55       
56        public Job getJob(String jobId){
57                return (Job)jobs.get(jobId);
58        }
59       
60        public List<JobInterface<?>> getJobs(){
61                List<JobInterface<?>> jobList = new ArrayList<JobInterface<?>>();
62                for(String jobId:jobs.keySet()) {
63                        jobList.add(jobs.get(jobId));
64                }
65                return jobList;
66        }
67
68        public List<JobInterface<?>> getJobs(int status) {
69                List<JobInterface<?>> jobList = new ArrayList<JobInterface<?>>();
70                synchronized (jobs) {
71                        for(String jobId:jobs.keySet()){
72                                JobInterface<?> job = jobs.get(jobId);
73                                if (job.getStatus() == status) {
74                                        jobList.add(job);
75                                }
76                        }
77                }
78                return jobList;
79        }
80
81}
Note: See TracBrowser for help on using the repository browser.