|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| package org.objectledge.scheduler.db; |
|
30 |
| |
|
31 |
| import java.util.Iterator; |
|
32 |
| import java.util.List; |
|
33 |
| |
|
34 |
| import org.jcontainer.dna.Configuration; |
|
35 |
| import org.jcontainer.dna.Logger; |
|
36 |
| import org.objectledge.ComponentInitializationError; |
|
37 |
| import org.objectledge.database.persistence.Persistence; |
|
38 |
| import org.objectledge.database.persistence.PersistenceException; |
|
39 |
| import org.objectledge.database.persistence.Persistent; |
|
40 |
| import org.objectledge.database.persistence.PersistentFactory; |
|
41 |
| import org.objectledge.scheduler.AbstractJobDescriptor; |
|
42 |
| import org.objectledge.scheduler.AbstractScheduler; |
|
43 |
| import org.objectledge.scheduler.JobModificationException; |
|
44 |
| import org.objectledge.scheduler.Schedule; |
|
45 |
| import org.objectledge.scheduler.ScheduleFactory; |
|
46 |
| import org.objectledge.threads.ThreadPool; |
|
47 |
| import org.picocontainer.MutablePicoContainer; |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| public class DBScheduler extends AbstractScheduler |
|
55 |
| implements PersistentFactory |
|
56 |
| { |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| protected Persistence persistence; |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
460
| public DBScheduler(
|
|
73 |
| MutablePicoContainer container, |
|
74 |
| Configuration config, |
|
75 |
| Logger logger, |
|
76 |
| ThreadPool threadPool, |
|
77 |
| ScheduleFactory[] scheduleFactories, |
|
78 |
| Persistence persistence) |
|
79 |
| { |
|
80 |
460
| super(container, config, logger, threadPool, scheduleFactories);
|
|
81 |
460
| this.persistence = persistence;
|
|
82 |
| } |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
1426
| public Persistent newInstance()
|
|
91 |
| { |
|
92 |
1426
| DBJobDescriptor job = new DBJobDescriptor(persistence, this);
|
|
93 |
1426
| return (Persistent)job;
|
|
94 |
| } |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
184
| public synchronized AbstractJobDescriptor createJobDescriptor(String name,
|
|
102 |
| Schedule schedule, String jobClassName) |
|
103 |
| throws JobModificationException |
|
104 |
| { |
|
105 |
184
| if (jobs.get(name) != null)
|
|
106 |
| { |
|
107 |
46
| throw new IllegalArgumentException("job " + name + " already exists");
|
|
108 |
| } |
|
109 |
138
| DBJobDescriptor job = null;
|
|
110 |
138
| try
|
|
111 |
| { |
|
112 |
138
| job = (DBJobDescriptor)newInstance();
|
|
113 |
| } |
|
114 |
| catch (Exception e) |
|
115 |
| { |
|
116 |
0
| throw new JobModificationException("failed to create instance", e);
|
|
117 |
| } |
|
118 |
138
| job.init(name, schedule, jobClassName);
|
|
119 |
138
| jobs.put(name, job);
|
|
120 |
138
| try
|
|
121 |
| { |
|
122 |
138
| persistence.save(job);
|
|
123 |
| } |
|
124 |
| catch (PersistenceException e) |
|
125 |
| { |
|
126 |
0
| throw new JobModificationException("failed to save new job", e);
|
|
127 |
| } |
|
128 |
138
| return job;
|
|
129 |
| } |
|
130 |
| |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
46
| public synchronized void deleteJobDescriptor(AbstractJobDescriptor job)
|
|
135 |
| throws JobModificationException |
|
136 |
| { |
|
137 |
46
| if (jobs.get(job.getName()) == null)
|
|
138 |
| { |
|
139 |
0
| throw new IllegalArgumentException("unregistered job " + job.getName());
|
|
140 |
| } |
|
141 |
46
| jobs.remove(job.getName());
|
|
142 |
46
| try
|
|
143 |
| { |
|
144 |
46
| persistence.delete((Persistent)job);
|
|
145 |
| } |
|
146 |
| catch (PersistenceException e) |
|
147 |
| { |
|
148 |
0
| throw new JobModificationException("failed to delete job", e);
|
|
149 |
| } |
|
150 |
| } |
|
151 |
| |
|
152 |
| |
|
153 |
| |
|
154 |
| |
|
155 |
46
| public boolean allowsModifications()
|
|
156 |
| { |
|
157 |
46
| return true;
|
|
158 |
| } |
|
159 |
| |
|
160 |
| |
|
161 |
| |
|
162 |
| |
|
163 |
460
| protected void loadJobs()
|
|
164 |
| { |
|
165 |
460
| try
|
|
166 |
| { |
|
167 |
460
| List jobList = persistence.load(null, this);
|
|
168 |
460
| Iterator i = jobList.iterator();
|
|
169 |
460
| while (i.hasNext())
|
|
170 |
| { |
|
171 |
828
| AbstractJobDescriptor job = (AbstractJobDescriptor)i.next();
|
|
172 |
828
| jobs.put(job.getName(), job);
|
|
173 |
| } |
|
174 |
| } |
|
175 |
| catch (PersistenceException e) |
|
176 |
| { |
|
177 |
| |
|
178 |
| throw new ComponentInitializationError("Failed to load jobs ", e); |
|
179 |
| |
|
180 |
| } |
|
181 |
| } |
|
182 |
| } |