1 16 package org.quartz.listeners; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import org.quartz.utils.Key; 22 import org.quartz.JobExecutionContext; 23 import org.quartz.JobExecutionException; 24 import org.quartz.SchedulerException; 25 26 44 public class JobChainingJobListener extends JobListenerSupport { 45 46 private String name; 47 private Map chainLinks; 48 49 50 55 public JobChainingJobListener(String name) { 56 if(name == null) 57 throw new IllegalArgumentException ("Listener name cannot be null!"); 58 this.name = name; 59 chainLinks = new HashMap (); 60 } 61 62 public String getName() { 63 return name; 64 } 65 66 73 public void addJobChainLink(Key firstJob, Key secondJob) { 74 75 if(firstJob == null || secondJob == null) 76 throw new IllegalArgumentException ("Key cannot be null!"); 77 if(firstJob.getName() == null || secondJob.getName() == null) 78 throw new IllegalArgumentException ("Key cannot have a null name!"); 79 80 chainLinks.put(firstJob, secondJob); 81 } 82 83 public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) { 84 85 Key sj = (Key) chainLinks.get(context.getJobDetail().getKey()); 86 87 if(sj == null) 88 return; 89 90 getLog().info("Job '" + context.getJobDetail().getFullName() + "' will now chain to Job '" + sj + "'"); 91 92 try { 93 if(context.getJobDetail().isVolatile() || context.getTrigger().isVolatile()) 94 context.getScheduler().triggerJobWithVolatileTrigger(sj.getName(), sj.getGroup()); 95 else 96 context.getScheduler().triggerJob(sj.getName(), sj.getGroup()); 97 } 98 catch(SchedulerException se) { 99 getLog().error("Error encountered during chaining to Job '" + sj + "'", se); 100 } 101 } 102 } 103 104 | Popular Tags |