Package gov.usgs.util

Class DirectoryPoller


  • public class DirectoryPoller
    extends java.lang.Object
    Monitor a directory for files, notifying FileListenerInterfaces. Implementers of the FileListenerInterface should process files before returning, because these files may move or disappear.
    • Constructor Detail

      • DirectoryPoller

        public DirectoryPoller​(java.io.File pollDirectory,
                               java.io.File storageDirectory)
        Create a DirectoryPoller.
        Parameters:
        pollDirectory - directory that is polled for new files.
        storageDirectory - directory where polled files are moved. When null, polled files are deleted after calling listeners.
    • Method Detail

      • getPollDirectory

        public java.io.File getPollDirectory()
        Returns:
        pollDirectory file
      • getStorageDirectory

        public java.io.File getStorageDirectory()
        Returns:
        storageDirectory file
      • addFileListener

        public void addFileListener​(FileListenerInterface listener)
        Parameters:
        listener - FileListenerInterface to add
      • removeFileListener

        public void removeFileListener​(FileListenerInterface listener)
        Parameters:
        listener - FileListenerInterface to remove
      • start

        public void start​(long frequencyInMilliseconds)
        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).
        Parameters:
        frequencyInMilliseconds - how often to poll.
      • stop

        public void stop()
        Stop any currently scheduled polling.
      • notifyListeners

        public void notifyListeners​(java.io.File file)
        Notify all listeners that files exist and need to be processed.
        Parameters:
        file - that needs to be processed