public static void main(String[] args) throws Exception {
ZkClient zkClient = new ZkClient("127.0.0.1:2181", 5000);
zkClient.createEphemeral("/zkclient");
zkClient.subscribeDataChanges("/zkclient", new IZkDataListener() {
@Override
public void handleDataDeleted(String dataPath) throws Exception {
System.out.println(String.format("The node "%s" is deleted.", dataPath));
}
@Override
public void handleDataChange(String dataPath, Object data) throws Exception {
System.out.println(String.format("The node "%s" is changed, now its data is "%s".", dataPath, data));
}
});
zkClient.writeData("/zkclient", "hello world");
Thread.sleep(1000);
zkClient.delete("/zkclient");
Thread.sleep(1000);
zkClient.close();
}
the output of this code is:
The node "/zkclient" is changed, now its data is "hello world".
The node "/zkclient" is deleted.
public static void main(String[] args) throws Exception {
ZkClient zkClient = new ZkClient("127.0.0.1:2181", 5000);
zkClient.createEphemeral("/zkclient");
zkClient.subscribeDataChanges("/zkclient", new IZkDataListener() {
@Override
public void handleDataDeleted(String dataPath) throws Exception {
System.out.println(String.format("The node "%s" is deleted.", dataPath));
}
@Override
public void handleDataChange(String dataPath, Object data) throws Exception {
System.out.println(String.format("The node "%s" is changed, now its data is "%s".", dataPath, data));
}
});
zkClient.writeData("/zkclient", "hello world");
zkClient.delete("/zkclient");
Thread.sleep(1000);
zkClient.close();
}
the output of this code is:
The node "/zkclient" is deleted.
The node "/zkclient" is deleted.
Why did I receive two delete node events?