Class HotDeployWatcher
java.lang.Object
io.github.rajendarreddyj.tomcat.deploy.HotDeployWatcher
- All Implemented Interfaces:
AutoCloseable
Watches for file changes and triggers hot deployment after an inactivity
period.
This class monitors the source webapp directory for file changes using the Java NIO WatchService. When changes are detected, it waits for a configurable period of inactivity before triggering a redeployment. This batching approach prevents multiple rapid redeployments when many files change in quick succession.
Thread Model
Uses two threads:
- hot-deploy-watcher: Monitors the WatchService for file events
- hot-deploy-sync: Periodically checks if redeployment is needed
Resource Management
Implements AutoCloseable and should be used in a try-with-resources
statement or explicitly closed when no longer needed.
- Since:
- 1.0.0
- Author:
- rajendarreddyj
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionHotDeployWatcher(DeployableConfiguration config, ExplodedWarDeployer deployer, Log log) Creates a new HotDeployWatcher. -
Method Summary
-
Constructor Details
-
HotDeployWatcher
Creates a new HotDeployWatcher.- Parameters:
config- the deployment configuration containing source path and auto-publish settingsdeployer- the deployer to use for redeployment operationslog- the Maven logger for status messages
-
-
Method Details
-
start
Starts watching for file changes.If auto-publish is disabled in the configuration, this method returns immediately without starting any watchers.
This method performs the following steps:
- Creates a new WatchService
- Recursively registers the source directory and all subdirectories
- Starts the background watcher thread
- Schedules the periodic sync check task
- Throws:
IOException- if the WatchService cannot be created or directories cannot be registered
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-