@Override public WatchService newWatchService() throws IOException { return delegate.newWatchService(); } }
public InterpreterOutputChangeWatcher(InterpreterOutputChangeListener listener) throws IOException { watcher = FileSystems.getDefault().newWatchService(); this.listener = listener; }
@Override public void beforeStart() throws Exception { watchService = FileSystems.getDefault().newWatchService(); }
private void doStart() throws IOException { this.service = FileSystems.getDefault().newWatchService(); this.running = true; result = executor.submit(new Runnable() { @Override public void run() { while (running) { loop(); } doStop(); } }); }
WatchServiceFileSystemWatcher(final String name, final boolean daemon) { try { watchService = FileSystems.getDefault().newWatchService(); } catch (IOException e) { throw new RuntimeException(e); } watchThread = new Thread(this, THREAD_NAME + "[" + name + "]-" + threadIdCounter); watchThread.setDaemon(daemon); watchThread.start(); }
@Override public FileWatcher fileWatcher() throws IOException { WatchService watchService = FileSystems.getDefault().newWatchService(); return new DefaultFileSystemWatcher( watchService ); }
@Override public FileWatcher fileWatcher() throws IOException { return new DefaultFileSystemWatcher( fs.newWatchService() ); }
public FileChangeDetector(String dirPath) throws IOException{ watcher = FileSystems.getDefault().newWatchService(); registerAll(Paths.get(dirPath)); }
public FileChangeDetector(String dirPath) throws IOException{ watcher = FileSystems.getDefault().newWatchService(); registerAll(Paths.get(dirPath)); }
DirWatcher(AttemptRegistrationListener listener) throws IOException { this.watchService = FileSystems.getDefault().newWatchService(); this.listener = listener; ExecutorService executor1 = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("DirWatcher").build()); watcherExecutorService = MoreExecutors.listeningDecorator(executor1); ExecutorService executor2 = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("WatchExpirer").build()); expirerExecutorService = MoreExecutors.listeningDecorator(executor2); }
public FileSystemWatcher(String[] classPath) throws IOException { watchService = FileSystems.getDefault().newWatchService(); for (String entry : classPath) { Path path = Paths.get(entry); File file = path.toFile(); if (file.exists()) { if (file.isDirectory()) { register(path); } } } }
public Watcher(final ExecutorService executor, final BiConsumer<Kind<?>, Path> listener, final Path... dirs) throws IOException { this.watcher = FileSystems.getDefault().newWatchService(); this.keys = new HashMap<>(); this.listener = listener; for (Path dir : dirs) { registerAll(dir); } this.executor = executor; }
public WatchAndRestartMachine( Set<Path> directoriesToRecursivelyWatch, Set<String> includes, Set<String> excludes, DelayedRestartTrigger restartTrigger) throws IOException { this.watchService = FileSystems.getDefault().newWatchService(); this.mapOfWatchKeysToPaths = new HashMap<>(); this.includes = includes; this.excludes = excludes; this.restartTrigger = restartTrigger; this.takeCount = new AtomicInteger(0); for (Path path: directoriesToRecursivelyWatch) { registerAll(path); } }
WatcherThread(FilesystemChangeListener change, Collection<String> targetFolders, boolean recursive) { this.onChange = change; this.recursive = recursive; for (String folder : targetFolders) { this.folders.add(new File(folder).getAbsolutePath()); } setName("watcher" + idGen.incrementAndGet()); try { watchService = FileSystems.getDefault().newWatchService(); } catch (IOException e) { throw U.rte("Couldn't create a file system watch service!", e); } }
@Override public void configure(final Env env, final Config conf, final Binder binder) throws Throwable { this.watcher = FileSystems.getDefault().newWatchService(); binder.bind(WatchService.class).toInstance(watcher); List<FileEventOptions> paths = new ArrayList<>(); paths(env.getClass().getClassLoader(), conf, "filewatcher.register", options -> paths.add(register(binder, options))); for (Throwing.Function2<Config, Binder, FileEventOptions> binding : bindings) { paths.add(binding.apply(conf, binder)); } binder.bind(FileMonitor.class).asEagerSingleton(); paths.forEach(it -> log.info("Watching: {}", it)); }
/** * Creates a watcher that watches <code>dirPath</code> and invokes <code>callback</code> on changes. * * @param dirPath the directory to watch. * @param callback the callback to invoke with events. <code>event.kind()</code> will return the type of event, * and <code>event.context()</code> will return the filename relative to <code>dirPath</code>. * @throws IOException if there is an error creating the WatchService. */ public FileChangeWatcher(Path dirPath, Consumer<WatchEvent<?>> callback) throws IOException { FileSystem fs = dirPath.getFileSystem(); WatchService watchService = fs.newWatchService(); if (LOG.isDebugEnabled()) { LOG.debug("Registering with watch service: " + dirPath); } dirPath.register( watchService, new WatchEvent.Kind<?>[]{ StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.OVERFLOW}, SensitivityWatchEventModifier.HIGH); state = State.NEW; this.watcherThread = new WatcherThread(watchService, callback); this.watcherThread.setDaemon(true); }
public Watcher(final BiConsumer<Kind<?>, Path> listener, final Path... dirs) throws IOException { this.watcher = FileSystems.getDefault().newWatchService(); this.keys = new HashMap<>(); this.listener = listener; for (Path dir : dirs) { registerAll(dir); } this.scanner = new Thread(() -> { boolean process = true; while (!stopped && process) { process = processEvents(); } }, "HotswapScanner"); scanner.setDaemon(true); }
@Test void delegatedFileSystemWatcher() throws IOException { FileSystem fileSystem = mock(FileSystem.class); try ( DelegateFileSystemAbstraction abstraction = new DelegateFileSystemAbstraction( fileSystem ) ) { assertNotNull( abstraction.fileWatcher() ); } verify( fileSystem ).newWatchService(); } }
final File dir = new File(DIR); dir.mkdirs(); try (final WatchService watcher = FileSystems.getDefault().newWatchService()) { WatchKey key = dir.toPath().register(watcher, StandardWatchEventKinds.ENTRY_CREATE);
@Test void registerMultipleDirectoriesForMonitoring() throws Exception { try ( DefaultFileSystemWatcher watcher = new DefaultFileSystemWatcher( FileSystems.getDefault().newWatchService() ) ) { File directory1 = testDirectory.directory( "test1" ); File directory2 = testDirectory.directory( "test2" ); WatchedResource watchedResource1 = watcher.watch( directory1 ); WatchedResource watchedResource2 = watcher.watch( directory2 ); assertNotSame( watchedResource1, watchedResource2 ); } }