Class FileWatcher
- java.lang.Object
-
- com.inductiveautomation.ignition.common.lifecycle.AbstractLifecycle
-
- com.inductiveautomation.perspective.gateway.files.FileWatcher
-
public class FileWatcher extends AbstractLifecycle
Creates aWatchService
from the injectedFileSystem
and registers it to the injectedPath
to watch. When started, instances of this class will schedule polling tasks on the injectedSchedulerAbstraction
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 aFileWatcher.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 respectiveFileWatcher.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 aFileWatcher.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 aFileWatcher.FileWatchEventType.REGISTER
event type and a null path.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FileWatcher.FileWatchEventType
Represents 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 void
onShutdown()
protected void
onStartup()
-
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
- TheFileSystem
which has the injected path which will be watchedpathToWatch
- ThePath
to watchscheduler
- TheSchedulerAbstraction
used to schedule polling taskslistener
- TheBiConsumer
listener 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:
onStartup
in classAbstractLifecycle
-
onShutdown
protected void onShutdown()
- Specified by:
onShutdown
in classAbstractLifecycle
-
-