Class PollingWatchService

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.nio.file.WatchService

    final class PollingWatchService
    extends AbstractWatchService
    Implementation of WatchService that polls for changes to directories at registered paths.
    • Field Detail

      • THREAD_FACTORY

        private static final java.util.concurrent.ThreadFactory THREAD_FACTORY
        Thread factory for polling threads, which should be daemon threads so as not to keep the VM running if the user doesn't close the watch service or the file system.
      • pollingService

        private final java.util.concurrent.ScheduledExecutorService pollingService
      • interval

        final long interval
      • timeUnit

        final java.util.concurrent.TimeUnit timeUnit
      • pollingFuture

        private java.util.concurrent.ScheduledFuture<?> pollingFuture
      • pollingTask

        private final java.lang.Runnable pollingTask
    • Method Detail

      • register

        @CanIgnoreReturnValue
        public AbstractWatchService.Key register​(java.nio.file.Watchable watchable,
                                                 java.lang.Iterable<? extends java.nio.file.WatchEvent.Kind<?>> eventTypes)
                                          throws java.io.IOException
        Description copied from class: AbstractWatchService
        Registers the given watchable with this service, returning a new watch key for it. This implementation just checks that the service is open and creates a key; subclasses may override it to do other things as well.
        Overrides:
        register in class AbstractWatchService
        Throws:
        java.io.IOException
      • checkWatchable

        private JimfsPath checkWatchable​(java.nio.file.Watchable watchable)
      • isSameFileSystem

        private boolean isSameFileSystem​(java.nio.file.Path path)
      • isPolling

        boolean isPolling()
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface java.nio.file.WatchService
        Overrides:
        close in class AbstractWatchService
      • startPolling

        private void startPolling()
      • stopPolling

        private void stopPolling()