You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@zookeeper.apache.org by Kah-Chan Low <ka...@yahoo.com> on 2014/01/16 16:44:15 UTC

How to monitor changes in children's data

I am a novice.
I have a Znode and I want to get notified whenever anyone of the Znode's children has a change of data.
What kind of watch should I place on the Znode?

Thanks!

RE: How to monitor changes in children's data

Posted by Rakesh R <ra...@huawei.com>.
One approach is :

-----Original Message-----
From: Kah-Chan Low [mailto:kahchanlow@yahoo.com] 
Sent: 16 January 2014 21:14
To: user@zookeeper.apache.org
Subject: How to monitor changes in children's data

I am a novice.
I have a Znode and I want to get notified whenever anyone of the Znode's children has a change of data.
What kind of watch should I place on the Znode?

Thanks!

RE: How to monitor changes in children's data

Posted by Rakesh R <ra...@huawei.com>.
One approach is to iterate over the znode children and add data watcher to it. In the below example, I defined one single watcher instance which will handle the events and based on path it can act upon.

for example:

String parentPath = "/myparentnode"; // parent node which holds the children

Watcher w = new Watcher(){
       @Override
       public void process(WatchedEvent watchEvent) {
         //......write logic based on the znode child path
       }
}
// here it would be good to handle the KeeperExceptions 
// according to the business logic
for(String child : children){
   zk.getData(parentpath + "/" + path, w);
}

-Rakesh

-----Original Message-----
From: Kah-Chan Low [mailto:kahchanlow@yahoo.com] 
Sent: 16 January 2014 21:14
To: user@zookeeper.apache.org
Subject: How to monitor changes in children's data

I am a novice.
I have a Znode and I want to get notified whenever anyone of the Znode's children has a change of data.
What kind of watch should I place on the Znode?

Thanks!

Re: How to monitor changes in children's data

Posted by Jordan Zimmerman <jo...@jordanzimmerman.com>.
You can still look at the Curator code to see how it’s done.

-JZ

From: Kah-Chan Low Kah-Chan Low
Reply: user@zookeeper.apache.org user@zookeeper.apache.org, Kah-Chan Low kahchanlow@yahoo.com
Date: January 17, 2014 at 9:51:59 AM
To: user@zookeeper.apache.org user@zookeeper.apache.org
Subject:  Re: How to monitor changes in children's data  
Thanks Rakesh & Jordan!
I should have said that I am using C binding so Curator is out.


So basically what I need to do is to set a watcher on each of the children.  I had hope there was an easier way out...




On Thursday, January 16, 2014 11:49 PM, Rakesh R <ra...@huawei.com> wrote:


Sorry, seems some format issues in the previous mail. Please see the modified one.

One approach is to iterate over the znode children and add data watcher to it.  
In the below example, I defined one single watcher instance which will handle the events and based on path it can act upon.

String parentPath = "/myparentnode"; // parent node which holds the children

Watcher w = new Watcher(){
      @Override
      public void process(WatchedEvent watchEvent) {
        //......write logic based on the znode child path
      }
}

// here it would be good to handle the KeeperExceptions  
// according to the business logic

for(String child : children){
  zk.getData(parentpath + "/" + path, w);  
}


-----Original Message-----
From: Rakesh R  
Sent: 17 January 2014 10:16
To: 'user@zookeeper.apache.org'; 'Kah-Chan Low'
Subject: RE: How to monitor changes in children's data


One approach is to iterate over the znode children and add data watcher to it. In the below example, I defined one single watcher instance which will handle the events and based on path it can act upon.

for example:

String parentPath = "/myparentnode"; // parent node which holds the children

Watcher w = new Watcher(){
      @Override
      public void process(WatchedEvent watchEvent) {
        //......write logic based on the znode child path
      }
}
// here it would be good to handle the KeeperExceptions // according to the business logic for(String child : children){
  zk.getData(parentpath + "/" + path, w); }

-Rakesh

-----Original Message-----
From: Kah-Chan Low [mailto:kahchanlow@yahoo.com]
Sent: 16 January 2014 21:14
To: user@zookeeper.apache.org
Subject: How to monitor changes in children's data

I am a novice.
I have a Znode and I want to get notified whenever anyone of the Znode's children has a change of data.
What kind of watch should I place on the Znode?

Thanks!

Re: How to monitor changes in children's data

Posted by Kah-Chan Low <ka...@yahoo.com>.
Thanks Rakesh & Jordan!
I should have said that I am using C binding so Curator is out.


