zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Milind Parikh <milindpar...@gmail.com>
Subject Re: processResults
Date Tue, 28 Sep 2010 04:02:09 GMT
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(10000);
        zk.getData(znode, false, this, null);
        }
        catch (InterruptedException ie) {
        System.out.println(ie);
        }

        }

    }

On Mon, Sep 27, 2010 at 6:56 PM, Milind Parikh <milindparikh@gmail.com>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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message