Package gov.usgs.util

Class DirectoryPoller

All Implemented Interfaces:
Configurable, Poller

public class DirectoryPoller extends DefaultConfigurable implements Poller
Monitor a directory for files, notifying FileListenerInterfaces. Implementers of the FileListenerInterface should process files before returning, because these files may move or disappear.
  • Field Details

    • POLL_CAREFULLY_PROPERTY

      public static final String POLL_CAREFULLY_PROPERTY
      Property for pollCarefully
      See Also:
    • DEFAULT_POLL_CAREFULLY

      public static final String DEFAULT_POLL_CAREFULLY
      Default status of POLL_CAREFULLY
      See Also:
    • POLL_DIRECTORY_PROPERTY

      public static final String POLL_DIRECTORY_PROPERTY
      Property for pollDirectory
      See Also:
    • DEFAULT_POLL_DIRECTORY

      public static final String DEFAULT_POLL_DIRECTORY
      Default pollDirectory
      See Also:
    • ERROR_DIRECTORY_PROPERTY

      public static final String ERROR_DIRECTORY_PROPERTY
      Property for errorDirectory
      See Also:
    • DEFAULT_ERROR_DIRECTORY

      public static final String DEFAULT_ERROR_DIRECTORY
      Default errorDirectory
      See Also:
    • STORAGE_DIRECTORY_PROPERTY

      public static final String STORAGE_DIRECTORY_PROPERTY
      Property for storageDirectory
      See Also:
    • DEFAULT_STORAGE_DIRECTORY

      public static final String DEFAULT_STORAGE_DIRECTORY
      Default storageDirectory
      See Also:
    • POLLINTERVAL_PROPERTY

      public static final String POLLINTERVAL_PROPERTY
      Poll interval property
      See Also:
    • DEFAULT_POLLINTERVAL

      public static final String DEFAULT_POLLINTERVAL
      Default interval for POLLINTERVAL
      See Also:
  • Constructor Details

    • DirectoryPoller

      public DirectoryPoller()
      Create a DirectoryPoller.
  • Method Details

    • configure

      public void configure(Config config) throws Exception
      Description copied from class: DefaultConfigurable
      Process configuration settings. Called before startup().
      Specified by:
      configure in interface Configurable
      Overrides:
      configure in class DefaultConfigurable
      Parameters:
      config - the Config object with settings.
      Throws:
      Exception - if configuration exceptions occur.
    • addFileListener

      public void addFileListener(FileListenerInterface listener)
      Specified by:
      addFileListener in interface Poller
      Parameters:
      listener - FileListenerInterface to add
    • removeFileListener

      public void removeFileListener(FileListenerInterface listener)
      Specified by:
      removeFileListener in interface Poller
      Parameters:
      listener - FileListenerInterface to remove
    • notifyListeners

      public void notifyListeners(File file)
      Notify all listeners that files exist and need to be processed.
      Specified by:
      notifyListeners in interface Poller
      Parameters:
      file - that needs to be processed
    • start

      public void start()
      Start polling in a background thread. Any previously scheduled polling is stopped before starting at this frequency. This schedules using fixed-delay (time between complete polls) as opposed to fixed-rate (how often to start polling).
      Specified by:
      start in interface Poller
    • stop

      public void stop()
      Stop any currently scheduled polling.
      Specified by:
      stop in interface Poller
    • getPollDirectory

      public File getPollDirectory()
      Returns:
      pollDirectory file
    • getStorageDirectory

      public File getStorageDirectory()
      Returns:
      storageDirectory file
    • setStorageDirectory

      public void setStorageDirectory(File storageDirectory)
    • getErrorDirectory

      public File getErrorDirectory()
      Returns:
      errorDirectory
    • setErrorDirectory

      public void setErrorDirectory(File errorDirectory)
      Parameters:
      errorDirectory - File to send
    • getPollInterval

      public Long getPollInterval()
      Returns:
      pollInterval long
    • setPollInterval

      public void setPollInterval(long pollInterval)
      Parameters:
      pollInterval - long to set
    • isPollCarefully

      public Boolean isPollCarefully()
      Returns:
      pollCarefully boolean
    • setPollCarefully

      public void setPollCarefully(boolean pollCarefully)
      Parameters:
      pollCarefully - boolean to set