@Test public void udpateFile() throws Exception { File filename = File.createTempFile("file.", ".csv"); PrintWriter writer = new PrintWriter(filename); writer.println("Name,Value"); writer.println("Andrew,34"); writer.println("Bob,12"); writer.close(); latch = new CountDownLatch(1); FileWatcherFileSystemService service = new FileWatcherFileSystemService(exec, Duration.ofMillis(100)); service.addWatcher(filename, task); latch.await(1000, TimeUnit.MILLISECONDS); assertThat(latch.getCount(), equalTo(1L)); writer = new PrintWriter(new BufferedWriter(new FileWriter(filename))); writer.println("Charlie,71"); writer.close(); latch.await(10000, TimeUnit.MILLISECONDS); assertThat(latch.getCount(), equalTo(0L)); }
@Override public void addWatcher(File file, Runnable callback) { try { registrations.add(new Registration(file, callback)); } catch (IOException ex) { log.log(Level.WARNING, "Notifications won't be enable for file " + file, ex); } }
FileWatcherFileSystemService implements FileWatcherService { @Override public void addWatcher(File file, Runnable callback) { try { registrations.add(new Registration(file, callback)); } catch (IOException ex) { log.log(Level.WARNING, "Notifications won't be enable for file " + file, ex); } } }
FileWatcherFileSystemService implements FileWatcherService { @Override public void addWatcher(File file, Runnable callback) { try { registrations.add(new Registration(file, callback)); } catch (IOException ex) { log.log(Level.WARNING, "Notifications won't be enable for file " + file, ex); } } FileWatcherFileSystemService(ScheduledExecutorService exec, Duration scanRate); }
FileWatcherFileSystemService implements FileWatcherService { @Override public void addWatcher(File file, Runnable callback) { try { registrations.add(new Registration(file, callback)); } catch (IOException ex) { log.log(Level.WARNING, "Notifications won't be enable for file " + file, ex); } } FileWatcherFileSystemService(ScheduledExecutorService exec, Duration scanRate); @Override void addWatcher(File file, Runnable callback); @Override void removeWatcher(File file, Runnable callback); }
FileWatcherFileSystemService implements FileWatcherService { @Override public void addWatcher(File file, Runnable callback) { try { registrations.add(new Registration(file, callback)); } catch (IOException ex) { log.log(Level.WARNING, "Notifications won't be enable for file " + file, ex); } } FileWatcherFileSystemService(ScheduledExecutorService exec, Duration scanRate); @Override void addWatcher(File file, Runnable callback); @Override void removeWatcher(File file, Runnable callback);  }