Java 7 WatchService - Ignoring multiple occurrences of the same event

后端 未结 14 632
情歌与酒
情歌与酒 2020-12-05 02:21

The javadoc for StandardWatchEventKinds.ENTRY_MODIFY says:

Directory entry modified. When a directory is registered for this event the

14条回答
  •  执念已碎
    2020-12-05 02:53

    If you are trying the same in Scala using better-files-akka library, I have comeup with this work around based on the solution proposed in the accepted answer.

    https://github.com/pathikrit/better-files/issues/313

    trait ConfWatcher {
    
      implicit def actorSystem: ActorSystem
    
      private val confPath = "/home/codingkapoor/application.conf"
      private val appConfFile = File(confPath)
      private var appConfLastModified = appConfFile.lastModifiedTime
    
      val watcher: ActorRef = appConfFile.newWatcher(recursive = false)
    
      watcher ! on(EventType.ENTRY_MODIFY) { file =>
        if (appConfLastModified.compareTo(file.lastModifiedTime) < 0) {
          // TODO
          appConfLastModified = file.lastModifiedTime
        }
      }
    
    }
    

提交回复
热议问题