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.ow2.proactive.scheduler.task.ProgressFileReader.java
boolean start(File workingDir, String filename) { try {/*ww w .j a va2 s.co m*/ createProgressFile(workingDir, filename); watchService = FileSystems.getDefault().newWatchService(); watchServiceThread = new Thread(new ProgressFileReaderThread(filename)); watchServiceThread.setName(ProgressFileReaderThread.class.getName()); watchServiceThread.start(); progress = 0; progressFileDir.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY); return true; } catch (IOException e) { logger.warn("Error while creating progress file. Progress will not be reported.", e); return false; } }
From source file:com.reactive.hzdfs.dll.JarModuleLoader.java
private void registerWatch(Path dir) throws IOException { if (log.isDebugEnabled()) { log.debug("registering: " + dir + " for file events"); }/* w w w . j a v a 2s .com*/ dir.register(watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY); }
From source file:org.wso2.carbon.uuf.renderablecreator.hbs.internal.io.RenderableUpdater.java
private void add(FileReference fileReference, MutableHbsRenderable mutableRenderable) { Path renderablePath = Paths.get(fileReference.getAbsolutePath()); Path parentDirectory = renderablePath.getParent(); if (watchingDirectories.add(parentDirectory)) { try {//from w ww . j av a 2s .c o m parentDirectory.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY); } catch (ClosedWatchServiceException e) { throw new UUFException("File watch service is closed.", e); } catch (NotDirectoryException e) { throw new FileOperationException("Cannot register path '" + parentDirectory + "' to file watch service as it is not a directory.", e); } catch (IOException e) { throw new FileOperationException("An IO error occurred when registering path '" + parentDirectory + "' to file watch service.'", e); } } watchingRenderables.put(renderablePath.getFileName(), mutableRenderable); mutableRenderable.getMutableExecutable() .ifPresent(me -> watchingExecutables.put(Paths.get(me.getPath()).getFileName(), me)); }
From source file:org.wso2.carbon.uuf.renderablecreator.hbs.internal.io.HbsRenderableUpdater.java
private void add(FileReference fileReference, MutableHbsRenderable mutableRenderable) { Path renderablePath = Paths.get(fileReference.getAbsolutePath()); Path parentDirectory = renderablePath.getParent(); if (watchingDirectories.add(parentDirectory)) { try {/* w ww . ja v a 2 s . c o m*/ parentDirectory.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY); } catch (ClosedWatchServiceException e) { throw new UUFException("File watch service is closed.", e); } catch (NotDirectoryException e) { throw new FileOperationException("Cannot register path '" + parentDirectory + "' to file watch service as it is not a directory.", e); } catch (IOException e) { throw new FileOperationException("An IO error occurred when registering path '" + parentDirectory + "' to file watch service.'", e); } } watchingRenderables.put(renderablePath, mutableRenderable); mutableRenderable.getMutableExecutable() .ifPresent(me -> watchingExecutables.put(Paths.get(me.getPath()), me)); }
From source file:io.stallion.fileSystem.FileSystemWatcherRunner.java
private void registerWatcherForFolder(IWatchEventHandler handler, String folder) { Path itemsDir = FileSystems.getDefault().getPath(folder); try {/* w w w. j a va 2 s . c o m*/ if (new File(itemsDir.toString()).isDirectory()) { itemsDir.register(watcher, new WatchEvent.Kind[] { StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE }, SensitivityWatchEventModifier.HIGH); Log.fine("Folder registered with watcher {0}", folder); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:de.elomagic.carafile.client.CaraCloud.java
/** * Starts synchronization of the given base path with the registry. * <p/>/*from w ww . j a va2 s . c o m*/ * This method will block till call method {@link CaraCloud#stop() } * * @throws IOException Thrown when an I/O error occurs * @throws InterruptedException Thrown when method stop was called or application will terminate * @throws GeneralSecurityException */ public void start() throws IOException, InterruptedException, GeneralSecurityException { if (client == null) { throw new IllegalStateException("Attribute \"client\" must be set."); } if (basePath == null) { throw new IllegalStateException("Attribute \"basePath\" must be set."); } if (!Files.exists(basePath)) { throw new IllegalStateException("Path \"" + basePath + "\" must exists."); } if (!Files.isDirectory(basePath)) { throw new IllegalStateException("Path \"" + basePath + "\" must be a directory/folder."); } watcher = FileSystems.getDefault().newWatchService(); registerDefaultWatch(basePath); while (!Thread.interrupted()) { WatchKey key = watcher.take(); for (WatchEvent<?> event : key.pollEvents()) { if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE) { Path path = basePath.resolve(event.context().toString()); createFile(path); } else if (event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) { } else if (event.kind() == StandardWatchEventKinds.ENTRY_DELETE) { Path path = basePath.resolve(event.context().toString()); deleteFile(path); } else { LOG.error("Unsupported kind: " + event.kind() + ", path: " + event.context()); } } key.reset(); } }
From source file:nz.co.fortytwo.signalk.server.SignalKServer.java
protected SignalKServer(String configDir) throws Exception { // init config Properties props = System.getProperties(); props.setProperty("java.net.preferIPv4Stack", "true"); System.setProperties(props);//w ww . j a v a2 s . c o m Util.getConfig(); // make sure we have all the correct dirs and files now ensureInstall(); logger.info("SignalKServer starting...."); // do we have a USB drive connected? //logger.info("USB drive " + Util.getUSBFile()); // create a new Camel Main so we can easily start Camel Main main = new Main(); //main.setApplicationContextUri("classpath:META-INF/spring/camel-context.xml"); // enable hangup support which mean we detect when the JVM terminates, // and stop Camel graceful main.enableHangupSupport(); // Start activemq broker BrokerService broker = ActiveMqBrokerFactory.newInstance(); broker.start(); //DNS-SD, zeroconf mDNS startMdns(); configureRouteManager(main); // and run, which keeps blocking until we terminate the JVM (or stop // CamelContext) main.start(); WatchService service = FileSystems.getDefault().newWatchService(); Path dir = Paths.get("./conf"); dir.register(service, StandardWatchEventKinds.ENTRY_MODIFY); WatchKey key = null; while (true) { key = service.take(); // Dequeueing events Kind<?> kind = null; for (WatchEvent<?> watchEvent : key.pollEvents()) { // Get the type of the event kind = watchEvent.kind(); logger.debug( "SignalKServer conf/ event:" + watchEvent.kind() + " : " + watchEvent.context().toString()); if (StandardWatchEventKinds.OVERFLOW == kind) { continue; //loop } else if (StandardWatchEventKinds.ENTRY_MODIFY == kind) { // A new Path was created @SuppressWarnings("unchecked") Path newPath = ((WatchEvent<Path>) watchEvent).context(); // Output if (newPath.endsWith("signalk-restart")) { logger.info("SignalKServer conf/signalk-restart changed, stopping.."); main.stop(); main.getCamelContexts().clear(); main.getRouteBuilders().clear(); main.getRouteDefinitions().clear(); // so now shutdown serial reader and server RouteManager routeManager = RouteManagerFactory.getInstance(); routeManager.stopNettyServers(); routeManager.stopSerial(); if (server != null) { server.stop(); server = null; } RouteManagerFactory.clear(); configureRouteManager(main); main.start(); } } } if (!key.reset()) { break; //loop } } stopMdns(); broker.stop(); // write out the signalk model SignalKModelFactory.save(SignalKModelFactory.getInstance()); System.exit(0); }
From source file:org.siphon.db2js.jshttp.ServerUnitManager.java
public void onFileChanged(WatchEvent<Path> ev, Path file) { Kind<Path> kind = ev.kind(); String filename = file.toString(); if (kind == StandardWatchEventKinds.ENTRY_DELETE) { if (contexts.containsKey(filename)) { if (logger.isDebugEnabled()) { logger.debug(filename + " dropped"); }//from ww w. ja v a 2 s . c o m contexts.remove(filename); } } else if (kind == StandardWatchEventKinds.ENTRY_MODIFY) { if (contexts.containsKey(filename)) { if (logger.isDebugEnabled()) { logger.debug(filename + " changed"); } contexts.remove(filename); } } }
From source file:io.mangoo.build.Watcher.java
/** * * USUALLY THIS IS THE DEFAULT WAY TO REGISTER THE EVENTS: * * WatchKey watchKey = path.register(// w w w . j a va 2s. com * watchService, * ENTRY_CREATE, * ENTRY_DELETE, * ENTRY_MODIFY); * * BUT THIS IS DAMN SLOW (at least on a Mac) * THEREFORE WE USE EVENTS FROM COM.SUN PACKAGES THAT ARE WAY FASTER * THIS MIGHT BREAK COMPATIBILITY WITH OTHER JDKs * MORE: http://stackoverflow.com/questions/9588737/is-java-7-watchservice-slow-for-anyone-else * * @param path * @throws IOException */ private void register(Path path) throws IOException { WatchKey watchKey = path.register(watchService, new WatchEvent.Kind[] { StandardWatchEventKinds.ENTRY_CREATE, //NOSONAR StandardWatchEventKinds.ENTRY_MODIFY, //NOSONAR StandardWatchEventKinds.ENTRY_DELETE //NOSONAR }, SensitivityWatchEventModifier.HIGH); watchKeys.put(watchKey, path); }
From source file:acromusashi.stream.ml.common.spout.WatchTextBatchSpout.java
/** * ???????????????????/*from ww w .j a v a2s.c o m*/ * * @param collector Collector * @throws IOException * @throws InterruptedException ? */ @SuppressWarnings({ "rawtypes" }) protected void checkDataFile(TridentCollector collector) throws IOException, InterruptedException { // ????????????????? if (this.isInitialReaded == false) { List<String> fileContents = FileUtils.readLines(this.targetFile); emitTuples(fileContents, collector); this.isInitialReaded = true; // Path dirPath = new File(this.dataFileDir).toPath(); FileSystem fileSystem = dirPath.getFileSystem(); this.watcherService = fileSystem.newWatchService(); this.watchKey = dirPath.register(this.watcherService, new Kind[] { StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY }); return; } // ???????? WatchKey detectedKey = this.watcherService.poll(1, TimeUnit.SECONDS); // ??????????????????????? if (detectedKey == null || detectedKey.equals(this.watchKey) == false) { return; } try { // ??????????????? for (WatchEvent event : detectedKey.pollEvents()) { Path filePath = (Path) event.context(); // ????????????? if (filePath == null || this.targetFile.toPath().getFileName().equals(filePath.getFileName()) == false) { continue; } List<String> fileContents = FileUtils.readLines(this.targetFile); emitTuples(fileContents, collector); } } finally { detectedKey.reset(); } }