@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 LifeCycle<DefaultWatchThread>
For example with Gradle you use ./gradlew run --continuous
Modifier | Constructor and Description |
---|---|
protected |
DefaultWatchThread(ApplicationEventPublisher eventPublisher,
FileWatchConfiguration configuration,
WatchService watchService)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Delegates to
LifeCycle.stop() . |
protected void |
closeWatchService()
Closes the watch service.
|
WatchService |
getWatchService() |
boolean |
isRunning() |
protected WatchKey |
registerPath(Path dir)
Registers a patch to watch.
|
DefaultWatchThread |
start()
Starts the lifecyle component.
|
DefaultWatchThread |
stop()
Stops the life cycle component.
|
protected DefaultWatchThread(ApplicationEventPublisher eventPublisher, FileWatchConfiguration configuration, WatchService watchService)
eventPublisher
- The event publisherconfiguration
- the configurationwatchService
- the watch servicepublic boolean isRunning()
isRunning
in interface LifeCycle<DefaultWatchThread>
@PostConstruct public DefaultWatchThread start()
LifeCycle
start
in interface LifeCycle<DefaultWatchThread>
public DefaultWatchThread stop()
LifeCycle
stop
in interface LifeCycle<DefaultWatchThread>
@PreDestroy public void close()
LifeCycle
LifeCycle.stop()
.close
in interface LifeCycle<DefaultWatchThread>
close
in interface Closeable
close
in interface AutoCloseable
@NonNull public WatchService getWatchService()
protected void closeWatchService()
@NonNull protected WatchKey registerPath(@NonNull Path dir) throws IOException
dir
- The directory to watchIOException
- if an error occurs.