@PostConstruct private void init() { ws = fs.newWatchService(); executorService.submit(new Runnable() { @Override public void run() { observeAndNotifyClients(); } }); }
private FileSystem registerFS(final FileSystem fs) { if (fs == null) { return fs; } if (ioWatchService != null && !ioWatchService.hasWatchService(fs)) { ioWatchService.addWatchService(fs, fs.newWatchService()); } fileSystems.add(new FileSystemMetadata(fs)); return fs; }
@PostConstruct public void setup() { Path defaultRoot = null; for (final Path path : fs.getRootDirectories()) { if (path.toUri().toString().contains("/master@")) { defaultRoot = path; break; } } if (defaultRoot == null) { throw new RuntimeException("Could not resolve 'systemFS' main root directory."); } // enable monitor by default if (System.getProperty(MONITOR_DISABLED) == null) { watchService = fs.newWatchService(); configUpdates = new CheckConfigurationUpdates(watchService); final ConfigServiceWatchServiceExecutor configServiceWatchServiceExecutor = getWatchServiceExecutor(); jobs.add(executorService.submit(new DescriptiveRunnable() { @Override public String getDescription() { return configUpdates.getDescription(); } @Override public void run() { configUpdates.execute(configServiceWatchServiceExecutor); } })); } }
@PostConstruct public void setup() { Path defaultRoot = null; for (final Path path : fs.getRootDirectories()) { if (path.toUri().toString().contains("/master@")) { defaultRoot = path; break; } } if (defaultRoot == null) { throw new RuntimeException("Could not resolve 'systemFS' main root directory."); } systemRepository.setRoot(convert(defaultRoot)); // enable monitor by default if (System.getProperty(MONITOR_DISABLED) == null) { watchService = fs.newWatchService(); configUpdates = new CheckConfigurationUpdates(watchService); final ConfigServiceWatchServiceExecutor configServiceWatchServiceExecutor = getWatchServiceExecutor(); jobs.add(executorService.submit(new DescriptiveRunnable() { @Override public String getDescription() { return configUpdates.getDescription(); } @Override public void run() { configUpdates.execute(configServiceWatchServiceExecutor); } })); } }
return; final WatchService ws = fs.newWatchService(); watchServicesByFS.put(fs.getName(), ws);
@Test public void recreatingFileSystemMakesNewWatchService() throws Exception { URI uri = new URI("test:///some/path"); Map<String, ?> env = Collections.emptyMap(); FileSystem fs1 = ioService.newFileSystem(uri, env); verify(fs1).newWatchService(); FSPath fsPath = mock(FSPath.class); when(fsPath.getFileSystem()).thenReturn(fs1); ioService.delete(fsPath); verify(fs1.newWatchService()).close(); FileSystem fs2 = ioService.newFileSystem(uri, env); // Stubs are reused so this will have been invoked one above in IOService, and once in this test in a verify method. verify(fs2, times(3)).newWatchService(); }
return; final WatchService ws = fs.newWatchService(); watchServicesByFS.put(fs.getName(), ws);
@Test public void recreatingFileSystemMakesNewWatchService() throws Exception { URI uri = new URI("test:///some/path"); Map<String, ?> env = Collections.emptyMap(); FileSystem fs1 = ioService.newFileSystem(uri, env); verify(fs1).newWatchService(); FSPath fsPath = mock(FSPath.class); when(fsPath.getFileSystem()).thenReturn(fs1); ioService.delete(fsPath); verify(fs1.newWatchService()).close(); FileSystem fs2 = ioService.newFileSystem(uri, env); // Stubs are reused so this will have been invoked one above in IOService, and once in this test in a verify method. verify(fs2, times(3)).newWatchService(); }
env); WatchService ws = fs.newWatchService(); final Path path = fs.getRootDirectories().iterator().next(); path.register(ws,
env); WatchService ws = fs.newWatchService(); final Path path = fs.getRootDirectories().iterator().next(); path.register(ws,
@Test public void simpleWatcherTest() { final Path init = ioService.get(URI.create("git://amend-repo-test/dora1.txt")); final WatchService ws = init.getFileSystem().newWatchService(); ioService.write(init, "init!"); { List<WatchEvent<?>> events = ws.poll().pollEvents(); WatchEvent.Kind<?> kind = events.get(0).kind(); assertEquals(kind.name(), StandardWatchEventKind.ENTRY_CREATE.name()); assertEquals(1, events.size()); } ioService.write(init, "init 2!"); { List<WatchEvent<?>> events = ws.poll().pollEvents(); WatchEvent.Kind<?> kind = events.get(0).kind(); assertEquals(kind.name(), StandardWatchEventKind.ENTRY_MODIFY.name()); assertEquals(1, events.size()); } } }
@Test public void simpleWatcherTest() { final Path init = ioService.get(URI.create("git://amend-repo-test/dora1.txt")); final WatchService ws = init.getFileSystem().newWatchService(); ioService.write(init, "init!"); { List<WatchEvent<?>> events = ws.poll().pollEvents(); WatchEvent.Kind<?> kind = events.get(0).kind(); assertEquals(kind.name(), StandardWatchEventKind.ENTRY_CREATE.name()); assertEquals(1, events.size()); } ioService.write(init, "init 2!"); { List<WatchEvent<?>> events = ws.poll().pollEvents(); WatchEvent.Kind<?> kind = events.get(0).kind(); assertEquals(kind.name(), StandardWatchEventKind.ENTRY_MODIFY.name()); assertEquals(1, events.size()); } } }
final Path initMoved = ioService.get(URI.create("git://amend-repo-test/fileMoved.txt")); final WatchService ws = init.getFileSystem().newWatchService();
final Path initMoved = ioService.get(URI.create("git://amend-repo-test/fileMoved.txt")); final WatchService ws = init.getFileSystem().newWatchService();
@Test public void deleteOnBatchEventShouldKeepUserInfo() { final Path init = ioService.get(URI.create("git://amend-repo-test/file.txt")); final WatchService ws = init.getFileSystem().newWatchService(); String user = "dora"; String message = "message"; ioService.write(init, "init!", new CommentedOption(user, message)); { List<WatchEvent<?>> events = ws.poll().pollEvents(); } ioService.startBatch(init.getFileSystem()); ioService.delete(init, new CommentedOption(user, message)); ioService.endBatch(); { List<WatchEvent<?>> events = ws.poll().pollEvents(); JGitWatchEvent event = (JGitWatchEvent) events.get(0); WatchContext context = (WatchContext) event.context(); assertEquals(user, context.getUser()); } }
@Test public void deleteOnBatchEventShouldKeepUserInfo() { final Path init = ioService.get(URI.create("git://amend-repo-test/file.txt")); final WatchService ws = init.getFileSystem().newWatchService(); String user = "dora"; String message = "message"; ioService.write(init, "init!", new CommentedOption(user, message)); { List<WatchEvent<?>> events = ws.poll().pollEvents(); } ioService.startBatch(init.getFileSystem()); ioService.delete(init, new CommentedOption(user, message)); ioService.endBatch(); { List<WatchEvent<?>> events = ws.poll().pollEvents(); JGitWatchEvent event = (JGitWatchEvent) events.get(0); WatchContext context = (WatchContext) event.context(); assertEquals(user, context.getUser()); } }
@Test public void testBatch() throws IOException, InterruptedException { final Path init = ioService.get(URI.create("git://amend-repo-test/readme.txt")); final WatchService ws = init.getFileSystem().newWatchService();
@Test public void testBatch() throws IOException, InterruptedException { final Path init = ioService.get(URI.create("git://amend-repo-test/readme.txt")); final WatchService ws = init.getFileSystem().newWatchService();
final WatchService ws = f1.getFileSystem().newWatchService();
final WatchService ws = f1.getFileSystem().newWatchService();