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 B5E6210203 for ; Mon, 18 Nov 2013 06:20:48 +0000 (UTC) Received: (qmail 11154 invoked by uid 500); 18 Nov 2013 06:20:46 -0000 Delivered-To: apmail-curator-user-archive@curator.apache.org Received: (qmail 11116 invoked by uid 500); 18 Nov 2013 06:20:44 -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 11107 invoked by uid 99); 18 Nov 2013 06:20:42 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Nov 2013 06:20:42 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of shaun.senecal@mail.rakuten.com designates 213.199.154.250 as permitted sender) Received: from [213.199.154.250] (HELO db9outboundpool.messaging.microsoft.com) (213.199.154.250) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Nov 2013 06:20:33 +0000 Received: from mail203-db9-R.bigfish.com (10.174.16.246) by DB9EHSOBE018.bigfish.com (10.174.14.81) with Microsoft SMTP Server id 14.1.225.22; Mon, 18 Nov 2013 06:20:10 +0000 Received: from mail203-db9 (localhost [127.0.0.1]) by mail203-db9-R.bigfish.com (Postfix) with ESMTP id E3EEF405E2 for ; Mon, 18 Nov 2013 06:20:10 +0000 (UTC) X-Forefront-Antispam-Report: CIP:111.221.116.165;KIP:(null);UIP:(null);IPV:NLI;H:SIXPRD0310HT001.apcprd03.prod.outlook.com;RD:none;EFVD:NLI X-SpamScore: -1 X-BigFish: VPS-1(z579ehz9371Ic85dhzz1f42h208ch1ee6h1de0h1fdah2073h2146h1202h1e76h1d1ah1d2ah1fc6hzz1de098h18c673h1de097hz2fh109h2a8h839hd25hf0ah1288h12a5h12bdh137ah1441h1504h1537h153bh15d0h162dh1631h1758h18e1h1946h19b5h19ceh1ad9h1b0ah1bceh224fh1d07h1d0ch1d2eh1d3fh1de9h1dfeh1dffh1e1dh1fe8h1ff5h20f0h2216h1155h) Received-SPF: pass (mail203-db9: domain of mail.rakuten.com designates 111.221.116.165 as permitted sender) client-ip=111.221.116.165; envelope-from=shaun.senecal@mail.rakuten.com; helo=SIXPRD0310HT001.apcprd03.prod.outlook.com ;.outlook.com ; Received: from mail203-db9 (localhost.localdomain [127.0.0.1]) by mail203-db9 (MessageSwitch) id 1384755608940707_29480; Mon, 18 Nov 2013 06:20:08 +0000 (UTC) Received: from DB9EHSMHS031.bigfish.com (unknown [10.174.16.241]) by mail203-db9.bigfish.com (Postfix) with ESMTP id D94C02C0103 for ; Mon, 18 Nov 2013 06:20:08 +0000 (UTC) Received: from SIXPRD0310HT001.apcprd03.prod.outlook.com (111.221.116.165) by DB9EHSMHS031.bigfish.com (10.174.14.41) with Microsoft SMTP Server (TLS) id 14.16.227.3; Mon, 18 Nov 2013 06:20:08 +0000 Received: from SIXPRD0310MB360.apcprd03.prod.outlook.com ([169.254.3.190]) by SIXPRD0310HT001.apcprd03.prod.outlook.com ([10.255.22.164]) with mapi id 14.16.0383.001; Mon, 18 Nov 2013 06:19:43 +0000 From: "Senecal, Shaun | Shaun | BDD" To: "user@curator.apache.org" Subject: RE: How to watch for events on all descendant nodes in ZooKeeper using curator? Thread-Topic: How to watch for events on all descendant nodes in ZooKeeper using curator? Thread-Index: AQHO5BfL/8nw4DjbbUCAfQpQ5+Up2poqg8KL Date: Mon, 18 Nov 2013 06:19:43 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [202.72.49.236] Content-Type: multipart/alternative; boundary="_000_EB75668D48CD564CB2B9A4007534C91C4D45E8C8SIXPRD0310MB360_" MIME-Version: 1.0 X-OriginatorOrg: mail.rakuten.com X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn% X-Virus-Checked: Checked by ClamAV on apache.org --_000_EB75668D48CD564CB2B9A4007534C91C4D45E8C8SIXPRD0310MB360_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable You need to set a child watcher on each node you want to watch. So if you= initially set a watch on "/rj/colo", then a new node is created (ie: "/rj/= colo/phx") you need to add a new watch on the new node as well. ________________________________ From: Techy Teck [comptechgeeky@gmail.com] Sent: Monday, November 18, 2013 1:35 PM To: user Subject: How to watch for events on all descendant nodes in ZooKeeper using= curator? I am working on a project in which I need to maintain a watches on a node, = and that nodes children and that nodes children as well. I have tried using= PathCache but I am not sure how to watch for childrens children here? Here my root node is - "/rj/colo" and keeping a watch on that node as well. Whenever I am adding any new node to "/rj/colo" such as "/rj/colo/phx", "/r= j/colo/slc", "/rj/colo/lvs" then the watch gets triggered. But if I am addi= ng any new node to "/rj/colo/phx" or "/rj/colo/slc", then no watches get tr= iggerd and I am not sure how to add the code for that as well? Any thoughts= how this can be done efficiently? 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 "/rj/colo" children but not the child= rens of "/rj/colo/phx" and etc etc. private static final String PATH =3D "/rj/colo"; public static void main(String[] args) { CuratorFramework client =3D null; PathChildrenCache cache =3D null; try { client =3D CuratorClient.createSimple("localhost:2181"); client.start(); // in this example we will cache data. Notice that this is opti= onal. cache =3D new PathChildrenCache(client, PATH, true); cache.start(); addListener(cache); for(;;) { try { Thread.sleep(50000); } catch(InterruptedException e) { } } // processCommands(client, cache); } catch (Exception e1) { e1.printStackTrace(); } } Below is my addListener method - private static void addListener(PathChildrenCache cache) { PathChildrenCacheListener listener =3D new PathChildrenCacheListene= r() { public void childEvent(CuratorFramework client, PathChildrenCac= heEvent event) throws Exception { switch (event.getType()) { case CHILD_ADDED: { System.out.println("Node added: " + ZKPaths.getNodeFrom= Path(event.getData().getPath())); break; } case CHILD_UPDATED: { System.out.println("Node changed: " + ZKPaths.getNod= eFromPath(event.getData().getPath())); break; } case CHILD_REMOVED: { System.out.println("Node removed: " + ZKPaths.getNod= eFromPath(event.getData().getPath())); break; } default: break; } } }; cache.getListenable().addListener(listener); } --_000_EB75668D48CD564CB2B9A4007534C91C4D45E8C8SIXPRD0310MB360_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
You need to set a child watcher on each node you want to watch. = ;  So if you initially set a watch on "/rj/colo", then a new= node is created (ie: "/rj/colo/phx") you need to add a new watch on the new node as well.


From: Techy Teck [comptechgeeky@gmail.com= ]
Sent: Monday, November 18, 2013 1:35 PM
To: user
Subject: How to watch for events on all descendant nodes in ZooKeepe= r using curator?

I am working on a project in which I need to maintain a wa= tches on a node, and that nodes children and that nodes children as well. I= have tried using PathCache but I am not sure how to watch for childrens ch= ildren here?

Here my root node is - "/rj/colo" and keeping a watch on that nod= e as well.

Whenever I am adding any new node to "/rj/colo" such as "/rj= /colo/phx", "/rj/colo/slc", "/rj/colo/lvs" then th= e watch gets triggered. But if I am adding any new node to "/rj/colo/p= hx" or "/rj/colo/slc", then no watches get triggerd and I am= not sure how to add the code for that as well? Any thoughts how this can be done efficient= ly? May be if somebody has done this in the past.. So any example will be o= f great help to me..

Below is my code which works fine for "/rj/colo" children but not= the childrens of "/rj/colo/phx" and etc etc.
   
    private static final String PATH =3D "/rj/colo"= ;;

    public static void main(String[] args) {
        CuratorFramework client =3D null;
        PathChildrenCache cache =3D null;
        try {
            client =3D Curator= Client.createSimple("localhost:2181");
            client.start();
            // in this example= we will cache data. Notice that this is optional.
            cache =3D new Path= ChildrenCache(client, PATH, true);
            cache.start();

            addListener(cache)= ;

            for(;;) {
               = try {
               =     Thread.sleep(50000);
               = } catch(InterruptedException e) {
               = }
            }

            // processCommands= (client, cache);
        } catch (Exception e1) {
            e1.printStackTrace= ();
        }
    }
   
Below is my addListener method -    

    private static void addListener(PathChildrenCache cache)= {

        PathChildrenCacheListener listener = =3D new PathChildrenCacheListener() {
            public void childE= vent(CuratorFramework client, PathChildrenCacheEvent event) throws Exceptio= n {
               = switch (event.getType()) {
               = case CHILD_ADDED: {
               =     System.out.println("Node added: " + ZKPat= hs.getNodeFromPath(event.getData().getPath()));
               =     break;
               = }

               = case CHILD_UPDATED: {
               =     System.out.println("Node changed: " &nbs= p;  + ZKPaths.getNodeFromPath(event.getData().getPath()));
               =     break;
               = }

               = case CHILD_REMOVED: {
               =     System.out.println("Node removed: " &nbs= p;  + ZKPaths.getNodeFromPath(event.getData().getPath()));
               =     break;
               = }
               = default:
               =     break;
               = }
            }
        };
        cache.getListenable().addListener(lis= tener);
    }

--_000_EB75668D48CD564CB2B9A4007534C91C4D45E8C8SIXPRD0310MB360_--