Class JobLogFileWatcher
- java.lang.Object
-
- br.pucrio.tecgraf.soma.job.log.watcher.impl.JobLogFileWatcher
-
- All Implemented Interfaces:
IFileWatcher,IWatcher,Closeable,AutoCloseable
public class JobLogFileWatcher extends Object implements IFileWatcher
The Job Logs file watcher that watches for changes in files.
-
-
Constructor Summary
Constructors Constructor Description JobLogFileWatcher(IFileWatcher watcher)Constructor with a file watcher.JobLogFileWatcher(List<IFileWatchEventListener> listeners)Constructor with a list of listeners for test purposes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAllMonitoredFilePath(List<String> filePaths)voidaddFileWatchEventListener(IFileWatchEventListener listener)voidaddMonitoredFilePath(String filePath)voidclose()List<String>getMonitoredFilePaths()protected StringgetParentFilePath(List<String> fileStrPaths)Get and check parent files from file list.booleanisMonitoredFilePathsEmpty()booleanisWatching()voidregister()Watch a list of file for changes.voidregister(String dirStrPath, FileFilter filter)voidremoveFileWatchEventListener(IFileWatchEventListener listener)voidremoveMonitoredFilePath(String filePath)voidstartWatch()voidstopWatch()
-
-
-
Constructor Detail
-
JobLogFileWatcher
public JobLogFileWatcher(List<IFileWatchEventListener> listeners)
Constructor with a list of listeners for test purposes.- Parameters:
watchService-listeners-
-
JobLogFileWatcher
public JobLogFileWatcher(IFileWatcher watcher)
Constructor with a file watcher.- Parameters:
watchService-listeners-
-
-
Method Detail
-
register
public void register() throws IOExceptionWatch a list of file for changes.- Throws:
IOException- Exception in register
-
getParentFilePath
protected String getParentFilePath(List<String> fileStrPaths)
Get and check parent files from file list.- Parameters:
fileStrPaths- file list to be watched.- Returns:
- The parent file string path or an exception in case of any files are not siblings.
-
addMonitoredFilePath
public void addMonitoredFilePath(String filePath)
-
removeMonitoredFilePath
public void removeMonitoredFilePath(String filePath)
-
isMonitoredFilePathsEmpty
public boolean isMonitoredFilePathsEmpty()
-
startWatch
public void startWatch() throws InterruptedException- Specified by:
startWatchin interfaceIFileWatcher- Throws:
InterruptedException
-
stopWatch
public void stopWatch() throws Exception- Specified by:
stopWatchin interfaceIFileWatcher- Throws:
Exception
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
register
public void register(String dirStrPath, FileFilter filter) throws IOException
- Specified by:
registerin interfaceIFileWatcher- Throws:
IOException
-
addFileWatchEventListener
public void addFileWatchEventListener(IFileWatchEventListener listener)
- Specified by:
addFileWatchEventListenerin interfaceIFileWatcher
-
removeFileWatchEventListener
public void removeFileWatchEventListener(IFileWatchEventListener listener)
- Specified by:
removeFileWatchEventListenerin interfaceIFileWatcher
-
isWatching
public boolean isWatching()
- Specified by:
isWatchingin interfaceIFileWatcher
-
-