Class DefaultWatchThread

  • All Implemented Interfaces:
    io.micronaut.context.LifeCycle<DefaultWatchThread>, java.io.Closeable, java.lang.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 java.lang.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 Summary

      Constructors 
      Modifier Constructor Description
      protected DefaultWatchThread​(io.micronaut.context.event.ApplicationEventPublisher eventPublisher, FileWatchConfiguration configuration, java.nio.file.WatchService watchService)
      Default constructor.
    • Constructor Detail

      • DefaultWatchThread

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

      • isRunning

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

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

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

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

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