use of net.rubygrapefruit.platform.file.FileWatchEvent in project gradle by gradle.
the class AbstractFileWatcherRegistryFactory method createFileWatcherRegistry.
@Override
public FileWatcherRegistry createFileWatcherRegistry(FileWatcherRegistry.ChangeHandler handler) {
BlockingQueue<FileWatchEvent> fileEvents = new ArrayBlockingQueue<>(FILE_EVENT_QUEUE_SIZE);
try {
// TODO How can we avoid hard-coding ".gradle" here?
FileWatcherProbeRegistry probeRegistry = new DefaultFileWatcherProbeRegistry(buildDir -> new File(new File(buildDir, ".gradle"), "file-system.probe"));
W watcher = createFileWatcher(fileEvents);
WatchableHierarchies watchableHierarchies = new WatchableHierarchies(probeRegistry, watchFilter);
FileWatcherUpdater fileWatcherUpdater = createFileWatcherUpdater(watcher, probeRegistry, watchableHierarchies);
return new DefaultFileWatcherRegistry(fileEventFunctions, watcher, handler, fileWatcherUpdater, fileEvents);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
use of net.rubygrapefruit.platform.file.FileWatchEvent 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