Class DefaultWatchThread

java.lang.Object
io.micronaut.scheduling.io.watch.DefaultWatchThread
All Implemented Interfaces:
io.micronaut.context.LifeCycle<DefaultWatchThread>, Closeable, AutoCloseable

@Requires(property="micronaut.io.watch.paths") @Requires(property="micronaut.io.watch.enabled",value="true",defaultValue="false") @Requires(condition=FileWatchCondition.class) @Requires(notEnv={"function","android"}) @Requires(beans=java.nio.file.WatchService.class) @Parallel @Singleton public class DefaultWatchThread extends Object implements io.micronaut.context.LifeCycle<DefaultWatchThread>
Simple watch service that simply stops the server if any changes occur. It is up to an external tool to watch the server.

For example with Gradle you use ./gradlew run --continuous

Since:
1.1.0
  • Constructor Details

    • DefaultWatchThread

      protected DefaultWatchThread(io.micronaut.context.event.ApplicationEventPublisher eventPublisher, FileWatchConfiguration configuration, WatchService watchService)
      Default constructor.
      Parameters:
      eventPublisher - The event publisher
      configuration - the configuration
      watchService - the watch service
  • Method Details

    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface io.micronaut.context.LifeCycle<DefaultWatchThread>
    • start

      @PostConstruct public DefaultWatchThread start()
      Specified by:
      start in interface io.micronaut.context.LifeCycle<DefaultWatchThread>
    • stop

      public DefaultWatchThread stop()
      Specified by:
      stop in interface io.micronaut.context.LifeCycle<DefaultWatchThread>
    • close

      @PreDestroy public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface io.micronaut.context.LifeCycle<DefaultWatchThread>
    • getWatchService

      @NonNull public @NonNull WatchService getWatchService()
      Returns:
      The watch service used.
    • closeWatchService

      protected void closeWatchService()
      Closes the watch service.
    • registerPath

      @NonNull protected @NonNull WatchKey registerPath(@NonNull @NonNull Path dir) throws IOException
      Registers a patch to watch.
      Parameters:
      dir - The directory to watch
      Returns:
      The watch key
      Throws:
      IOException - if an error occurs.