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>,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 Summary
ConstructorsModifierConstructorDescriptionprotectedDefaultWatchThread(io.micronaut.context.event.ApplicationEventPublisher eventPublisher, FileWatchConfiguration configuration, WatchService watchService) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected voidCloses the watch service.@NonNull WatchServicebooleanprotected @NonNull WatchKeyregisterPath(@NonNull Path dir) Registers a patch to watch.start()stop()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.context.LifeCycle
refresh
-
Constructor Details
-
DefaultWatchThread
protected DefaultWatchThread(io.micronaut.context.event.ApplicationEventPublisher eventPublisher, FileWatchConfiguration configuration, WatchService watchService) Default constructor.- Parameters:
eventPublisher- The event publisherconfiguration- the configurationwatchService- the watch service
-
-
Method Details
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceio.micronaut.context.LifeCycle<DefaultWatchThread>
-
start
- Specified by:
startin interfaceio.micronaut.context.LifeCycle<DefaultWatchThread>
-
stop
- Specified by:
stopin interfaceio.micronaut.context.LifeCycle<DefaultWatchThread>
-
close
@PreDestroy public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceio.micronaut.context.LifeCycle<DefaultWatchThread>
-
getWatchService
- Returns:
- The watch service used.
-
closeWatchService
protected void closeWatchService()Closes the watch service. -
registerPath
Registers a patch to watch.- Parameters:
dir- The directory to watch- Returns:
- The watch key
- Throws:
IOException- if an error occurs.
-