Class DirWatchService

java.lang.Object
io.deephaven.util.files.DirWatchService

public class DirWatchService extends Object
Utilities to assist with file and directory operations. See MatcherType for details on the matcher types supported.
  • Constructor Details

    • DirWatchService

      public DirWatchService(@NotNull @NotNull String dirToWatch, @NotNull @NotNull Consumer<DirWatchService.ExceptionConsumerParameter> exceptionConsumer, @NotNull @NotNull DirWatchService.WatchServiceType watchServiceType, long pollIntervalMillis, @NotNull @NotNull WatchEvent.Kind... kinds)
      Constructor to create a directory watch service. This initializes the instance but doesn't add any watch patterns, and doesn't start the watch thread.
      Parameters:
      dirToWatch - Directory to watch for changes
      exceptionConsumer - Consumer to accept exceptions if they occur. Even if the watch service has terminated, stop() should be called before restarting it. The exceptionConsumer must accept two arguments - the Exception generated, and a boolean which specifies whether the WatchService has terminated as a result of the exception.
      watchServiceType - the watch service type, from the WatchServiceType enum
      pollIntervalMillis - for a poll service, the interval between polls
      kinds - The kinds of events that may need to be watched from java.nio.file.StandardWatchEventKinds, valid options are: ENTRY_CREATE, ENTRY_DELETE, and ENTRY_MODIFY
  • Method Details

    • addExactFileWatch

      public void addExactFileWatch(@NotNull @NotNull String separator, @NotNull @NotNull String filePattern, @NotNull @NotNull BiConsumer<Path,WatchEvent.Kind> consumer)
      Adds an exact match file pattern to watch for; equivalent to adding with the EXACT_MATCH_WITH_SEPARATOR MatcherType
      Parameters:
      filePattern - The exact file pattern to watch for (i.e. the part before the separator must match this)
      consumer - The consumer to be called when the pattern is matched
    • addFileWatchAtEnd

      public void addFileWatchAtEnd(@NotNull @NotNull Predicate<String> matcher, @NotNull @NotNull BiConsumer<Path,WatchEvent.Kind> consumer)
      Adds a file pattern to watch for at the end of the ordered watch list
      Parameters:
      matcher - The filtering predicate, returns true for files that should be consumed
      consumer - Consumer to be called with the file and event type
    • addFileWatchAtStart

      public void addFileWatchAtStart(@NotNull @NotNull Predicate<String> matcher, @NotNull @NotNull BiConsumer<Path,WatchEvent.Kind> consumer)
      Adds a file pattern to watch for at the start of the ordered watch list
      Parameters:
      matcher - The filtering predicate, returns true for files that should be consumed
      consumer - Consumer to be called with the file and event type
    • stop

      public void stop() throws Exception
      Request that the fileWatcher thread stop. This will not return until the thread has stopped.
      Throws:
      Exception
    • start

      public void start() throws Exception
      Starts the watch service thread. Even if it's initially empty the service should start as it could get files later.
      Throws:
      IOException - from the Java watch service
      Exception
    • makeRegexMatcher

      public static Predicate<String> makeRegexMatcher(@NotNull @NotNull String regex)
    • makeStartsWithMatcher

      public static Predicate<String> makeStartsWithMatcher(@NotNull @NotNull String prefix)
    • makeEndsWithMatcher

      public static Predicate<String> makeEndsWithMatcher(@NotNull @NotNull String suffix)