Zookeeper
@RequestMapping("/zookeeper")
@ResponseBody
void zookeeperTest() {
String connectString = "172.16.31.67:2181";
int sessionTimeout = 4000;
Watcher watcher = new Watcher() {
public void process(WatchedEvent event) {
//System.out.println(event.getPath());
}
};
try {
ZooKeeper zooKeeper = new ZooKeeper(connectString, sessionTimeout, watcher);
List<String> list = zooKeeper.getChildren("/configurations/KDS/loadtest", false);
for (String path : list) {
System.out.println(path);
}
} catch (IOException e) {
e.printStackTrace();
} catch (KeeperException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@RequestMapping("/zookeeper2")
@ResponseBody
void zookeeperTest2() {
String connectString = "172.16.31.67:2181";
int sessionTimeout = 4000;
Watcher watcher = new Watcher() {
public void process(WatchedEvent event) {
//System.out.println(event.getPath());
}
};
try {
ZooKeeper zooKeeper = new ZooKeeper(connectString, sessionTimeout, watcher);
// List<String> list = zooKeeper.getChildren("/configurations/KDS/loadtest", false);
//for (String path : list) {
// System.out.println(path);
byte[] b = zooKeeper.getData("/configurations/KDS/loadtest/apps:activemq", false, null) ;
System.out.println( new String(b) );
// }
} catch (IOException e) {
e.printStackTrace();
} catch (KeeperException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@RequestMapping("/zookeeper3")
@ResponseBody
String zookeeperTest3() throws Exception {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
CuratorFramework newClient=CuratorFrameworkFactory.newClient("172.16.31.67:2181", retryPolicy);
String path="/configurations/KDS/loadtest/apps:activemq";
return new String(newClient.getData().forPath(path));
}