1 25 26 package net.killingar.quartz; 27 28 import net.killingar.Utils; 29 import org.quartz.CronTrigger; 30 import org.quartz.JobDetail; 31 import org.quartz.Scheduler; 32 import org.quartz.SchedulerException; 33 import org.quartz.impl.StdSchedulerFactory; 34 35 import javax.servlet.ServletException ; 36 import java.util.Iterator ; 37 import java.util.Map ; 38 import java.util.Properties ; 39 40 44 45 public class WebworkInitServlet extends org.quartz.ee.servlet.QuartzInitializerServlet 46 { 47 public void init(javax.servlet.ServletConfig config) throws ServletException 48 { 49 super.init(config); 50 51 System.err.println("INFO: SKForum loading jobs..."); 52 53 try 54 { 55 Properties jobs = Utils.getProperties("quartz-webwork"); 57 58 Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); 59 60 for (Iterator i = jobs.entrySet().iterator(); i.hasNext(); ) 61 { 62 Map.Entry entry = (Map.Entry )i.next(); 63 64 try 65 { 66 String name = (String )entry.getKey(); 67 68 System.err.println("INFO: SKForum loading schedule job "+name+" ('"+entry.getValue()+"')"); 69 70 CronTrigger trigger = new CronTrigger(name+" trigger", name+" group", (String )entry.getValue()); 71 JobDetail jobDetail = new JobDetail(name, name+" group", WebworkJob.class); 72 73 Map m = jobDetail.getJobDataMap(); 75 Properties properties = Utils.getProperties("quartz-webwork/"+name); 76 for (Iterator j = properties.entrySet().iterator(); j.hasNext(); ) 77 { 78 Map.Entry entry2 = (Map.Entry )j.next(); 79 80 m.put(entry2.getKey(), entry2.getValue()); 81 82 System.err.println("INFO: property: "+entry2.getKey()+"="+entry2.getValue()); 83 } 84 85 scheduler.scheduleJob(jobDetail, trigger); 86 } 87 catch (java.text.ParseException e) 88 { 89 e.printStackTrace(); 90 } 91 } 92 102 } 103 catch (SchedulerException e) 104 { 105 e.printStackTrace(); 106 throw new ServletException (e); 107 } 108 } 109 } 110 | Popular Tags |