org.quartz.jobs
Class DirectoryScanJob

java.lang.Object
  extended by org.quartz.jobs.DirectoryScanJob
All Implemented Interfaces:
Job

@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class DirectoryScanJob
extends java.lang.Object
implements Job

Inspects a directory and compares whether any files' "last modified dates" have changed since the last time it was inspected. If one or more files have been updated (or created), the job invokes a "call-back" method on an identified DirectoryScanListener that can be found in the SchedulerContext.

Author:
pl47ypus, jhouse
See Also:
DirectoryScanListener, SchedulerContext

Field Summary
static java.lang.String DIRECTORY_NAME
          JobDataMap key with which to specify the directory to be monitored - an absolute path is recommended.
static java.lang.String DIRECTORY_SCAN_LISTENER_NAME
          JobDataMap key with which to specify the DirectoryScanListener to be notified when the directory contents change.
static java.lang.String MINIMUM_UPDATE_AGE
          JobDataMap key with which to specify a long value that represents the minimum number of milliseconds that must have past since the file's last modified time in order to consider the file new/altered.
 
Constructor Summary
DirectoryScanJob()
           
 
Method Summary
 void execute(JobExecutionContext context)
           Called by the Scheduler when a Trigger fires that is associated with the Job.
protected  java.io.File[] getUpdatedOrNewFiles(java.lang.String dirName, long lastDate, long maxAgeDate)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIRECTORY_NAME

public static final java.lang.String DIRECTORY_NAME
JobDataMap key with which to specify the directory to be monitored - an absolute path is recommended.

See Also:
Constant Field Values

DIRECTORY_SCAN_LISTENER_NAME

public static final java.lang.String DIRECTORY_SCAN_LISTENER_NAME
JobDataMap key with which to specify the DirectoryScanListener to be notified when the directory contents change.

See Also:
Constant Field Values

MINIMUM_UPDATE_AGE

public static final java.lang.String MINIMUM_UPDATE_AGE
JobDataMap key with which to specify a long value that represents the minimum number of milliseconds that must have past since the file's last modified time in order to consider the file new/altered. This is necessary because another process may still be in the middle of writing to the file when the scan occurs, and the file may therefore not yet be ready for processing.

If this parameter is not specified, a default value of 5000 (five seconds) will be used.

See Also:
Constant Field Values
Constructor Detail

DirectoryScanJob

public DirectoryScanJob()
Method Detail

execute

public void execute(JobExecutionContext context)
             throws JobExecutionException
Description copied from interface: Job

Called by the Scheduler when a Trigger fires that is associated with the Job.

The implementation may wish to set a result object on the JobExecutionContext before this method exits. The result itself is meaningless to Quartz, but may be informative to JobListeners or TriggerListeners that are watching the job's execution.

Specified by:
execute in interface Job
Throws:
JobExecutionException - if there is an exception while executing the job.
See Also:
Job.execute(org.quartz.JobExecutionContext)

getUpdatedOrNewFiles

protected java.io.File[] getUpdatedOrNewFiles(java.lang.String dirName,
                                              long lastDate,
                                              long maxAgeDate)


Copyright 2001-2019, Terracotta, Inc.