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
ModifierConstructorDescriptionprotected
DefaultWatchThread
(ApplicationEventPublisher eventPublisher, FileWatchConfiguration configuration, WatchService watchService) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Delegates toLifeCycle.stop()
.protected void
Closes the watch service.boolean
registerPath
(@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:
isRunning
in interfaceLifeCycle<DefaultWatchThread>
- Returns:
- Whether the component is running
-
start
Description copied from interface:LifeCycle
Starts the lifecyle component.- Specified by:
start
in interfaceLifeCycle<DefaultWatchThread>
- Returns:
- This lifecycle component
-
stop
Description copied from interface:LifeCycle
Stops the life cycle component.- Specified by:
stop
in interfaceLifeCycle<DefaultWatchThread>
- Returns:
- This lifecycle component
-
close
Description copied from interface:LifeCycle
Delegates toLifeCycle.stop()
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in 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.
-