Class DelayWatcher

java.lang.Object
org.aoju.bus.core.io.watcher.DelayWatcher
All Implemented Interfaces:
Watcher

public class DelayWatcher extends Object implements Watcher
延迟观察者 使用此观察者通过定义一定的延迟时间,解决WatchService多个modify的问题 在监听目录或文件时,如果这个文件有修改操作,会多次触发modify方法 此类通过维护一个Set将短时间内相同文件多次modify的事件合并处理触发,从而避免以上问题
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • DelayWatcher

      public DelayWatcher(Watcher watcher, long delay)
      构造
      Parameters:
      watcher - 实际处理触发事件的监视器Watcher,不可以是DelayWatcher
      delay - 延迟时间,单位毫秒
  • Method Details

    • onModify

      public void onModify(WatchEvent<?> event, Path currentPath)
      Description copied from interface: Watcher
      文件修改时执行的方法 文件修改可能触发多次
      Specified by:
      onModify in interface Watcher
      Parameters:
      event - 事件
      currentPath - 事件发生的当前Path路径
    • onCreate

      public void onCreate(WatchEvent<?> event, Path currentPath)
      Description copied from interface: Watcher
      文件创建时执行的方法
      Specified by:
      onCreate in interface Watcher
      Parameters:
      event - 事件
      currentPath - 事件发生的当前Path路径
    • onDelete

      public void onDelete(WatchEvent<?> event, Path currentPath)
      Description copied from interface: Watcher
      文件删除时执行的方法
      Specified by:
      onDelete in interface Watcher
      Parameters:
      event - 事件
      currentPath - 事件发生的当前Path路径
    • onOverflow

      public void onOverflow(WatchEvent<?> event, Path currentPath)
      Description copied from interface: Watcher
      事件丢失或出错时执行的方法
      Specified by:
      onOverflow in interface Watcher
      Parameters:
      event - 事件
      currentPath - 事件发生的当前Path路径