1 2 18 19 22 package org.quartz; 23 24 import java.util.HashSet ; 25 import java.util.Set ; 26 27 import org.apache.commons.collections.SetUtils; 28 import org.quartz.utils.Key; 29 30 59 public class JobDetail implements Cloneable , java.io.Serializable { 60 61 68 69 private String name; 70 71 private String group = Scheduler.DEFAULT_GROUP; 72 73 private String description; 74 75 private Class jobClass; 76 77 private JobDataMap jobDataMap; 78 79 private boolean volatility = false; 80 81 private boolean durability = false; 82 83 private boolean shouldRecover = false; 84 85 private Set jobListeners = SetUtils.orderedSet(new HashSet ()); 86 87 private transient Key key = null; 88 89 96 97 109 public JobDetail() { 110 } 112 113 124 public JobDetail(String name, String group, Class jobClass) { 125 setName(name); 126 setGroup(group); 127 setJobClass(jobClass); 128 } 129 130 141 public JobDetail(String name, String group, Class jobClass, 142 boolean volatility, boolean durability, boolean recover) { 143 setName(name); 144 setGroup(group); 145 setJobClass(jobClass); 146 setVolatility(volatility); 147 setDurability(durability); 148 setRequestsRecovery(recover); 149 } 150 151 158 159 164 public String getName() { 165 return name; 166 } 167 168 176 public void setName(String name) { 177 if (name == null || name.trim().length() == 0) { 178 throw new IllegalArgumentException ("Job name cannot be empty."); 179 } 180 181 this.name = name; 182 } 183 184 189 public String getGroup() { 190 return group; 191 } 192 193 203 public void setGroup(String group) { 204 if (group != null && group.trim().length() == 0) { 205 throw new IllegalArgumentException ( 206 "Group name cannot be empty."); 207 } 208 209 if (group == null) { 210 group = Scheduler.DEFAULT_GROUP; 211 } 212 213 this.group = group; 214 } 215 216 222 public String getFullName() { 223 return group + "." + name; 224 } 225 226 public Key getKey() { 227 if(key == null) { 228 key = new Key(getName(), getGroup()); 229 } 230 231 return key; 232 } 233 234 242 public String getDescription() { 243 return description; 244 } 245 246 253 public void setDescription(String description) { 254 this.description = description; 255 } 256 257 262 public Class getJobClass() { 263 return jobClass; 264 } 265 266 274 public void setJobClass(Class jobClass) { 275 if (jobClass == null) { 276 throw new IllegalArgumentException ("Job class cannot be null."); 277 } 278 279 if (!Job.class.isAssignableFrom(jobClass)) { 280 throw new IllegalArgumentException ( 281 "Job class must implement the Job interface."); 282 } 283 284 this.jobClass = jobClass; 285 } 286 287 292 public JobDataMap getJobDataMap() { 293 if (jobDataMap == null) { 294 jobDataMap = new JobDataMap(); 295 } 296 return jobDataMap; 297 } 298 299 304 public void setJobDataMap(JobDataMap jobDataMap) { 305 this.jobDataMap = jobDataMap; 306 } 307 308 317 public void validate() throws SchedulerException { 318 if (name == null) { 319 throw new SchedulerException("Job's name cannot be null", 320 SchedulerException.ERR_CLIENT_ERROR); 321 } 322 323 if (group == null) { 324 throw new SchedulerException("Job's group cannot be null", 325 SchedulerException.ERR_CLIENT_ERROR); 326 } 327 328 if (jobClass == null) { 329 throw new SchedulerException("Job's class cannot be null", 330 SchedulerException.ERR_CLIENT_ERROR); 331 } 332 } 333 334 345 public void setVolatility(boolean volatility) { 346 this.volatility = volatility; 347 } 348 349 359 public void setDurability(boolean durability) { 360 this.durability = durability; 361 } 362 363 376 public void setRequestsRecovery(boolean shouldRecover) { 377 this.shouldRecover = shouldRecover; 378 } 379 380 394 public boolean isVolatile() { 395 return volatility; 396 } 397 398 411 public boolean isDurable() { 412 return durability; 413 } 414 415 420 public boolean isStateful() { 421 if (jobClass == null) { 422 return false; 423 } 424 425 return (StatefulJob.class.isAssignableFrom(jobClass)); 426 } 427 428 441 public boolean requestsRecovery() { 442 return shouldRecover; 443 } 444 445 451 public void addJobListener(String name) { 452 if (jobListeners.add(name) == false) { 453 throw new IllegalArgumentException ( 454 "Job listener '" + name + "' is already registered for job detail: " + getFullName()); 455 } 456 } 457 458 466 public boolean removeJobListener(String name) { 467 return jobListeners.remove(name); 468 } 469 470 477 public String [] getJobListenerNames() { 478 return (String [])jobListeners.toArray(new String [jobListeners.size()]); 479 } 480 481 486 public String toString() { 487 return "JobDetail '" + getFullName() + "': jobClass: '" 488 + ((getJobClass() == null) ? null : getJobClass().getName()) 489 + " isStateful: " + isStateful() + " isVolatile: " 490 + isVolatile() + " isDurable: " + isDurable() 491 + " requestsRecovers: " + requestsRecovery(); 492 } 493 494 public Object clone() { 495 JobDetail copy; 496 try { 497 copy = (JobDetail) super.clone(); 498 copy.jobListeners = SetUtils.orderedSet(new HashSet (jobListeners)); 499 if (jobDataMap != null) { 500 copy.jobDataMap = (JobDataMap) jobDataMap.clone(); 501 } 502 } catch (CloneNotSupportedException ex) { 503 throw new IncompatibleClassChangeError ("Not Cloneable."); 504 } 505 506 return copy; 507 } 508 } 509 | Popular Tags |