Package io.pravega.common.io.filesystem
Class FileModificationPollingMonitor
- java.lang.Object
-
- io.pravega.common.io.filesystem.FileModificationPollingMonitor
-
- All Implemented Interfaces:
FileModificationMonitor
public class FileModificationPollingMonitor extends java.lang.Object implements FileModificationMonitor
Monitors for modifications to the specified file using a polling-based mechanism and performs the specified action (in the form of a callback) upon detection of a file modification. UnlikeFileModificationEventWatcher, which doesn't work for monitoring modifications to a file which is a symbolic link to another file, an object of this class works for such files as well. However, since this object uses a polling-based mechanism - unlike the event-based mechanism used byFileModificationEventWatcher, lists files on each iteration and compares the output, this object is highly likely to be less efficient than an object ofFileModificationEventWatcher- CPU cycles-wise.
-
-
Constructor Summary
Constructors Constructor Description FileModificationPollingMonitor(@NonNull java.nio.file.Path fileToWatch, @NonNull java.util.function.Consumer<java.io.File> callback)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetPollingInterval()voidstartMonitoring()Start monitoring.voidstopMonitoring()Stop monitoring.
-
-
-
Constructor Detail
-
FileModificationPollingMonitor
public FileModificationPollingMonitor(@NonNull @NonNull java.nio.file.Path fileToWatch, @NonNull @NonNull java.util.function.Consumer<java.io.File> callback) throws java.io.FileNotFoundExceptionCreates a new instance.- Parameters:
fileToWatch- the file to watchcallback- the callback to invoke when a modification to thefileToWatchis detected- Throws:
java.nio.file.InvalidPathException- iffileToWatchis invalidjava.io.FileNotFoundException- when a file at specified pathfileToWatchdoes not existjava.lang.NullPointerException- if eitherfileToWatchorcallbackis null
-
-
Method Detail
-
startMonitoring
public void startMonitoring()
Description copied from interface:FileModificationMonitorStart monitoring.- Specified by:
startMonitoringin interfaceFileModificationMonitor
-
stopMonitoring
public void stopMonitoring()
Description copied from interface:FileModificationMonitorStop monitoring.- Specified by:
stopMonitoringin interfaceFileModificationMonitor
-
getPollingInterval
public int getPollingInterval()
-
-