@Test @Disabled void testListenToDirectory() throws IOException { final Path tempFolder = Files.createTempDirectory("configurate-test"); final Path test1 = tempFolder.resolve("test1"); final Path test2 = tempFolder.resolve("test2"); Files.createFile(test1); Files.createFile(test2); final AtomicReference<Path> lastPath = new AtomicReference<>(); final CyclicBarrier barrier = new CyclicBarrier(2); listener.listenToDirectory(tempFolder, event -> { if (event.context() instanceof Path) { lastPath.set((Path) event.context()); } else { throw new RuntimeException("Event " + event + " received, was not expected"); } try { barrier.await(); } catch (InterruptedException | BrokenBarrierException e) { throw new RuntimeException(e); } }); assertTimeout(Duration.ofMinutes(1), () -> { Files.write(test1, Collections.singleton("version one"), StandardOpenOption.SYNC); barrier.await(); assertEquals(test1.getFileName(), lastPath.get()); barrier.reset(); Files.write(test2, Collections.singleton("version two"), StandardOpenOption.SYNC); barrier.await(); assertEquals(test2.getFileName(), lastPath.get()); }); }
public Disposable listenToDirectory(Path directory, final Subscriber<WatchEvent<?>> callback) throws IOException, IllegalArgumentException { directory = directory.toAbsolutePath(); if (!(Files.isDirectory(directory) || !Files.exists(directory))) { throw new IllegalArgumentException("Path " + directory + " must be a directory"); } return getRegistration(directory).subscribe(callback); }
WatchServiceListener implements AutoCloseable { public Disposable listenToDirectory(Path directory, final Subscriber<WatchEvent<?>> callback) throws IOException, IllegalArgumentException { directory = directory.toAbsolutePath(); if (!(Files.isDirectory(directory) || !Files.exists(directory))) { throw new IllegalArgumentException("Path " + directory + " must be a directory"); } return getRegistration(directory).subscribe(callback); } }
WatchServiceListener implements AutoCloseable { public Disposable listenToDirectory(Path directory, final Subscriber<WatchEvent<?>> callback) throws IOException, IllegalArgumentException { directory = directory.toAbsolutePath(); if (!(Files.isDirectory(directory) || !Files.exists(directory))) { throw new IllegalArgumentException("Path " + directory + " must be a directory"); } return getRegistration(directory).subscribe(callback); } private  WatchServiceListener(final ThreadFactory factory, final FileSystem fileSystem, final Executor taskExecutor); }
WatchServiceListener implements AutoCloseable { public Disposable listenToDirectory(Path directory, final Subscriber<WatchEvent<?>> callback) throws IOException, IllegalArgumentException { directory = directory.toAbsolutePath(); if (!(Files.isDirectory(directory) || !Files.exists(directory))) { throw new IllegalArgumentException("Path " + directory + " must be a directory"); } return getRegistration(directory).subscribe(callback); } private  WatchServiceListener(final ThreadFactory factory, final FileSystem fileSystem, final Executor taskExecutor); static Builder builder(); static WatchServiceListener create(); Disposable listenToFile(Path file, final Subscriber<WatchEvent<?>> callback); Disposable listenToDirectory(Path directory, final Subscriber<WatchEvent<?>> callback); ConfigurationReference<N> listenToConfiguration(final Function<Path, ConfigurationLoader<? extends N>> loaderFunc, final Path path); @Override void close(); }
WatchServiceListener implements AutoCloseable { public Disposable listenToDirectory(Path directory, final Subscriber<WatchEvent<?>> callback) throws IOException, IllegalArgumentException { directory = directory.toAbsolutePath(); if (!(Files.isDirectory(directory) || !Files.exists(directory))) { throw new IllegalArgumentException("Path " + directory + " must be a directory"); } return getRegistration(directory).subscribe(callback); } private  WatchServiceListener(final ThreadFactory factory, final FileSystem fileSystem, final Executor taskExecutor); static Builder builder(); static WatchServiceListener create(); Disposable listenToFile(Path file, final Subscriber<WatchEvent<?>> callback); Disposable listenToDirectory(Path directory, final Subscriber<WatchEvent<?>> callback); ConfigurationReference<N> listenToConfiguration(final Function<Path, ConfigurationLoader<? extends N>> loaderFunc, final Path path); @Override void close();  }