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 protected
DefaultWatchThread(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 void
close()
protected void
closeWatchService()
Closes the watch service.java.nio.file.WatchService
getWatchService()
boolean
isRunning()
protected java.nio.file.WatchKey
registerPath(java.nio.file.Path dir)
Registers a patch to watch.DefaultWatchThread
start()
DefaultWatchThread
stop()
-
-
-
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:
isRunning
in interfaceio.micronaut.context.LifeCycle<DefaultWatchThread>
-
start
@PostConstruct public DefaultWatchThread start()
- Specified by:
start
in interfaceio.micronaut.context.LifeCycle<DefaultWatchThread>
-
stop
public DefaultWatchThread stop()
- Specified by:
stop
in interfaceio.micronaut.context.LifeCycle<DefaultWatchThread>
-
close
@PreDestroy public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in 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.IOException
Registers a patch to watch.- Parameters:
dir
- The directory to watch- Returns:
- The watch key
- Throws:
java.io.IOException
- if an error occurs.
-
-