01: /*
02: * Created on 09/10/2006 21:30:35
03: */
04: package net.jforum.api.integration.mail.pop;
05:
06: import java.text.ParseException;
07:
08: import net.jforum.util.preferences.ConfigKeys;
09: import net.jforum.util.preferences.SystemGlobals;
10:
11: import org.apache.log4j.Logger;
12: import org.quartz.CronTrigger;
13: import org.quartz.JobDetail;
14: import org.quartz.Scheduler;
15: import org.quartz.SchedulerException;
16: import org.quartz.Trigger;
17: import org.quartz.impl.StdSchedulerFactory;
18:
19: /**
20: * @author Rafael Steil
21: * @version $Id: POPJobStarter.java,v 1.1 2006/10/10 00:40:53 rafaelsteil Exp $
22: */
23: public class POPJobStarter {
24: private static boolean isStarted;
25: private static Scheduler scheduler;
26: private static Logger logger = Logger
27: .getLogger(POPJobStarter.class);
28:
29: public static void startJob() throws SchedulerException {
30: boolean isEnabled = SystemGlobals
31: .getBoolValue(ConfigKeys.MAIL_POP3_INTEGRATION_ENABLED);
32:
33: if (!isStarted && isEnabled) {
34: String filename = SystemGlobals
35: .getValue(ConfigKeys.QUARTZ_CONFIG);
36:
37: String cronExpression = SystemGlobals
38: .getValue("org.quartz.context.mailintegration.cron.expression");
39: scheduler = new StdSchedulerFactory(filename)
40: .getScheduler();
41:
42: Trigger trigger = null;
43:
44: try {
45: trigger = new CronTrigger(POPListener.class.getName(),
46: "pop3Integration", cronExpression);
47: logger.info("Starting POP3 integration expression "
48: + cronExpression);
49: scheduler.scheduleJob(new JobDetail(POPListener.class
50: .getName(), "pop3Integration",
51: POPListener.class), trigger);
52: scheduler.start();
53: } catch (ParseException e) {
54: e.printStackTrace();
55: }
56: }
57:
58: isStarted = true;
59: }
60: }
|