Package org.aoju.bus.core.io.watcher
Class DelayWatcher
java.lang.Object
org.aoju.bus.core.io.watcher.DelayWatcher
- All Implemented Interfaces:
Watcher
延迟观察者 使用此观察者通过定义一定的延迟时间,解决
WatchService多个modify的问题 在监听目录或文件时,如果这个文件有修改操作,会多次触发modify方法
此类通过维护一个Set将短时间内相同文件多次modify的事件合并处理触发,从而避免以上问题- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidonCreate(WatchEvent<?> event, Path currentPath) 文件创建时执行的方法voidonDelete(WatchEvent<?> event, Path currentPath) 文件删除时执行的方法voidonModify(WatchEvent<?> event, Path currentPath) 文件修改时执行的方法 文件修改可能触发多次voidonOverflow(WatchEvent<?> event, Path currentPath) 事件丢失或出错时执行的方法
-
Constructor Details
-
DelayWatcher
构造- Parameters:
watcher- 实际处理触发事件的监视器Watcher,不可以是DelayWatcherdelay- 延迟时间,单位毫秒
-
-
Method Details
-
onModify
Description copied from interface:Watcher文件修改时执行的方法 文件修改可能触发多次 -
onCreate
Description copied from interface:Watcher文件创建时执行的方法 -
onDelete
Description copied from interface:Watcher文件删除时执行的方法 -
onOverflow
Description copied from interface:Watcher事件丢失或出错时执行的方法- Specified by:
onOverflowin interfaceWatcher- Parameters:
event- 事件currentPath- 事件发生的当前Path路径
-