Package com.seeq.utilities
Class FileWatcher
java.lang.Object
com.seeq.utilities.FileWatcher
Monitors a directory for changes to a specific file and notifies the listener of any changes to the file.
-
Constructor Summary
ConstructorsConstructorDescriptionFileWatcher
(Path directory, String file, FileChangeListener listener, Duration debouncePeriod) Constructor for the file watcher. -
Method Summary
-
Constructor Details
-
FileWatcher
public FileWatcher(Path directory, @Nullable String file, FileChangeListener listener, Duration debouncePeriod) Constructor for the file watcher. Note thatstart()
must be called to begin watching for changes to the directory.- Parameters:
directory
- The directory to watch for changes. Created if it does not exist.file
- The name of the file to watch for changes. If null, the whole directory is monitored for changes.listener
- The listener that is invoked upon the file being changed.debouncePeriod
- The period to wait before notifying the listener. If an additional change happens during this period, then the debouncePeriod clock is reset and another debouncePeriod must elapse before the listener is notified.
-
-
Method Details
-
start
Start watching the API key file by spawning a new thread.- Throws:
IOException
- Thrown when the directory cannot be created or watched.
-
stop
public void stop()Stop this thread. The killing happens lazily, giving the running thread an opportunity to finish the work at hand. -
isRunning
public boolean isRunning()Determines whether or not the watcher service is running.- Returns:
- True if the watcher is running, false otherwise
-