public class ScanFTPSiteJob implements Job {
private static Log logger = LogFactory.getLog(ScanFTPSiteJob.class);
/*
* Called the scheduler framework at the right time
*/ public void execute(JobExecutionContext context)
throws JobExecutionException {
JobDataMap jobDataMap = context.getJobDataMap();
try {
// Check the ftp site for files
File[] files = JobUtil.checkForFiles(jobDataMap);
JobUtil.sendEmail(jobDataMap, files);
} catch (Exception ex) {
throw new JobExecutionException(ex.getMessage());
}
}}
public class MyQuartzServer {
public static void main(String[] args) {
MyQuartzServer server = new MyQuartzServer();
try {
server.startScheduler();
} catch (SchedulerException ex) {
ex.printStackTrace();
}
}
protected void startScheduler() throws SchedulerException {
// Use the factory to create a Scheduler instance
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
// JobDetail holds the definition for Jobs
JobDetail jobDetail = new JobDetail("ScanFTPJob", Scheduler.DEFAULT_GROUP,
ScanFTPSiteJob.class);// Store job parameters to be used within execute()jobDetail.getJobDataMap().put("FTP_HOST", "\\home\\cavaness\\inbound");
// Other neccessary Job parameters here
// Create a Trigger that fires every 60 seconds
Trigger trigger = TriggerUtils.makeSecondlyTrigger(60);
// Setup the Job and Trigger with the Scheduler
scheduler.scheduleJob(jobDetail, trigger );
// Start the Scheduler running
scheduler.start();
}}