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 00A4010AD0 for ; Fri, 8 Nov 2013 20:59:55 +0000 (UTC) Received: (qmail 74935 invoked by uid 500); 8 Nov 2013 20:59:54 -0000 Delivered-To: apmail-curator-user-archive@curator.apache.org Received: (qmail 74861 invoked by uid 500); 8 Nov 2013 20:59:54 -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 74853 invoked by uid 99); 8 Nov 2013 20:59:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Nov 2013 20:59:54 +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 (athena.apache.org: domain of mckenzie.cam@gmail.com designates 209.85.192.174 as permitted sender) Received: from [209.85.192.174] (HELO mail-pd0-f174.google.com) (209.85.192.174) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Nov 2013 20:59:49 +0000 Received: by mail-pd0-f174.google.com with SMTP id z10so2638867pdj.33 for ; Fri, 08 Nov 2013 12:59:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=5Ljkt6SETsdNIr3sQt7D9BSWVXJ4nj+CbtIczA6TaDM=; b=u2GLIWpJcwPbDM87pkjIVVr3iEqT+ZjiEtch+RpqJXii8kMQkFOZgf26NkdFdcRC+q qDX6aqHr+x1F05bFEVGdHleQpB9/R+q/lLpAuh76jpf9FLPMWZLjS2H0ESn/x+eZBWqO owGaEqrhXeoHFvcUh122q0W2wNGV1bk4GVP563Pvm/emWpiTApnVVareP/wES4qPwaOc 2nxg7ENk9CAqFbpYvasYLXtvSQNewK/tWODwOaQ4YKBx6sNcNrtjjIEFSoo+3bAg5Roz 6kdnx3L2Rq2U6ShqBNcNxh0yWfoPS9ZkIGw2VJBc1OaXvp31+Zex6qqlRihoUcDgwwOg 5UgQ== MIME-Version: 1.0 X-Received: by 10.66.119.136 with SMTP id ku8mr17769693pab.121.1383944369535; Fri, 08 Nov 2013 12:59:29 -0800 (PST) Received: by 10.68.236.7 with HTTP; Fri, 8 Nov 2013 12:59:29 -0800 (PST) In-Reply-To: References: Date: Sat, 9 Nov 2013 07:59:29 +1100 Message-ID: Subject: Re: How to use Curator for Watching the nodes and trigger purpose From: Cameron McKenzie To: user@curator.apache.org Content-Type: multipart/alternative; boundary=e89a8ffbacdf89032804eab0a869 X-Virus-Checked: Checked by ClamAV on apache.org --e89a8ffbacdf89032804eab0a869 Content-Type: text/plain; charset=ISO-8859-1 WHen does handleWatchEvents get called()? In your sample code the method is defined but its not called from your main() function. On Sat, Nov 9, 2013 at 7:56 AM, Techy Teck wrote: > > On Fri, Nov 8, 2013 at 12:31 PM, Cameron McKenzie wrote: > >> client.getCuratorListenable().addListener(new CuratorListener() { >> public void eventReceived(CuratorFramework curator, CuratorEvent >> event) { >> //Your event handling code here. >> } >> }); >> > > > Thanks Cameron and Jordan for the suggestion.. I am also using the same > code in my simple test program but one thing that I am not able to > understand is - My client program should always be running to detect any > trigger happening because of any watches on the parent node right? > Currently, I am running my simple Java static void main code which gets the > children and has the watch code as well - Something like below is my full > program- > > public class ZKWatcher { > > public static void main(String[] args) { > > try { > CuratorFramework client = > CuratorClient.createSimple("localhost:2181"); > client.start(); > > List children = watchedGetChildren(client, "/foo"); > > } 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, String > path, byte[] payload) 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); > } > } > > I run the above program as the simple java application and it gets all the > children from the */foo* parent node but the above program gets stopped > after getting the children. So I am wondering if I am adding any child node > to the same */foo* parent node behind the scene using zkCli, then > eventReceived won't get called for sure as my program was stopped.. > > Which makes me to think, I need to run my above program as some sort of > server way so that it will keep on running once we start it and then if any > trigger is happening because of addition of any child nodes to /foo parent > node then eventReceived will get called automatically? > > if yes, then how to do that? Pardon my ignorance on this. > > > > --e89a8ffbacdf89032804eab0a869 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
WHen does handleWatchEvents get called()? In your sample c= ode the method is defined but its not called from your main() function.


On Sat, Nov= 9, 2013 at 7:56 AM, Techy Teck <comptechgeeky@gmail.com> wrote:

On Fri, Nov 8, 2013 at 12:= 31 PM, Cameron McKenzie <mckenzie.cam@gmail.com> wrote:=
client.getCuratorLis= tenable().addListener(new CuratorListener() {
=A0 =A0 public void= eventReceived(CuratorFramework curator, CuratorEvent event) {
=A0 =A0 =A0 =A0 //Your event handling code here.
=A0 =A0 }
});


Thanks Cameron and Jordan for the suggestion.. I a= m also using the same code in my simple test program but one thing that I a= m not able to understand is - My client program should always be running to= detect any trigger happening because of any watches on the parent node rig= ht? Currently, I am running my simple Java static void main code which gets= the children and has the watch code as well - Something like below is my f= ull program-

public class ZKWatcher {

=A0=A0=A0 public static void main(Strin= g[] args) {

=A0=A0=A0 =A0=A0=A0 try {
=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 client.start();

=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 List<String> children =3D watchedGe= tChildren(client, "/foo");

=A0=A0=A0 =A0=A0=A0 } catch (Ex= ception ex) {
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 ex.printStackTrace();
=A0= =A0=A0 =A0=A0=A0 }
=A0=A0=A0 }

=A0=A0=A0 public static List<St= ring> watchedGetChildren(CuratorFramework client, String path) throws Ex= ception {

=A0=A0=A0 =A0=A0=A0 return client.getChildren().watched().forPath(path)= ;
=A0=A0=A0 }

=A0=A0=A0 public static void handleWatchEvents(Cura= torFramework client, String path, byte[] payload) throws Exception {
=A0= =A0=A0 =A0=A0=A0 // this is one method of getting event/async notifications=
=A0=A0=A0 =A0=A0=A0 CuratorListener listener =3D new CuratorListener() {=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 public void eventReceived(CuratorFramework c= lient, CuratorEvent event) throws Exception {
=A0=A0=A0 =A0=A0=A0 =A0=A0= =A0 =A0=A0=A0 // examine event for details

=A0=A0=A0 =A0=A0=A0 =A0= =A0=A0 =A0=A0=A0 System.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 client.getCuratorListenable().addListener(listener);
=A0=A0=A0 }<= br>}

I run the above program as the= simple java application and it gets all the children from the /foo = parent node but the above program gets stopped after getting the children. = So I am wondering if I am adding any child node to the same /foo par= ent node behind the scene using zkCli, then eventReceived won't get cal= led for sure as my program was stopped..

Which makes me to think, I need to run= my above program as some sort of server way so that it will keep on runnin= g once we start it and then if any trigger is happening because of addition= of any child nodes to /foo parent node then eventReceived will get called = automatically?

if yes, then how to do that? Pardon my= ignorance on this.




--e89a8ffbacdf89032804eab0a869--