Class CertificateWatcher

java.lang.Object
com.loomcache.common.config.CertificateWatcher
All Implemented Interfaces:
AutoCloseable

public class CertificateWatcher extends Object implements AutoCloseable
Watches keystore and truststore files for modifications using Java NIO WatchService.

Detects file changes and triggers certificate reload callbacks. Handles errors gracefully without crashing the server. Debounces rapid changes to avoid duplicate reloads.

  • Constructor Details

    • CertificateWatcher

      public CertificateWatcher(@Nullable Path keystorePath, @Nullable Path truststorePath, long debounceMs, Runnable onCertificateChange) throws IOException
      Create a certificate watcher.
      Parameters:
      keystorePath - path to keystore file (may be null if not used)
      truststorePath - path to truststore file (may be null if not used)
      debounceMs - milliseconds to wait after last file change before reloading
      onCertificateChange - callback to invoke when certs change (called from watch thread)
      Throws:
      IOException - if WatchService cannot be created
  • Method Details

    • start

      public void start()
      Start watching certificate files for changes. Non-blocking — returns immediately after registering watches and starting the scheduler.
    • close

      public void close()
      Stop watching and clean up resources.
      Specified by:
      close in interface AutoCloseable
    • isRunning

      public boolean isRunning()
      Check if the watcher is currently running.