Package io.micronaut.scheduling.io.watch
Class DefaultWatchThread
- java.lang.Object
-
- io.micronaut.scheduling.io.watch.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 protectedDefaultWatchThread(io.micronaut.context.event.ApplicationEventPublisher eventPublisher, FileWatchConfiguration configuration, java.nio.file.WatchService watchService)Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()protected voidcloseWatchService()Closes the watch service.java.nio.file.WatchServicegetWatchService()booleanisRunning()protected java.nio.file.WatchKeyregisterPath(java.nio.file.Path dir)Registers a patch to watch.DefaultWatchThreadstart()DefaultWatchThreadstop()
-
-
-
Constructor Detail
-
DefaultWatchThread
protected DefaultWatchThread(io.micronaut.context.event.ApplicationEventPublisher eventPublisher, FileWatchConfiguration configuration, java.nio.file.WatchService watchService)Default constructor.- Parameters:
eventPublisher- The event publisherconfiguration- the configurationwatchService- the watch service
-
-
Method Detail
-
isRunning
public boolean isRunning()
- Specified by:
isRunningin interfaceio.micronaut.context.LifeCycle<DefaultWatchThread>
-
start
@PostConstruct public DefaultWatchThread start()
- Specified by:
startin interfaceio.micronaut.context.LifeCycle<DefaultWatchThread>
-
stop
public DefaultWatchThread stop()
- Specified by:
stopin interfaceio.micronaut.context.LifeCycle<DefaultWatchThread>
-
close
@PreDestroy public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceio.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.IOExceptionRegisters a patch to watch.- Parameters:
dir- The directory to watch- Returns:
- The watch key
- Throws:
java.io.IOException- if an error occurs.
-
-