|
|
@@ -13,7 +13,11 @@ import org.apache.curator.framework.recipes.cache.ChildData;
|
|
|
import org.apache.curator.framework.recipes.cache.TreeCache;
|
|
|
import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
|
|
|
import org.apache.curator.framework.recipes.cache.TreeCacheListener;
|
|
|
+import org.apache.curator.framework.state.ConnectionState;
|
|
|
+import org.apache.curator.framework.state.ConnectionStateListener;
|
|
|
import org.apache.curator.retry.ExponentialBackoffRetry;
|
|
|
+import org.apache.zookeeper.ZooKeeper;
|
|
|
+import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
|
|
|
import org.springframework.core.env.Environment;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -58,10 +62,28 @@ public class TnbZkService {
|
|
|
.connectionTimeoutMs(3000)
|
|
|
.retryPolicy(new ExponentialBackoffRetry(1000, 3))
|
|
|
.build();
|
|
|
+
|
|
|
+ client.getConnectionStateListenable().addListener(new ConnectionStateListener() {
|
|
|
+ @Override
|
|
|
+ public void stateChanged(CuratorFramework client, ConnectionState newState) {
|
|
|
+ String connectString = client.getZookeeperClient().getCurrentConnectionString();
|
|
|
+ //client.getZookeeperClient().getZooKeeper().getState();
|
|
|
+ QuorumVerifier quorumVerifier = client.getCurrentConfig();
|
|
|
+ log.info("{} 连接事件 {} {}", connectString, newState.toString(), client.getState());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
client.start();
|
|
|
return client;
|
|
|
}
|
|
|
|
|
|
+ public void getZkConfig() throws Exception {
|
|
|
+ QuorumVerifier quorumVerifier = client.getCurrentConfig();
|
|
|
+ ZooKeeper zooKeeper = client.getZookeeperClient().getZooKeeper();
|
|
|
+ String zkStr = zooKeeper.toString();
|
|
|
+ System.out.println();
|
|
|
+ }
|
|
|
+
|
|
|
public List<String> getZkService(String zkPath) throws Exception {
|
|
|
List<String> list = new ArrayList<>();
|
|
|
List<String> list1 = client.getChildren().forPath(zkPath);
|