List of usage examples for java.nio.file StandardWatchEventKinds ENTRY_MODIFY
WatchEvent.Kind ENTRY_MODIFY
To view the source code for java.nio.file StandardWatchEventKinds ENTRY_MODIFY.
Click Source Link
From source file:org.springframework.cloud.gcp.stream.binder.pubsub.PubSubEmulator.java
private void startEmulator() throws IOException, InterruptedException { boolean configPresent = Files.exists(EMULATOR_CONFIG_PATH); WatchService watchService = null; if (configPresent) { watchService = FileSystems.getDefault().newWatchService(); EMULATOR_CONFIG_DIR.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY); }//from w w w . jav a 2 s . c o m try { this.emulatorProcess = new ProcessBuilder("gcloud", "beta", "emulators", "pubsub", "start").start(); } catch (IOException ex) { fail("Gcloud not found; leaving host/port uninitialized."); } if (configPresent) { updateConfig(watchService); watchService.close(); } else { createConfig(); } }
From source file:com.reactivetechnologies.platform.rest.dll.JarModuleLoader.java
private Set<File> filesFromEvents() throws InterruptedException { WatchKey key = watcher.take(); Set<File> files = new LinkedHashSet<File>(); if (key != null && key.isValid()) { for (WatchEvent<?> event : key.pollEvents()) { if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE || event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) { Path item = (Path) event.context(); File file = new File( ((Path) key.watchable()).toAbsolutePath() + File.separator + item.getFileName()); if (log.isDebugEnabled()) { log.debug("Watch Event: " + event.kind() + ": " + file); }/*w w w . j av a 2s. com*/ if (isJarFile(file)) { files.add(file); } else log.warn("[JAR Loader] Ignoring file " + file); } } key.reset(); } return files; }
From source file:jsonbrowse.JsonBrowse.java
private void startWatchThread() throws IOException { watcher = jsonFilePath.getFileSystem().newWatchService(); watchThread = new Thread(this, "FileWatcher"); watchThread.start();/*from w ww .j a v a2 s .c om*/ jsonFilePath.getParent().register(watcher, StandardWatchEventKinds.ENTRY_MODIFY); }
From source file:org.springframework.cloud.config.monitor.FileMonitorConfiguration.java
private Set<File> filesFromEvents() { Set<File> files = new LinkedHashSet<File>(); if (this.watcher == null) { return files; }//from w ww . j a va2 s . c o m WatchKey key = this.watcher.poll(); while (key != null) { for (WatchEvent<?> event : key.pollEvents()) { if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE || event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) { Path item = (Path) event.context(); File file = new File( ((Path) key.watchable()).toAbsolutePath() + File.separator + item.getFileName()); if (file.isDirectory()) { files.addAll(walkDirectory(file.toPath())); } else { if (!file.getPath().contains(".git") && !PatternMatchUtils.simpleMatch(this.excludes, file.getName())) { if (log.isDebugEnabled()) { log.debug("Watch Event: " + event.kind() + ": " + file); } files.add(file); } } } else if (event.kind() == StandardWatchEventKinds.OVERFLOW) { if (log.isDebugEnabled()) { log.debug("Watch Event: " + event.kind() + ": context: " + event.context()); } if (event.context() != null && event.context() instanceof Path) { files.addAll(walkDirectory((Path) event.context())); } else { for (Path path : this.directory) { files.addAll(walkDirectory(path)); } } } else { if (log.isDebugEnabled()) { log.debug("Watch Event: " + event.kind() + ": context: " + event.context()); } } } key.reset(); key = this.watcher.poll(); } return files; }
From source file:org.wso2.appserver.integration.tests.logging.accesslogs.HttpAccessLogTestCase.java
@Test(groups = "wso2.as", description = "Send GET and POST requests to generate http access logs and read " + "http access log files", dependsOnMethods = "testWebAppUpload") public void testWebAppResponse() throws Exception { //GET request HttpResponse response = HttpURLConnectionClient.sendGetRequest(getWebAppURL(WebAppTypes.WEBAPPS) + "/" + WEB_APP_NAME + "/services/test_access_log/simpleget?name=abc&domain=wso2.com", null); assertEquals(response.getResponseCode(), HttpStatus.SC_OK, "GET Request was not successful in user mode : " + userMode); //POST Request assertEquals(/* w ww . j av a 2 s . com*/ makePostRequest(getWebAppURL(WebAppTypes.WEBAPPS) + "/" + WEB_APP_NAME + "/services/test_access_log/simplepost").toString(), "hello abc", "POST Request was not successful in user mode : " + userMode); //Register a watch service to wait until log files are created WatchService watcher = FileSystems.getDefault().newWatchService(); Path filePath = Paths.get(logFileLocation); filePath.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY); long time = System.currentTimeMillis() + 30 * 1000; boolean isNewLogFilesAreCreated = false; while (!isNewLogFilesAreCreated && System.currentTimeMillis() < time) { WatchKey key; try { key = watcher.take(); } catch (InterruptedException ex) { return; } for (WatchEvent<?> event : key.pollEvents()) { WatchEvent.Kind<?> kind = event.kind(); if (kind == StandardWatchEventKinds.ENTRY_MODIFY) { if (request_log_file.exists() && response_log_file.exists() && variable_log_file.exists()) { isNewLogFilesAreCreated = true; break; } } } boolean valid = key.reset(); if (!valid) { break; } } }
From source file:org.apache.tomee.jul.handler.rotating.ArchivingTest.java
@SuppressWarnings("unchecked") @Test/*from w w w .java2 s . co m*/ public void logAndRotateAndPurge() throws Exception { clean("target/ArchivingTestPurge-" + format + "/logs"); final AtomicReference<String> today = new AtomicReference<>(); final Map<String, String> config = new HashMap<>(); // initial config today.set("2015-09-01"); config.put("filenamePattern", "target/ArchivingTestPurge-" + format + "/logs/test.%s.%d.log"); config.put("archiveDirectory", "target/ArchivingTestPurge-" + format + "/logs/archives"); config.put("archiveFormat", format); config.put("archiveOlderThan", "1 s"); config.put("purgeOlderThan", "2 s"); config.put("limit", "10 kilobytes"); config.put("level", "INFO"); config.put("dateCheckInterval", "1 second"); final LocalFileHandler handler = new LocalFileHandler() { @Override protected String currentDate() { return today.get(); } @Override protected String getProperty(final String name, final String defaultValue) { final String s = config.get(name.substring(name.lastIndexOf('.') + 1)); return s != null ? s : defaultValue; } }; final String string10chars = "abcdefghij"; final int iterations = 950; for (int i = 0; i < iterations; i++) { handler.publish(new LogRecord(Level.INFO, string10chars)); } today.set("2015-09-02"); try { Thread.sleep(2000); } catch (final InterruptedException e) { Thread.interrupted(); } final File logArchive = new File( "target/ArchivingTestPurge-" + format + "/logs/archives/test.2015-09-01.0.log." + format); final File parentFile = logArchive.getParentFile(); if (!parentFile.exists() && !parentFile.mkdirs()) { Assert.fail("Unable to create: " + parentFile); } final Path dir = parentFile.toPath(); final WatchService watcher = FileSystems.getDefault().newWatchService(); final WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_MODIFY); latch.set(new CountDownLatch(1)); watch(key); handler.publish(new LogRecord(Level.INFO, string10chars)); // will trigger the archiving assertTrue("Failed to get archived log", latch.get().await(20, TimeUnit.SECONDS)); final WatchEvent<?> watchEvent = lastEvent.get(); assertTrue(StandardWatchEventKinds.ENTRY_CREATE.equals(watchEvent.kind()) || StandardWatchEventKinds.ENTRY_MODIFY.equals(watchEvent.kind())); final WatchEvent<Path> ev = (WatchEvent<Path>) watchEvent; final String io = ev.context().toString(); assertTrue(io.startsWith("test.2015-09-01.") && io.endsWith(format)); today.set("2015-09-03"); try { Thread.sleep(2500); } catch (final InterruptedException e) { Thread.interrupted(); } handler.publish(new LogRecord(Level.INFO, string10chars)); // will trigger the purging handler.close(); withRetry(10, 2, new Runnable() { @Override public void run() { assertFalse(logArchive.getAbsolutePath() + " was purged", logArchive.exists()); } }); }
From source file:de.elomagic.carafile.client.CaraCloud.java
private void registerDefaultWatch(final Path path) throws IOException { path.register(watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE); }
From source file:org.springframework.cloud.config.monitor.FileMonitorConfiguration.java
private void registerWatch(Path dir) throws IOException { if (log.isDebugEnabled()) { log.debug("registering: " + dir + " for file creation events"); }//from ww w . j av a 2 s. c om try { dir.register(this.watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY); } catch (IOException e) { throw e; } catch (Exception e) { throw new IOException("Cannot register watcher for " + dir, e); } }
From source file:com.facebook.buck.util.ProjectFilesystemTest.java
@Test public void testCreateContextStringForModifyEvent() throws IOException { Path file = tmp.newFile("foo.txt").toPath(); WatchEvent<Path> modifyEvent = WatchEvents.createPathEvent(file, StandardWatchEventKinds.ENTRY_MODIFY); assertEquals(file.toAbsolutePath().toString(), filesystem.createContextString(modifyEvent)); }
From source file:ddf.camel.component.catalog.content.ContentProducerDataAccessObjectTest.java
@Test public void testCreateContentItem() throws Exception { File testFile = temporaryFolder.newFile("testCreateContentItem.txt"); // make sample list of metacard and set of keys List<MetacardImpl> metacardList = ImmutableList.of(new MetacardImpl()); String uri = testFile.toURI().toASCIIString(); Set<String> keys = new HashSet<>(Collections.singletonList(String.valueOf(DigestUtils.sha1Hex(uri)))); // mock out responses for create, delete, update CreateResponse mockCreateResponse = mock(CreateResponse.class); doReturn(metacardList).when(mockCreateResponse).getCreatedMetacards(); DeleteResponse mockDeleteResponse = mock(DeleteResponse.class); doReturn(metacardList).when(mockDeleteResponse).getDeletedMetacards(); UpdateResponse mockUpdateResponse = mock(UpdateResponse.class); doReturn(metacardList).when(mockUpdateResponse).getUpdatedMetacards(); // setup mockFileSystemPersistenceProvider FileSystemPersistenceProvider mockFileSystemPersistenceProvider = mock(FileSystemPersistenceProvider.class); doReturn(keys).when(mockFileSystemPersistenceProvider).loadAllKeys(); doAnswer(invocationOnMock -> keys.remove(invocationOnMock.getArguments()[0])) .when(mockFileSystemPersistenceProvider).delete(anyString()); doReturn("sample").when(mockFileSystemPersistenceProvider).loadFromPersistence(any(String.class)); // setup mockCatalogFramework CatalogFramework mockCatalogFramework = mock(CatalogFramework.class); doReturn(mockCreateResponse).when(mockCatalogFramework).create(any(CreateStorageRequest.class)); doReturn(mockDeleteResponse).when(mockCatalogFramework).delete(any(DeleteRequest.class)); // setup mockSourceInfo SourceInfoResponse mockSourceInfoResponse = mock(SourceInfoResponse.class); SourceDescriptor mockSourceDescriptor = mock(SourceDescriptor.class); when(mockSourceDescriptor.isAvailable()).thenReturn(true); when(mockSourceInfoResponse.getSourceInfo()).thenReturn(Collections.singleton(mockSourceDescriptor)); when(mockCatalogFramework.getSourceInfo(any(SourceInfoRequest.class))).thenReturn(mockSourceInfoResponse); // setup mockComponent ContentComponent mockComponent = mock(ContentComponent.class); doReturn(mockCatalogFramework).when(mockComponent).getCatalogFramework(); // setup mockEndpoint ContentEndpoint mockEndpoint = mock(ContentEndpoint.class); doReturn(mockComponent).when(mockEndpoint).getComponent(); WatchEvent.Kind<Path> kind; String mimeType = "txt"; Map<String, Object> headers = new HashedMap(); Map<String, Serializable> attributeOverrides = new HashMap<>(); attributeOverrides.put("example", ImmutableList.of("something", "something1")); attributeOverrides.put("example2", ImmutableList.of("something2")); headers.put(Constants.ATTRIBUTE_OVERRIDES_KEY, attributeOverrides); headers.put(Constants.STORE_REFERENCE_KEY, uri); kind = StandardWatchEventKinds.ENTRY_CREATE; contentProducerDataAccessObject.createContentItem(mockFileSystemPersistenceProvider, mockEndpoint, testFile, kind, mimeType, headers);// w w w . ja v a2 s .c o m verify(mockCatalogFramework).create(any(CreateStorageRequest.class)); kind = StandardWatchEventKinds.ENTRY_MODIFY; contentProducerDataAccessObject.createContentItem(mockFileSystemPersistenceProvider, mockEndpoint, testFile, kind, mimeType, headers); verify(mockCatalogFramework).update(any(UpdateStorageRequest.class)); kind = StandardWatchEventKinds.ENTRY_DELETE; contentProducerDataAccessObject.createContentItem(mockFileSystemPersistenceProvider, mockEndpoint, testFile, kind, mimeType, headers); verify(mockCatalogFramework).delete(any(DeleteRequest.class)); contentProducerDataAccessObject.createContentItem(mockFileSystemPersistenceProvider, mockEndpoint, testFile, kind, mimeType, headers); verify(mockCatalogFramework).delete(any(DeleteRequest.class)); }