Class HotDeployWatcher

java.lang.Object
io.github.rajendarreddyj.tomcat.deploy.HotDeployWatcher
All Implemented Interfaces:
AutoCloseable

public class HotDeployWatcher extends Object implements 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 Details

    • HotDeployWatcher

      public HotDeployWatcher(DeployableConfiguration config, ExplodedWarDeployer deployer, Log log)
      Creates a new HotDeployWatcher.
      Parameters:
      config - the deployment configuration containing source path and auto-publish settings
      deployer - the deployer to use for redeployment operations
      log - the Maven logger for status messages
  • Method Details

    • start

      public void start() throws IOException
      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:

      1. Creates a new WatchService
      2. Recursively registers the source directory and all subdirectories
      3. Starts the background watcher thread
      4. 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:
      close in interface AutoCloseable