Return-Path: X-Original-To: apmail-curator-user-archive@minotaur.apache.org Delivered-To: apmail-curator-user-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C839510E5C for ; Mon, 10 Feb 2014 03:38:08 +0000 (UTC) Received: (qmail 90422 invoked by uid 500); 10 Feb 2014 03:38:07 -0000 Delivered-To: apmail-curator-user-archive@curator.apache.org Received: (qmail 90320 invoked by uid 500); 10 Feb 2014 03:38:06 -0000 Mailing-List: contact user-help@curator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@curator.apache.org Delivered-To: mailing list user@curator.apache.org Received: (qmail 90312 invoked by uid 99); 10 Feb 2014 03:38:06 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Feb 2014 03:38:06 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy includes SPF record at spf.trusted-forwarder.org) Received: from [209.85.213.170] (HELO mail-ig0-f170.google.com) (209.85.213.170) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Feb 2014 03:37:58 +0000 Received: by mail-ig0-f170.google.com with SMTP id m12so5837880iga.1 for ; Sun, 09 Feb 2014 19:37:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to :references:subject:mime-version:content-type; bh=wa9Mo5vuDzzcsX5Am3oM3U3JyuXqcoF8znTG6DLxmmw=; b=PXZeg9SDWTyKySqoWopbr90MhrFm+3snOqwwP3mTIFBd7cfougt7mr4BAOP09WIt7P fYABHvHScoPX6/4berBjHUhtpu2aVh9wE6MYx7G+8J1dpBrbDwM6S6zKKFDm4uTDZn6h 2d9vw5Y8GSnv+slBYR/jU1QrLXj4qhE6SVZIQXtPOF9Xe82OjlPEjb6LuxlR0QTikgIk ngyCf1lghHVp8xCADfAT7RFiFrnBgmDhTQyQN/CbXk/Tf3tdsevoVlkurGerHUUoAYz7 kjroGHH2H4iehTCrB+wUSne7FKKSJkG8dtqpEwcwq7qQ04mnhC0Y4dPvKemGwyjJfBOq FZzQ== X-Gm-Message-State: ALoCoQmpky1hCHloN1D5i6WxAq8AXfslX5we1xtdZ5dNN8qoF+TFuWfQqBP3fmcp47enkz47vYd1 X-Received: by 10.50.78.229 with SMTP id e5mr11696524igx.49.1392003456898; Sun, 09 Feb 2014 19:37:36 -0800 (PST) Received: from Jordans-MacBook-Pro.local ([190.219.168.142]) by mx.google.com with ESMTPSA id kt2sm40589628igb.1.2014.02.09.19.37.35 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 09 Feb 2014 19:37:36 -0800 (PST) Date: Sun, 9 Feb 2014 22:19:07 -0500 From: Jordan Zimmerman To: Check Peck Cc: user Message-ID: In-Reply-To: References: Subject: Re: How to watch on descendant znodes using Curator PathCache? X-Mailer: Airmail (223) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="52f8497c_71ea1109_10880" X-Virus-Checked: Checked by ClamAV on apache.org --52f8497c_71ea1109_10880 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline That=E2=80=99s essentially what I was suggesting. But, you=E2=80=99d need= to keep track of all the created PathChildrenCache objects in a map or s= omething so that you can delete/close them when needed. Also, use a commo= n executor service to avoid thread pool explosion. -JZ =46rom:=C2=A0Check Peck Check Peck Reply:=C2=A0Check Peck comptechgeeky=40gmail.com Date:=C2=A0=46ebruary 9, 2014 at 10:10:26 PM To:=C2=A0Jordan Zimmerman jordan=40jordanzimmerman.com Subject:=C2=A0 Re: How to watch on descendant znodes using Curator PathCa= che=3F =20 What about for now, If I keep on recursively using PathChildrenCache for = making a watches on each children's=3F =C2=A0=C2=A0=C2=A0 private static void addListener(PathChildrenCache cach= e) =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 PathChildrenCacheListener list= ener =3D new PathChildrenCacheListener() =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 public= void childEvent(Curator=46ramework client, PathChildrenCacheEvent event)= throws Exception =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 switch (event.getType()) =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 case CHILD=5FADDED: =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 String pa= th =3D ZKPaths.getPathAndNode(event.getData().getPath()).getPath(); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 String no= de =3D ZKPaths.getNode=46romPath(event.getData().getPath()); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 System.ou= t.println(=22Node added: =22 + path + =22 =22 + node); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // recurs= ively keep on creating watches =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 PathChild= renCache cache =3D new PathChildrenCache(client, path + =22/=22 + node, t= rue); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cache.sta= rt(); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 addListen= er(cache); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 break; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =7D =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 =7D =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =7D =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =7D =C2=A0=C2=A0=C2=A0 =7D Will there be any problem if I do it like this=3F On Sun, =46eb 9, 2014 at 6:53 PM, Jordan Zimmerman wrote: If I were to do something like this I=E2=80=99d use a Guava Cache or some= thing to hold PathChildrenCache objects for each child node. That=E2=80=99= s a quick=E2=80=99n=E2=80=99dirty solution. I think you=E2=80=99d want to= pass in a common=C2=A0CloseableExecutorService to avoid too many threads= . This might get cumbersome to manage though. If you only need the one su= b-level, you could use NodeCache for each of the children instead of Path= ChildrenCache. Whenever the PathChildrenCache sends a CHILD=5FADDED, you = allocate a new PatchChildrenCache/NodeCache for that node. When=C2=A0CHIL= D=5FREMOVED is sent, close and remove it. So, what you end with is a map = of PatchChildrenCache/NodeCache instances.=C2=A0 So, this is off the top of my head and I haven=E2=80=99t thought through = all the edge cases. If it works, though, it might make a nice recipe addi= tion. -JZ =46rom:=C2=A0Check Peck Check Peck Reply:=C2=A0Check Peck comptechgeeky=40gmail.com Date:=C2=A0=46ebruary 9, 2014 at 9:35:24 PM To:=C2=A0Jordan Zimmerman jordan=40jordanzimmerman.com Subject:=C2=A0 Re: How to watch on descendant znodes using Curator PathCa= che=3F Thanks for suggestion. I am using PathChildrenCache for one level. =46or = example - If my root node is - =22/my/test=22 and I am keeping a watch on that node= using the PathChildrenCache as mentioned in my previous email code. So s= uppose if these nodes gets added to my root node - =C2=A0=C2=A0=C2=A0 =22/my/test/test1=22 =C2=A0=C2=A0=C2=A0 =22/my/test/test2=22 =C2=A0=C2=A0=C2=A0 =22/my/test/test3=22 =C2=A0=C2=A0=C2=A0 Then I get notified and it works fine with the PathChildrenCache code but= if any new node gets added, updated or removed to =60=22/my/test/test1=22= =60, =60=22/my/test/test2=22=60 and =60=22/my/test/test3=22=60 then it do= esn't works and no watches gets triggered and I am not able to understand= how to make that work as my understanding is very limited as of now. On Sun, =46eb 9, 2014 at 6:31 PM, Jordan Zimmerman wrote: Do you need just the one level=3F If so, why not use PathChildrenCache:=C2= =A0http://curator.apache.org/curator-recipes/path-cache.html -JZ =46rom:=C2=A0Check Peck Check Peck Reply:=C2=A0user=40curator.apache.org user=40curator.apache.org Date:=C2=A0=46ebruary 9, 2014 at 9:08:20 PM To:=C2=A0user user=40curator.apache.org Subject:=C2=A0 How to watch on descendant znodes using Curator PathCache=3F= I am working on a project in which I need to maintain a watches on a node= , and that nodes children as well. I have tried using PathCache but I am = not sure how to watch for childrens children here=3F Here my root node is - =60=22/my/test=22=60 and I am keeping a watch on t= hat node using the below code. What I want to do is, to keep the watch on= =60=22/my/test=22=60 znode. So suppose if these nodes gets added to my r= oot node - =C2=A0=C2=A0=C2=A0 =22/my/test/test1=22 =C2=A0=C2=A0=C2=A0 =22/my/test/test2=22 =C2=A0=C2=A0=C2=A0 =22/my/test/test3=22 =C2=A0=C2=A0=C2=A0 Then I should get notified (till this part I am able to make it work) but= if any new node gets added, updated or removed to =60=22/my/test/test1=22= =60, =60=22/my/test/test2=22=60 and =60=22/my/test/test3=22=60 then I sho= uld also get notified and this is the part I am not able to understand ho= w to make it work. Whenever I am adding any new node to =60=22/my/test=22=60 such as =60=22/= my/test/test1=22=60, =60=22/my/test/test2=22=60, =60=22/my/test/test3=22=60= then the watch gets triggered with the use of below code. But if I am ad= ding any new node to =60=22/my/test/test1=22=60 or =60=22/my/test/test2=22= =60, then no watches get triggerd and I am not sure how to add the code f= or that as well=3F Any thoughts how this can be done=3F May be if somebody has done this in the past.. So any example will be of = great help to me.. Below is my code which works fine for =60=22/my/test=22=60 children but n= ot the childrens of =60=22/my/test/test1=22=60 and etc etc. =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 private static final String PATH =3D =22/my/test=22; =C2=A0=C2=A0=C2=A0 public static void main(String=5B=5D args) =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Curator=46ramework client =3D = null; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 PathChildrenCache cache =3D nu= ll; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 client= =3D CuratorClient.createSimple(=22localhost:2181=22); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 client= .start(); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // in = this example we will cache data. Notice that this is optional. =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cache = =3D new PathChildrenCache(client, PATH, true); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cache.= start(); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 addLis= tener(cache); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 for(;;= ) =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 try =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Thread.sleep(50000); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 =7D catch(InterruptedException e) =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 =7D =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =7D =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =7D catch (Exception e1) =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 e1.pri= ntStackTrace(); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =7D =C2=A0=C2=A0=C2=A0 =7D =C2=A0=C2=A0 Below is my addListener method -=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 private static void addListener(PathChildrenCache cach= e) =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 PathChildrenCacheListener list= ener =3D new PathChildrenCacheListener() =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 public= void childEvent(Curator=46ramework client, PathChildrenCacheEvent event)= throws Exception =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 switch (event.getType()) =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 case CHILD=5FADDED: =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 System.out.println(=22Node added:= =22 + ZKPaths.getNode=46romPath(event.getData().getPath())); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 break; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 =7D =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 case CHILD=5FUPDATED: =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 System.out.println(=22Node change= d: =22=C2=A0=C2=A0=C2=A0 + ZKPaths.getNode=46romPath(event.getData().getP= ath())); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 break; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 =7D =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 case CHILD=5FREMOVED: =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 System.out.println(=22Node remove= d: =22=C2=A0=C2=A0=C2=A0 + ZKPaths.getNode=46romPath(event.getData().getP= ath())); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 break; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 =7D =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 default: =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 break; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 =7D =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =7D =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =7D; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cache.getListenable().addListe= ner(listener); =C2=A0=C2=A0=C2=A0 =7D =C2=A0=C2=A0=C2=A0 Can anyone provide a simple example for this for my use case=3F I am usin= g Curator 2.4.0 which got released recently. --52f8497c_71ea1109_10880 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline