fix: CuratorWatch unwatch , childListener is null (#12742)

This commit is contained in:
BigXin0109 2023-07-18 18:46:45 +08:00 committed by GitHub
parent a6bef26663
commit 345e58fc59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 7 deletions

View File

@ -51,6 +51,7 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
@ -481,13 +482,14 @@ public class CuratorZookeeperClient extends AbstractZookeeperClient<CuratorZooke
}
if (childListener != null) {
Runnable task = () -> {
try {
childListener.childChanged(path, client.getChildren().usingWatcher(CuratorWatcherImpl.this).forPath(path));
} catch (Exception e) {
logger.warn(REGISTRY_ZOOKEEPER_EXCEPTION, "", "", "client get children error", e);
}
};
Runnable task = () -> Optional.ofNullable(childListener)
.ifPresent(c -> {
try {
c.childChanged(path, client.getChildren().usingWatcher(CuratorWatcherImpl.this).forPath(path));
} catch (Exception e) {
logger.warn(REGISTRY_ZOOKEEPER_EXCEPTION, "", "", "client get children error", e);
}
});
initExecutorIfNecessary();
if (!closed && CURATOR_WATCHER_EXECUTOR_SERVICE != null) {
CURATOR_WATCHER_EXECUTOR_SERVICE.execute(task);