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 EB7381015E for ; Sat, 9 Nov 2013 00:04:53 +0000 (UTC) Received: (qmail 4715 invoked by uid 500); 9 Nov 2013 00:04:53 -0000 Delivered-To: apmail-curator-user-archive@curator.apache.org Received: (qmail 4692 invoked by uid 500); 9 Nov 2013 00:04:53 -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 4683 invoked by uid 99); 9 Nov 2013 00:04:53 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Nov 2013 00:04:53 +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: domain of comptechgeeky@gmail.com designates 209.85.212.172 as permitted sender) Received: from [209.85.212.172] (HELO mail-wi0-f172.google.com) (209.85.212.172) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Nov 2013 00:04:47 +0000 Received: by mail-wi0-f172.google.com with SMTP id ez12so140295wid.17 for ; Fri, 08 Nov 2013 16:04:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=MBSQ3Xy0zHKhaLw+Mg6Q2fly2YijZfXc54unOIuuGBw=; b=oAv4BM5jFqcTbfOUKU8a9M+ZYqBPPgTp/u0ejNxHAlvqGrB2+Uo9j13qLv3e+s0Ro/ E46nR+Cb1+hXHDsPnbyxgt2bEV71DFZBZpLHrVUbePawfydYuInUiERr0fJMiAKR5gId 17IAE2CIRWPkrBT+SJ/MobSpO17yLp7E+sCeN7jJyu4eStSa2MIASijQ3z01+dnkW2sF jpADPUgFSwaMgFc8nIrp2n8eLQACOWFCoXjNA+GqAKyV3hWp6ry7CVdhCPyZ1lP3SYdD 43sKclrpG6Vv/dypjRhSuzVOui0jYxWADhvTvJf3gmerdAAgTLcj3QTHmW2pAAr7PpIv x0sw== X-Received: by 10.180.149.234 with SMTP id ud10mr4239538wib.25.1383955466514; Fri, 08 Nov 2013 16:04:26 -0800 (PST) MIME-Version: 1.0 Received: by 10.180.100.137 with HTTP; Fri, 8 Nov 2013 16:04:06 -0800 (PST) In-Reply-To: References: From: Techy Teck Date: Fri, 8 Nov 2013 16:04:06 -0800 Message-ID: Subject: Re: How to use Curator for Watching the nodes and trigger purpose To: user Content-Type: multipart/alternative; boundary=001a11c38424f7740a04eab33d8f X-Virus-Checked: Checked by ClamAV on apache.org --001a11c38424f7740a04eab33d8f Content-Type: text/plain; charset=ISO-8859-1 On Fri, Nov 8, 2013 at 1:36 PM, Cameron McKenzie wrote: > for(;;) { > try { > Thread.sleep(50000); > } catch(InterruptedException e) { > } > } > Aah... I was in the impression that I need to start some sort of server using Curator.. Never mind.. It works fine for the first time.. But second time when I create a new child nodes again, it doesn't print out Hello World again which strikes me that you mentioned I need to rewatch the parent node after each event. Below is my example.. Do I need to add anything in eventReceived method to rewatch again? public class ZKWatcher { public static void main(String[] args) { try { CuratorFramework client = CuratorClient.createSimple("localhost:2181"); client.start(); List children = watchedGetChildren(client, "/foo"); System.out.println(children); handleWatchEvents(client); for(;;) { try { Thread.sleep(50000); } catch(InterruptedException e) { } } } catch (Exception ex) { ex.printStackTrace(); } } public static List watchedGetChildren(CuratorFramework client, String path) throws Exception { return client.getChildren().watched().forPath(path); } public static void handleWatchEvents(CuratorFramework client) throws Exception { // this is one method of getting event/async notifications CuratorListener listener = new CuratorListener() { public void eventReceived(CuratorFramework client, CuratorEvent event) throws Exception { // examine event for details System.out.println("Hello World"); } }; client.getCuratorListenable().addListener(listener); } } --001a11c38424f7740a04eab33d8f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

= On Fri, Nov 8, 2013 at 1:36 PM, Cameron McKenzie <mckenzie.cam@gmail.= com> wrote:
for(;;) {
= =A0 =A0 try {
=A0 =A0 =A0 =A0 Thread.sleep(50000);
=A0 = =A0 } catch(InterruptedException e) {
=A0 =A0 }
}


Aah= ... I was in the impression that I need to start some sort of server using = Curator.. Never mind.. It works fine for the first time.. But second time w= hen I create a new child nodes again, it doesn't print out Hello World = again which strikes me that you mentioned I need to rewatch the parent node= after each event. Below is my example.. Do I need to add anything in event= Received method to rewatch again?

=A0=A0=A0 public class ZKWatcher {
=A0=A0=A0
=A0=A0=A0=A0=A0=A0= =A0 public static void main(String[] args) {
=A0=A0=A0
=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0 try {
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 CuratorFramework client =3D CuratorClient.createSimple("localhost:= 2181");
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 client.start();
=A0=A0=A0 =
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 List<String> childr= en =3D watchedGetChildren(client, "/foo");
=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 System.out.println(children);
=A0=A0=A0
= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 handleWatchEvents(client); =A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 for(;;) {
= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 try {
=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Thread.slee= p(50000);
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 } ca= tch(InterruptedException e) {
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 }
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 }
=A0= =A0=A0
=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 } catch (Exception ex) {=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ex.printStackTrace();
=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 }
=A0=A0=A0=A0=A0=A0=A0 }
=A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0 public static List<String> watchedGetChildren= (CuratorFramework client, String path) throws Exception {
=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return client.getChildren()= .watched().forPath(path);
=A0=A0=A0=A0=A0=A0=A0 }
=A0=A0=A0
=A0= =A0=A0=A0=A0=A0=A0 public static void handleWatchEvents(CuratorFramework cl= ient) throws Exception {
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 // this is on= e method of getting event/async notifications
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 CuratorListener listener =3D new CuratorL= istener() {
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 public void ev= entReceived(CuratorFramework client, CuratorEvent event) throws Exception {=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 // examine ev= ent for details
=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Sys= tem.out.println("Hello World");
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 }
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 };
=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0 client.getCuratorListenable().addListener(listener);<= br>=A0=A0=A0=A0=A0=A0=A0 }
=A0=A0=A0 }


--001a11c38424f7740a04eab33d8f--