So basically what I need to do is to set a watcher on each of the children.  I had hope there was an easier way out...




On Thursday, January 16, 2014 11:49 PM, Rakesh R <ra...@huawei.com> wrote:
 

Sorry, seems some format issues in the previous mail. Please see the modified one.

One approach is to iterate over the znode children and add data watcher to it. 
In the below example, I defined one single watcher instance which will handle the events and based on path it can act upon.

String parentPath = "/myparentnode"; // parent node which holds the children

Watcher w = new Watcher(){
       @Override
       public void process(WatchedEvent watchEvent) {
         //......write logic based on the znode child path
       }
}

// here it would be good to handle the KeeperExceptions 
// according to the business logic

for(String child : children){
   zk.getData(parentpath + "/" + path, w); 
}


-----Original Message-----
From: Rakesh R 
Sent: 17 January 2014 10:16
To: 'user@zookeeper.apache.org'; 'Kah-Chan Low'
Subject: RE: How to monitor changes in children's data


One approach is to iterate over the znode children and add data watcher to it. In the below example, I defined one single watcher instance which will handle the events and based on path it can act upon.

for example:

String parentPath = "/myparentnode"; // parent node which holds the children

Watcher w = new Watcher(){
       @Override
       public void process(WatchedEvent watchEvent) {
         //......write logic based on the znode child path
       }
}
// here it would be good to handle the KeeperExceptions // according to the business logic for(String child : children){
   zk.getData(parentpath + "/" + path, w); }

-Rakesh

-----Original Message-----
From: Kah-Chan Low [mailto:kahchanlow@yahoo.com]
Sent: 16 January 2014 21:14
To: user@zookeeper.apache.org
Subject: How to monitor changes in children's data

I am a novice.
I have a Znode and I want to get notified whenever anyone of the Znode's children has a change of data.
What kind of watch should I place on the Znode?

Thanks!

RE: How to monitor changes in children's data

Posted by Rakesh R <ra...@huawei.com>.
Sorry, seems some format issues in the previous mail. Please see the modified one.

One approach is to iterate over the znode children and add data watcher to it. 
In the below example, I defined one single watcher instance which will handle the events and based on path it can act upon.

String parentPath = "/myparentnode"; // parent node which holds the children

Watcher w = new Watcher(){
       @Override
       public void process(WatchedEvent watchEvent) {
         //......write logic based on the znode child path
       }
}

// here it would be good to handle the KeeperExceptions 
// according to the business logic

for(String child : children){
   zk.getData(parentpath + "/" + path, w); 
}


-----Original Message-----
From: Rakesh R 
Sent: 17 January 2014 10:16
To: 'user@zookeeper.apache.org'; 'Kah-Chan Low'
Subject: RE: How to monitor changes in children's data


One approach is to iterate over the znode children and add data watcher to it. In the below example, I defined one single watcher instance which will handle the events and based on path it can act upon.

for example:

String parentPath = "/myparentnode"; // parent node which holds the children

Watcher w = new Watcher(){
       @Override
       public void process(WatchedEvent watchEvent) {
         //......write logic based on the znode child path
       }
}
// here it would be good to handle the KeeperExceptions // according to the business logic for(String child : children){
   zk.getData(parentpath + "/" + path, w); }

-Rakesh

-----Original Message-----
From: Kah-Chan Low [mailto:kahchanlow@yahoo.com]
Sent: 16 January 2014 21:14
To: user@zookeeper.apache.org
Subject: How to monitor changes in children's data

I am a novice.
I have a Znode and I want to get notified whenever anyone of the Znode's children has a change of data.
What kind of watch should I place on the Znode?

Thanks!

Re: How to monitor changes in children's data

Posted by Jordan Zimmerman <jo...@jordanzimmerman.com>.
Have at look at Curator’s PathChildrenCache. It does this. 

-Jordan

From: Kah-Chan Low Kah-Chan Low
Reply: user@zookeeper.apache.org user@zookeeper.apache.org, Kah-Chan Low kahchanlow@yahoo.com
Date: January 16, 2014 at 7:44:54 AM
To: user@zookeeper.apache.org user@zookeeper.apache.org
Subject:  How to monitor changes in children's data  
I am a novice.  
I have a Znode and I want to get notified whenever anyone of the Znode's children has a change of data.  
What kind of watch should I place on the Znode?  

Thanks!