use of java.nio.file.WatchEvent in project sldeditor by robward-scisys.
the class FileSystemWatcher method internalWatchDirectoryPath.
/**
* Internal watch directory path method.
*
* @throws InterruptedException
* @throws IOException Signals that an I/O exception has occurred.
*/
private void internalWatchDirectoryPath() {
WatchKey key = null;
// Poll for events in an infinite loop
for (; ; ) {
// notification
try {
key = watchService.take();
} catch (InterruptedException e) {
// Do nothing
}
// once a key is obtained, we poll for events on that key
if (key != null) {
List<WatchEvent<?>> keys = key.pollEvents();
processWatchEvents(key, keys);
// Reset the key so the further key events may be polled
key.reset();
}
if (stopPolling) {
break;
}
}
}
use of java.nio.file.WatchEvent in project Singularity by HubSpot.
the class WatchServiceHelper method processWatchKey.
private void processWatchKey(WatchKey watchKey) throws IOException {
final long start = System.currentTimeMillis();
final List<WatchEvent<?>> events = watchKey.pollEvents();
int processed = 0;
for (WatchEvent<?> event : events) {
WatchEvent.Kind<?> kind = event.kind();
if (!watchEvents.contains(kind)) {
LOG.trace("Ignoring an {} event to {}", event.kind(), event.context());
continue;
}
WatchEvent<Path> ev = cast(event);
Path filename = ev.context();
if (processEvent(kind, filename)) {
processed++;
}
}
LOG.debug("Handled {} out of {} event(s) for {} in {}", processed, events.size(), watchDirectory, JavaUtils.duration(start));
}
Aggregations