java.lang.Object
com.inductiveautomation.ignition.common.lifecycle.AbstractLifecycle
com.inductiveautomation.perspective.gateway.files.FileWatcher

public class FileWatcher extends AbstractLifecycle
Creates a WatchService from the injected FileSystem and registers it to the injected Path to watch. When started, instances of this class will schedule polling tasks on the injected SchedulerAbstraction to check whether or not the directory represented by the injected path to watch exists and is a valid directory and if so, will start watching that directory and will call the injected listener with a FileWatcher.FileWatchEventType.REGISTER event type and a null path, else it will continue polling until the directory is created or it is shut down. Once the directory is being watched, if a file was created, modified, or deleted in the watched directory in between each poll cycle, then the respective FileWatcher.FileWatchEventType will be passed to the injected listener along with the full path to the file for each watch event which occurred for that poll cycle. If there is an overflow of events from the FileSystem, the injected listener will be called with a FileWatcher.FileWatchEventType.OVERFLOW event type and a null path. This watcher handles the case where the path to watch is deleted while it is being watched. In this case, it falls back to the above mentioned behavior when the watcher is started up and the path to watch does not represent a directory or does not exist. If the path to watch is re-created as a valid directory, the watcher will resume watching the path for changes and will notify the listener with a FileWatcher.FileWatchEventType.REGISTER event type and a null path.