| | |
| | | package com.ximple.eofms; |
| | | |
| | | import java.util.Date; |
| | | import javax.swing.JFrame; |
| | | import javax.swing.SwingUtilities; |
| | | import java.util.Date; |
| | | |
| | | import org.apache.commons.cli.CommandLine; |
| | | import org.apache.commons.cli.CommandLineParser; |
| | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.awl.Wizard; |
| | | import org.quartz.DateBuilder; |
| | | import org.quartz.JobBuilder; |
| | | import org.quartz.JobDetail; |
| | | import org.quartz.Scheduler; |
| | | import org.quartz.SchedulerException; |
| | | import org.quartz.Trigger; |
| | | import org.quartz.TriggerBuilder; |
| | | import org.quartz.TriggerUtils; |
| | | import org.quartz.impl.JobDetailImpl; |
| | | import org.quartz.impl.StdSchedulerFactory; |
| | | |
| | | import com.ximple.eofms.jobs.OracleConvertDgn2ShpJob; |
| | |
| | | /** |
| | | * Hello world! |
| | | */ |
| | | public class XQuartzJobCarrier |
| | | { |
| | | public class XQuartzJobCarrier { |
| | | static Log logger = LogFactory.getLog(XQuartzJobCarrier.class); |
| | | static Options options = new Options(); |
| | | |
| | | private static final String VERSION = "0.9.0"; |
| | | private static final String VERSION = "1.3.1"; |
| | | |
| | | public static void main(String[] args) |
| | | { |
| | | public static void main(String[] args) { |
| | | XQuartzJobCarrier instance = new XQuartzJobCarrier(); |
| | | instance.initializeOption(); |
| | | instance.execute(args); |
| | | } |
| | | |
| | | private void initializeOption() |
| | | { |
| | | private void initializeOption() { |
| | | Option option; |
| | | option = OptionBuilder.create("help"); |
| | | option.setDescription("print this message"); |
| | |
| | | |
| | | } |
| | | |
| | | private void execute(String[] args) |
| | | { |
| | | private void execute(String[] args) { |
| | | // CommandLineParser parser = new GnuParser(); |
| | | CommandLineParser parser = new PosixParser(); |
| | | CommandLine commandLine = null; |
| | | try |
| | | { |
| | | try { |
| | | // parse the command commandLine arguments |
| | | commandLine = parser.parse(options, args); |
| | | } |
| | | catch (ParseException exp) |
| | | { |
| | | catch (ParseException exp) { |
| | | // oops, something went wrong |
| | | System.err.println("Parsing failed. Reason: " + exp.getMessage()); |
| | | } |
| | | |
| | | if ((commandLine != null) && (commandLine.getOptions().length > 0)) |
| | | { |
| | | if (commandLine.hasOption("help")) |
| | | { |
| | | if ((commandLine != null) && (commandLine.getOptions().length > 0)) { |
| | | if (commandLine.hasOption("help")) { |
| | | printHelpMessage(); |
| | | } else if (commandLine.hasOption("version")) |
| | | { |
| | | } else if (commandLine.hasOption("version")) { |
| | | printVersionMessage(); |
| | | } else if (commandLine.hasOption("wizard")) |
| | | { |
| | | } else if (commandLine.hasOption("wizard")) { |
| | | startWizardMode(); |
| | | } |
| | | return; |
| | |
| | | startScheduler(); |
| | | } |
| | | |
| | | private void printHelpMessage() |
| | | { |
| | | private void printHelpMessage() { |
| | | HelpFormatter formatter = new HelpFormatter(); |
| | | formatter.printHelp("XQuartzJobCarrier", options); |
| | | } |
| | | |
| | | private void printVersionMessage() |
| | | { |
| | | private void printVersionMessage() { |
| | | System.out.println("XQuartzJobCarrier - " + VERSION); |
| | | } |
| | | |
| | | public void startWizardMode() |
| | | { |
| | | Runnable runnable = new Runnable() |
| | | { |
| | | public void run() |
| | | { |
| | | public void startWizardMode() { |
| | | Runnable runnable = new Runnable() { |
| | | public void run() { |
| | | Wizard wizard = new XQuartzJobWizard((JFrame) null); |
| | | |
| | | wizard.pack(); |
| | | wizard.setVisibleOnCenterOfScreen(); |
| | | } |
| | | }; |
| | | try |
| | | { |
| | | try { |
| | | SwingUtilities.invokeLater(runnable); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public void startScheduler() |
| | | { |
| | | public void startScheduler() { |
| | | Scheduler scheduler = null; |
| | | boolean shutdown = false; |
| | | |
| | | try |
| | | { |
| | | try { |
| | | // Get a Scheduler instance from the Factory |
| | | scheduler = StdSchedulerFactory.getDefaultScheduler(); |
| | | |
| | |
| | | scheduler.start(); |
| | | logger.info("Scheduler started at " + new Date()); |
| | | |
| | | } catch (SchedulerException ex) |
| | | { |
| | | } catch (SchedulerException ex) { |
| | | // deal with any exceptions |
| | | logger.error(ex); |
| | | logger.error(ex, ex); |
| | | shutdown = true; |
| | | } catch (Throwable throwable) |
| | | { |
| | | } catch (Throwable throwable) { |
| | | logger.error(throwable.getMessage(), throwable); |
| | | shutdown = true; |
| | | } |
| | | if (shutdown) |
| | | { |
| | | try |
| | | { |
| | | if (shutdown) { |
| | | try { |
| | | scheduler.shutdown(); |
| | | } catch (SchedulerException e) |
| | | { |
| | | } catch (SchedulerException e) { |
| | | logger.error(e.getMessage(), e); |
| | | } |
| | | } |
| | |
| | | /* |
| | | * return an instance of the Scheduler from the factory |
| | | */ |
| | | public Scheduler createScheduler() throws SchedulerException |
| | | { |
| | | public Scheduler createScheduler() throws SchedulerException { |
| | | return StdSchedulerFactory.getDefaultScheduler(); |
| | | } |
| | | |
| | | // Create and Schedule a ScanDirectoryJob with the Scheduler |
| | | private void scheduleJob(Scheduler scheduler) throws SchedulerException |
| | | { |
| | | private void scheduleJob(Scheduler scheduler) throws SchedulerException { |
| | | |
| | | // Create a JobDetail for the Job |
| | | JobDetail jobDetail = new JobDetail("ScanDirectory", Scheduler.DEFAULT_GROUP, |
| | | OracleConvertDgn2ShpJob.class); |
| | | |
| | | /* |
| | | JobDetailImpl jobDetail = new JobDetailImpl("ScanDirectory", Scheduler.DEFAULT_GROUP, |
| | | OracleConvertDgn2ShpJob.class); |
| | | */ |
| | | JobDetail jobDetail = JobBuilder.newJob(OracleConvertDgn2ShpJob.class) |
| | | .withIdentity("ScanDirectory", Scheduler.DEFAULT_GROUP) |
| | | .usingJobData("SCAN_DIR", "c:\\quartz-book\\input") |
| | | .build(); |
| | | // Configure the directory to scan |
| | | jobDetail.getJobDataMap().put("SCAN_DIR", "c:\\quartz-book\\input"); |
| | | // jobDetail.getJobDataMap().put("SCAN_DIR", "c:\\quartz-book\\input"); |
| | | |
| | | // Create a trigger that fires every 10 seconds, forever |
| | | Trigger trigger = TriggerUtils.makeSecondlyTrigger(10); |
| | | trigger.setName("scanTrigger"); |
| | | // Trigger trigger = TriggerUtils.makeSecondlyTrigger(10); |
| | | // trigger.setName("scanTrigger"); |
| | | Trigger trigger = TriggerBuilder.newTrigger().withIdentity("scanTrigger") |
| | | .startAt(DateBuilder.futureDate(10, DateBuilder.IntervalUnit.SECOND)) |
| | | .build(); |
| | | // Start the trigger firing from now |
| | | trigger.setStartTime(new Date()); |
| | | // trigger.setStartTime(new Date()); |
| | | |
| | | // Associate the trigger with the job in the scheduler |
| | | scheduler.scheduleJob(jobDetail, trigger); |