Package io.micronaut.scheduling.io.watch
Class DefaultWatchThread
java.lang.Object
io.micronaut.scheduling.io.watch.DefaultWatchThread
- All Implemented Interfaces:
LifeCycle<DefaultWatchThread>,Closeable,AutoCloseable
- Direct Known Subclasses:
MacOsWatchThread
@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>
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
- Author:
- graemerocher
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefaultWatchThread(ApplicationEventPublisher eventPublisher, FileWatchConfiguration configuration, WatchService watchService) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Delegates toLifeCycle.stop().protected voidCloses the watch service.booleanregisterPath(@NonNull Path dir) Registers a patch to watch.start()Starts the lifecyle component.stop()Stops the life cycle component.
-
Constructor Details
-
DefaultWatchThread
protected DefaultWatchThread(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 interfaceLifeCycle<DefaultWatchThread>- Returns:
- Whether the component is running
-
start
Description copied from interface:LifeCycleStarts the lifecyle component.- Specified by:
startin interfaceLifeCycle<DefaultWatchThread>- Returns:
- This lifecycle component
-
stop
Description copied from interface:LifeCycleStops the life cycle component.- Specified by:
stopin interfaceLifeCycle<DefaultWatchThread>- Returns:
- This lifecycle component
-
close
Description copied from interface:LifeCycleDelegates toLifeCycle.stop().- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceLifeCycle<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.
-