@EnableScheduling @Controller public class FileWatcher extends Object implements org.springframework.beans.factory.DisposableBean
This class used for watching on file modified event Also class uses Spring Scheduling mechanism for periodically checking files
| Modifier and Type | Class and Description |
|---|---|
static class |
FileWatcher.FileRecord
File watcher record
|
| Constructor and Description |
|---|
FileWatcher()
Creates a new instance of the
FileWatcher class. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(File file,
FileWatcherEvent event)
Add new file watcher
|
void |
destroy()
Destroying watcher
|
boolean |
fileIsModified(File file)
Check if file is modified
|
WatchService |
getWatcher() |
boolean |
isClosed() |
boolean |
isOverflowed() |
void |
scheduleModifiedFiles()
Process modify events by schedule
|
void |
setClosed(boolean closed) |
public FileWatcher()
throws IOException
FileWatcher class.IOException - If an I/O error occurspublic boolean add(File file, FileWatcherEvent event)
file - fileevent - event which occurs on file modificationBoolean true if watcher is added, otherwise falsepublic boolean fileIsModified(File file)
Method compares file lastModified value and lastModified which added on watcher creation If difference between this two values is greater than FILE_MODIFY_THRESHOLD then method returns true, otherwise false
FILE_MODIFY_THRESHOLD used because when file is modifying it modifies twice:
file - file@Scheduled(fixedDelayString="2000") public void scheduleModifiedFiles()
FILE_MODIFY_DELAY used for set schedule repeat delay
public boolean isClosed()
public void setClosed(boolean closed)
public WatchService getWatcher()
public void destroy()
throws IOException
destroy in interface org.springframework.beans.factory.DisposableBeanIOException - if this watch service is closedpublic boolean isOverflowed()
Copyright © 2019. All rights reserved.