1 43 package net.jforum.summary; 44 45 import java.io.IOException ; 46 import java.text.ParseException ; 47 48 import net.jforum.util.preferences.ConfigKeys; 49 import net.jforum.util.preferences.SystemGlobals; 50 51 import org.apache.log4j.Logger; 52 import org.quartz.CronTrigger; 53 import org.quartz.JobDetail; 54 import org.quartz.Scheduler; 55 import org.quartz.SchedulerException; 56 import org.quartz.Trigger; 57 import org.quartz.impl.StdSchedulerFactory; 58 59 67 public class SummaryScheduler 68 { 69 private static Scheduler scheduler; 70 71 private static Logger logger = Logger.getLogger(SummaryScheduler.class); 72 73 private static boolean isStarted = false; 74 75 83 public static void startJob() throws SchedulerException, IOException 84 { 85 boolean isEnabled = new Boolean (SystemGlobals.getValue(ConfigKeys.SUMMARY_IS_ENABLED)).booleanValue(); 86 87 if (!isStarted && isEnabled) { 88 String filename = SystemGlobals.getValue(ConfigKeys.SEARCH_INDEXER_QUARTZ_CONFIG); 89 90 SystemGlobals.loadAdditionalDefaults(filename); 91 92 String cronExpression = SystemGlobals.getValue("org.quartz.context.summary.cron.expression"); 93 scheduler = new StdSchedulerFactory(filename).getScheduler(); 94 95 Trigger trigger = null; 96 97 try { 98 trigger = new CronTrigger(SummaryJob.class.getName(), "summaryJob", cronExpression); 99 logger.info("Starting quartz summary expression " + cronExpression); 100 scheduler.scheduleJob(new JobDetail(SummaryJob.class.getName(), "summaryJob", SummaryJob.class), 101 trigger); 102 scheduler.start(); 103 } 104 catch (ParseException e) { 105 e.printStackTrace(); 106 } 107 } 108 109 isStarted = true; 110 } 111 } 112 | Popular Tags |