Github user ivmaykov commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/680#discussion_r228719526
--- Diff:
zookeeper-server/src/main/java/org/apache/zookeeper/common/X509Util.java ---
@@ -546,4 +557,109 @@ public static StoreFileType
detectStoreFileTypeFromFileExtension(File filename)
}
throw new IOException("Unable to auto-detect store file type from
file name: " + filename);
}
+
+ /**
+ * Enables automatic reloading of the trust store and key store files
when they change on disk.
+ *
+ * @throws IOException if creating the FileChangeWatcher objects fails.
+ */
+ public void enableCertFileReloading() throws IOException {
+ ZKConfig config = new ZKConfig();
+ String keyStoreLocation =
config.getProperty(sslKeystoreLocationProperty);
+ if (keyStoreLocation != null && !keyStoreLocation.isEmpty()) {
+ final Path filePath =
Paths.get(keyStoreLocation).toAbsolutePath();
+ FileChangeWatcher newKeyStoreFileWatcher = new
FileChangeWatcher(
+ filePath.getParent(),
+ new Consumer<WatchEvent<?>>() {
+ @Override
+ public void accept(WatchEvent<?> watchEvent) {
+ handleWatchEvent(filePath, watchEvent);
+ }
+ });
+ // stop old watcher if there is one
+ if (keyStoreFileWatcher != null) {
+ keyStoreFileWatcher.stop();
+ keyStoreFileWatcher = newKeyStoreFileWatcher;
--- End diff --
oops, this has a bug that I introduced while refactoring. Will fix.
---