Class WatchDir

    • Constructor Detail

      • WatchDir

        public WatchDir​(@Nonnull
                        Path aDir,
                        boolean bRecursive)
                 throws IOException
        Creates a WatchService and registers the given directory
        Parameters:
        aDir - The directory to be watched. May not be null.
        bRecursive - true to watch the directory recursive, false to watch just this directory.
        Throws:
        IOException - In case something goes wrong.
    • Method Detail

      • getStartDirectory

        @Nonnull
        public Path getStartDirectory()
        Returns:
        The start directory as specified in the constructor. Never null.
      • isRecursive

        public boolean isRecursive()
        Returns:
        true if this is a recursive listener, false if not.
      • stopProcessing

        public void stopProcessing()
        Stop processing, if processEvents() is active. This method is automatically called in close().
      • processEvents

        public void processEvents()
        Process all events for keys queued to the watcher. Call stopProcessing() or close() to stop processing within a reasonable time. This method should run in a separate thread, as it contains an infinite loop! Usually you don't call this method manually.
        See Also:
        runAsync()
      • runAsync

        public void runAsync()
        Call this method to process events. This method creates a background thread than runs processEvents() and performs the heavy lifting.
      • runAsyncAndReturn

        @Nonnull
        public Thread runAsyncAndReturn()
        Call this method to process events. This method creates a background thread than runs processEvents() and performs the heavy lifting.
        Returns:
        The created Thread that can also be stopped again if not needed anymore.
        Since:
        10.1.5
      • createAsyncRunningWatchDir

        @Nonnull
        @ReturnsMutableCopy
        public static WatchDir createAsyncRunningWatchDir​(@Nonnull
                                                          Path aDir,
                                                          boolean bRecursive,
                                                          @Nonnull
                                                          IWatchDirCallback aCallback)
                                                   throws IOException
        Static factory method to create a simple WatchDir instance that already spawned an Thread to listen. To close the thread call the close() method.
        Parameters:
        aDir - The directory to be watched. May not be null.
        bRecursive - true to watch the directory recursive, false to watch just this directory.
        aCallback - The callback to be invoked if something changed. May not be null.
        Returns:
        The newly created WatchDir instance and never null.
        Throws:
        IOException - In case something goes wrong.