forked from geodmms/xdgnjobs

?? ?
2008-08-05 264ace6a491c915f47c61d49ef12bd08d8b5cce3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.ximple.eofms;
 
import java.util.Date;
 
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.TriggerUtils;
import org.quartz.impl.StdSchedulerFactory;
 
import com.ximple.eofms.jobs.OracleConvertDgn2ShpJob;
 
/**
 * Hello world!
 */
public class XQuartzJobCarrier
{
    static Log logger = LogFactory.getLog(XQuartzJobCarrier.class);
 
    public static void main(String[] args)
    {
        XQuartzJobCarrier instance = new XQuartzJobCarrier();
        instance.startScheduler();
    }
 
    public void startScheduler()
    {
        Scheduler scheduler = null;
        boolean shutdown = false;
 
        try
        {
            // Get a Scheduler instance from the Factory
            scheduler = StdSchedulerFactory.getDefaultScheduler();
 
            // Start the scheduler
            scheduler.start();
            logger.info("Scheduler started at " + new Date());
 
        } catch (SchedulerException ex)
        {
            // deal with any exceptions
            logger.error(ex);
            shutdown = true;
        } catch (Throwable throwable)
        {
            logger.error(throwable.getMessage(), throwable);
            shutdown = true;
        }
        if (shutdown)
        {
            try
            {
                scheduler.shutdown();
            } catch (SchedulerException e)
            {
                logger.error(e.getMessage(), e);
            }
        }
    }
 
    /*
     * return an instance of the Scheduler from the factory
     */
    public Scheduler createScheduler() throws SchedulerException
    {
        return StdSchedulerFactory.getDefaultScheduler();
    }
 
    // Create and Schedule a ScanDirectoryJob with the Scheduler
    private void scheduleJob(Scheduler scheduler) throws SchedulerException
    {
 
        // Create a JobDetail for the Job
        JobDetail jobDetail = new JobDetail("ScanDirectory", Scheduler.DEFAULT_GROUP,
                OracleConvertDgn2ShpJob.class);
 
        // Configure the directory to scan
        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");
        // Start the trigger firing from now
        trigger.setStartTime(new Date());
 
        // Associate the trigger with the job in the scheduler
        scheduler.scheduleJob(jobDetail, trigger);
    }
 
}