4

I am new to zookeeper. I have written simple program to create Persistent Node. Its working but giving exception once execution is completed.I tried to search on google but there is no satisfactory answer. Can any one advice me anything.

public class ZkProg {
    public static void main(String[] args) throws IOException, KeeperException, InterruptedException
    {
        ZooKeeper zk=new ZooKeeper("localhost",1281, null);
        zk.create("/zookeeper/Names",new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        //zk.delete("/zookeeper/Names",-1);
        zk.close();
    }
}
Kapil
  • 193
  • 2
  • 14
  • what is the full exception?? also one suggestion please check whether Zookeeper is working fine and u r able to write data manually on znode. – Vikas Hardia Jun 05 '14 at 05:51

2 Answers2

3

I also had this error being logged. It is because the Zookeeper watcher is null. In the call to the constructor, the third parameter is a watcher:

ZooKeeper zk=new ZooKeeper("localhost",1281, null);

It seems that the Zookeeper ClientCnxn tries to call process on the watcher, even if it is null. However, it catches the exception and just logs the error and moves on.

DJ_Polly
  • 434
  • 3
  • 12
2

If you don't want to watch events, you can write your own "StubWatcher".

Create a class that inherits from Watcher and implement the process method with empty body.

That should do it.

Shani Elharrar
  • 667
  • 4
  • 5