Java 7 NIO notification
Java 7 NIO notification
Igazából ide nincs milyen példát felhozni, hiszen csaknem ugyan az, mint a JPathwatch. Szinte csak az importokat kell lecserélni.
Jellemzője:
- java 7. Még friss és sokáig tipikusan a üzleti alkalmazásoknál nem fognak gyorsan váltani.
- alapból nem kezeli a rekurzív könyvtár vizsgálatot.
- a többi kb a JPathwatch-nál leírtak.
Rekurzív könyvtárvizsgálat
Ugyan alapbül nem támogatja, de azért természetesen megoldható. A WatchDir.java példában következő módon:
1 /** 2 * Register the given directory with the WatchService 3 */ 4 private void register(Path dir) throws IOException { 5 WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY); 6 if (trace) { 7 Path prev = keys.get(key); 8 if (prev == null) { 9 System.out.format("register: %s\n", dir); 10 } else { 11 if (!dir.equals(prev)) { 12 System.out.format("update: %s -> %s\n", prev, dir); 13 } 14 } 15 } 16 keys.put(key, dir); 17 } 18 19 /** 20 * Register the given directory, and all its sub-directories, with the 21 * WatchService. 22 */ 23 private void registerAll(final Path start) throws IOException { 24 // register directory and sub-directories 25 Files.walkFileTree(start, new SimpleFileVisitor<Path>() { 26 @Override 27 public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) 28 throws IOException 29 { 30 register(dir); 31 return FileVisitResult.CONTINUE; 32 } 33 }); 34 }
További kapcsolódó linkek:
- FolderListener for JDK7 – Watch folder events more elegantly.
- FilesystemAlterationMonitor Talán nem is ezzel megvalósítva, de a teljes képhez az a Apache Commons project is érdekes.
Directory Watcher
- Mi az a Directory Watcher?
- Java directory watcher
- JNotify
- JPathwatch
- Java 7 NIO notification
- Pollozó megoldás
- Groovy directory diff
- Groovy pollozó megoldás
Apr 20, 2012
comments powered by Disqus