Re: processResults

2010-09-27 Thread Patrick Hunt
I believe what the author is trying to say is that if the getdata were to
fail (such as the example you give) the watch set as part of the original
call will fire, and this will notify the client that the node was deleted.
(call to process(event))

Patrick

On Mon, Sep 27, 2010 at 6:56 PM, Milind Parikh wrote:

> In the explanation of the Java binding, it is mentioned "If the file (or
> znode) exists, it gets the data from the znode, and then invoke the
> exists()
> callback of Executor if the state has changed. Note, it doesn't have to do
> any Exception processing for the getData call because it has watches
> pending
> for anything that could cause an error: if the node is deleted before it
> calls ZooKeeper.getData(), the watch event set by the
> ZooKeeper.exists()triggers a callback "
>
> I read this to mean that if I insert a Thread.sleep() before the getData
> call & removed the node from the cli, somehow (magically) there would be no
> error. But of course, it does not happen
>
> Sleeps for 10 seconds
> org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode =
> NoNode for /zk_test
>at org.apache.zookeeper.KeeperException.create(KeeperException.java:102)
>at org.apache.zookeeper.KeeperException.create(KeeperException.java:42)
>at org.apache.zookeeper.ZooKeeper.getData(ZooKeeper.java:921)
>at org.apache.zookeeper.ZooKeeper.getData(ZooKeeper.java:950)
>at DataMonitor.processResult(DataMonitor.java:114)
>at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:512)
>
> Am I doing something wrong (or reading something wrong)?
>
> -- Milind
>


Re: processResults

2010-09-27 Thread Milind Parikh
If I use a ASync version of getData and implement DataCallback on the
DataMonitor, it works with a No Node in the below mentioned use case. I can
update this IF this is the correct way of doing this.


/* DataCallback */

public void processResult(int rc, String path, Object ctx, byte[] data,
Stat stat) {

boolean exists;
switch (rc) {
case Code.Ok:
exists = true;
break;
case Code.NoNode:
System.out.println("No node");

exists = false;
break;
case Code.SessionExpired:
case Code.NoAuth:
dead = true;
listener.closing(rc);
return;
default:
// Retry errors
zk.exists(znode, true, this, null);
return;
}

if (exists) {

if ((data == null && data != prevData)
|| (data != null && !Arrays.equals(prevData, data))) {
listener.exists(data);
prevData = data;
}
}
}



/* Exists Callback */


public void processResult(int rc, String path, Object ctx, Stat stat) {

boolean exists;
switch (rc) {
case Code.Ok:
exists = true;
break;
case Code.NoNode:
exists = false;
break;
case Code.SessionExpired:
case Code.NoAuth:
dead = true;
listener.closing(rc);
return;
default:
// Retry errors
zk.exists(znode, true, this, null);
return;
}


if (exists) {
try {
System.out.println("SLEEP 10 seconds");

Thread.sleep(1);
zk.getData(znode, false, this, null);
}
catch (InterruptedException ie) {
System.out.println(ie);
}

}

}

On Mon, Sep 27, 2010 at 6:56 PM, Milind Parikh wrote:

> In the explanation of the Java binding, it is mentioned "If the file (or
> znode) exists, it gets the data from the znode, and then invoke the exists()
> callback of Executor if the state has changed. Note, it doesn't have to do
> any Exception processing for the getData call because it has watches pending
> for anything that could cause an error: if the node is deleted before it
> calls ZooKeeper.getData(), the watch event set by the 
> ZooKeeper.exists()triggers a callback "
>
> I read this to mean that if I insert a Thread.sleep() before the getData
> call & removed the node from the cli, somehow (magically) there would be no
> error. But of course, it does not happen
>
> Sleeps for 10 seconds
> org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode =
> NoNode for /zk_test
> at
> org.apache.zookeeper.KeeperException.create(KeeperException.java:102)
> at org.apache.zookeeper.KeeperException.create(KeeperException.java:42)
> at org.apache.zookeeper.ZooKeeper.getData(ZooKeeper.java:921)
> at org.apache.zookeeper.ZooKeeper.getData(ZooKeeper.java:950)
> at DataMonitor.processResult(DataMonitor.java:114)
> at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:512)
>
> Am I doing something wrong (or reading something wrong)?
>
> -- Milind