Search in sources :

Example 1 with OVERFLOW

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;
}
Also used : FileWatcherUpdater(org.gradle.internal.watch.registry.FileWatcherUpdater) FileWatcherRegistry(org.gradle.internal.watch.registry.FileWatcherRegistry) INVALIDATED(org.gradle.internal.watch.registry.FileWatcherRegistry.Type.INVALIDATED) LoggerFactory(org.slf4j.LoggerFactory) FileWatcher(net.rubygrapefruit.platform.file.FileWatcher) InterruptedIOException(java.io.InterruptedIOException) Level(java.util.logging.Level) CREATED(org.gradle.internal.watch.registry.FileWatcherRegistry.Type.CREATED) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractFileEventFunctions(net.rubygrapefruit.platform.internal.jni.AbstractFileEventFunctions) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) WatchMode(org.gradle.internal.watch.registry.WatchMode) FileSystemLocationSnapshot(org.gradle.internal.snapshot.FileSystemLocationSnapshot) Collection(java.util.Collection) REMOVED(org.gradle.internal.watch.registry.FileWatcherRegistry.Type.REMOVED) IOException(java.io.IOException) BlockingQueue(java.util.concurrent.BlockingQueue) SnapshotHierarchy(org.gradle.internal.snapshot.SnapshotHierarchy) NativeLogger(net.rubygrapefruit.platform.internal.jni.NativeLogger) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) MODIFIED(org.gradle.internal.watch.registry.FileWatcherRegistry.Type.MODIFIED) Paths(java.nio.file.Paths) FileWatchEvent(net.rubygrapefruit.platform.file.FileWatchEvent) Optional(java.util.Optional) OVERFLOW(org.gradle.internal.watch.registry.FileWatcherRegistry.Type.OVERFLOW) FileWatchEvent(net.rubygrapefruit.platform.file.FileWatchEvent)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 Paths (java.nio.file.Paths)1 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Level (java.util.logging.Level)1 Nullable (javax.annotation.Nullable)1 FileWatchEvent (net.rubygrapefruit.platform.file.FileWatchEvent)1 FileWatcher (net.rubygrapefruit.platform.file.FileWatcher)1 AbstractFileEventFunctions (net.rubygrapefruit.platform.internal.jni.AbstractFileEventFunctions)1 NativeLogger (net.rubygrapefruit.platform.internal.jni.NativeLogger)1 FileSystemLocationSnapshot (org.gradle.internal.snapshot.FileSystemLocationSnapshot)1 SnapshotHierarchy (org.gradle.internal.snapshot.SnapshotHierarchy)1 FileWatcherRegistry (org.gradle.internal.watch.registry.FileWatcherRegistry)1 CREATED (org.gradle.internal.watch.registry.FileWatcherRegistry.Type.CREATED)1