use of org.gradle.internal.watch.registry.FileWatcherRegistry.Type.OVERFLOW in project gradle by gradle.
the class DefaultFileWatcherRegistry method createAndStartEventConsumerThread.
private Thread createAndStartEventConsumerThread(ChangeHandler handler) {
Thread thread = new Thread(() -> {
LOGGER.debug("Started listening to file system change events");
try {
while (consumeEvents) {
FileWatchEvent nextEvent = fileEvents.take();
if (!stopping) {
nextEvent.handleEvent(new FileWatchEvent.Handler() {
@Override
public void handleChangeEvent(FileWatchEvent.ChangeType type, String absolutePath) {
fileWatchingStatistics.eventReceived();
fileWatcherUpdater.triggerWatchProbe(absolutePath);
handler.handleChange(convertType(type), Paths.get(absolutePath));
}
@Override
public void handleUnknownEvent(String absolutePath) {
LOGGER.error("Received unknown event for {}", absolutePath);
fileWatchingStatistics.unknownEventEncountered();
handler.stopWatchingAfterError();
}
@Override
public void handleOverflow(FileWatchEvent.OverflowType type, @Nullable String absolutePath) {
if (absolutePath == null) {
LOGGER.info("Overflow detected (type: {}), invalidating all watched files", type);
fileWatcherUpdater.getWatchedFiles().visitRoots(watchedRoot -> handler.handleChange(OVERFLOW, Paths.get(watchedRoot)));
} else {
LOGGER.info("Overflow detected (type: {}) for watched path '{}', invalidating", type, absolutePath);
handler.handleChange(OVERFLOW, Paths.get(absolutePath));
}
}
@Override
public void handleFailure(Throwable failure) {
LOGGER.error("Error while receiving file changes", failure);
fileWatchingStatistics.errorWhileReceivingFileChanges(failure);
handler.stopWatchingAfterError();
}
@Override
public void handleTerminated() {
consumeEvents = false;
}
});
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
// stop thread
}
LOGGER.debug("Finished listening to file system change events");
});
thread.setDaemon(true);
thread.setName("File watcher consumer");
thread.setUncaughtExceptionHandler((failedThread, exception) -> {
LOGGER.error("File system event consumer thread stopped due to exception", exception);
handler.stopWatchingAfterError();
});
thread.start();
return thread;
}
Aggregations