1 43 package net.jforum.util.search.quartz; 44 45 import net.jforum.entities.Post; 46 import net.jforum.exceptions.SearchInstantiationException; 47 import net.jforum.util.preferences.ConfigKeys; 48 import net.jforum.util.preferences.SystemGlobals; 49 import net.jforum.util.search.SearchManager; 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.Trigger; 56 import org.quartz.impl.StdSchedulerFactory; 57 58 62 public class QuartzSearchManager implements SearchManager 63 { 64 private static Logger logger = Logger.getLogger(QuartzSearchManager.class); 65 private static Scheduler scheduler; 66 69 public void init() 70 { 71 try { 72 String filename = SystemGlobals.getValue(ConfigKeys.SEARCH_INDEXER_QUARTZ_CONFIG); 73 74 SystemGlobals.loadAdditionalDefaults(filename); 75 String cronExpression = SystemGlobals.getValue( 76 ConfigKeys.QUARTZ_CONTEXT + ConfigKeys.SEARCH_INDEXER_CRON_EXPRESSON); 77 78 scheduler = new StdSchedulerFactory(filename).getScheduler(); 79 Trigger trigger = new CronTrigger(QuartzSearchIndexerJob.class.getName(), 80 "indexer", 81 cronExpression); 82 83 logger.info("Starting quartz search manager using expression " + cronExpression); 84 85 scheduler.scheduleJob(new JobDetail(QuartzSearchIndexerJob.class.getName(), 86 "indexer", 87 QuartzSearchIndexerJob.class), 88 trigger); 89 scheduler.start(); 90 } 91 catch (Exception e) { 92 if (e.toString().indexOf("org.quartz.ObjectAlreadyExistsException") == -1) { 93 throw new SearchInstantiationException("Error while trying to start " + this.getClass().getName() + ": " + e); 94 } 95 } 96 } 97 98 101 public void index(Post post) {} 102 } 103 | Popular Tags |