Quantcast

How to set a watch for a deletion of a node?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to set a watch for a deletion of a node?

xytd


Is there way to watch for a deletion of a child node? The callback thus contains the node path which is being deleted.

The only way I would see it to work is to load a list of the children and when a ChildrenWatch gets triggered, use it to compare with the list of children returned. But this is not very intuitive. There must be a better way to do this?

Thanks for any suggestion,

Yang
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to set a watch for a deletion of a node?

James A. Robinson-2
You can just set a getData or exists watch on the node you are interested
in.

From the documentation at
http://zookeeper.apache.org/doc/r3.1.2/zookeeperProgrammers.html:

getData() and exists() return information about the data of the node,
whereas getChildren() returns a list of children. Thus, setData() will
trigger data watches for the znode being set (assuming the set is
successful). A successful create() will trigger a data watch for the
znode being created and a child watch for the parent znode. A
successful delete() will trigger both a data watch and a child watch
(since there can be no more children) for a znode being deleted as
well as a child watch for the parent znode.

On Mon, Jun 9, 2014 at 10:20 AM, xytd <[hidden email]> wrote:

>
>
> Is there way to watch for a deletion of a child node? The callback thus
> contains the node path which is being deleted.
>
> The only way I would see it to work is to load a list of the children and
> when a ChildrenWatch gets triggered, use it to compare with the list of
> children returned. But this is not very intuitive. There must be a better
> way to do this?
>
> Thanks for any suggestion,
>
> Yang
>
>
>
>
> --
> View this message in context: http://zookeeper-user.578899.n2.nabble.com/How-to-set-a-watch-for-a-deletion-of-a-node-tp7579974.html
> Sent from the zookeeper-user mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to set a watch for a deletion of a node?

xytd
The thing is I don't want to set a watch on that particular child node.  I am using the parent node as a container table and I would like to be notified through a Watch mechanism any of my child is being deleted and which child is that (via a node path).  

That way I don't have to set a watch for each child node when it is getting created and I can track it on the parent node level only.

Isn't there a way to get around this please?

Thanks for the hints,

Yang
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to set a watch for a deletion of a node?

Jordan Zimmerman-3
Have a look at Curator. It has a recipe to do this exact thing: PathChildrenCache

https://curator.apache.org/curator-recipes/path-cache.html

-Jordan


From: xytd [hidden email]
Reply: [hidden email] [hidden email]
Date: June 9, 2014 at 12:42:49 PM
To: [hidden email] [hidden email]
Subject:  Re: How to set a watch for a deletion of a node?  

The thing is I don't want to set a watch on that particular child node. I am  
using the parent node as a container table and I would like to be notified  
through a Watch mechanism any of my child is being deleted and which child  
is that (via a node path).  

That way I don't have to set a watch for each child node when it is getting  
created and I can track it on the parent node level only.  

Isn't there a way to get around this please?  

Thanks for the hints,  

Yang  




--  
View this message in context: http://zookeeper-user.578899.n2.nabble.com/How-to-set-a-watch-for-a-deletion-of-a-node-tp7579974p7579976.html 
Sent from the zookeeper-user mailing list archive at Nabble.com.  
Loading...