Class FileWatcher
- java.lang.Object
-
- com.inductiveautomation.ignition.common.lifecycle.AbstractLifecycle
-
- com.inductiveautomation.perspective.gateway.files.FileWatcher
-
public class FileWatcher extends AbstractLifecycle
Creates aWatchServicefrom the injectedFileSystemand registers it to the injectedPathto watch. When started, instances of this class will schedule polling tasks on the injectedSchedulerAbstractionto 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 aFileWatcher.FileWatchEventType.REGISTERevent 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 respectiveFileWatcher.FileWatchEventTypewill 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 aFileWatcher.FileWatchEventType.OVERFLOWevent 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 aFileWatcher.FileWatchEventType.REGISTERevent type and a null path.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFileWatcher.FileWatchEventTypeRepresents the types of file watch events which may occur
-
Constructor Summary
Constructors Constructor Description FileWatcher(java.nio.file.FileSystem fileSystem, java.nio.file.Path pathToWatch, SchedulerAbstraction scheduler, java.util.function.BiConsumer<FileWatcher.FileWatchEventType,java.nio.file.Path> listener)The primary constructor for creating instances of theFileWatcher.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidonShutdown()protected voidonStartup()-
Methods inherited from class com.inductiveautomation.ignition.common.lifecycle.AbstractLifecycle
isRunning, shutdown, startup
-
-
-
-
Constructor Detail
-
FileWatcher
public FileWatcher(@Nonnull java.nio.file.FileSystem fileSystem, @Nonnull java.nio.file.Path pathToWatch, @Nonnull SchedulerAbstraction scheduler, @Nonnull java.util.function.BiConsumer<FileWatcher.FileWatchEventType,java.nio.file.Path> listener)The primary constructor for creating instances of theFileWatcher.- Parameters:
fileSystem- TheFileSystemwhich has the injected path which will be watchedpathToWatch- ThePathto watchscheduler- TheSchedulerAbstractionused to schedule polling taskslistener- TheBiConsumerlistener which will be called when the watcher is registered with the path to watch and for any watch events which occur in the watched path per poll cycle
-
-
Method Detail
-
onStartup
protected void onStartup()
- Specified by:
onStartupin classAbstractLifecycle
-
onShutdown
protected void onShutdown()
- Specified by:
onShutdownin classAbstractLifecycle
-
-