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 20C18101DF for ; Sat, 9 Nov 2013 00:13:12 +0000 (UTC) Received: (qmail 16552 invoked by uid 500); 9 Nov 2013 00:13:12 -0000 Delivered-To: apmail-curator-user-archive@curator.apache.org Received: (qmail 16520 invoked by uid 500); 9 Nov 2013 00:13:12 -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 16511 invoked by uid 99); 9 Nov 2013 00:13:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Nov 2013 00:13:12 +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 (athena.apache.org: domain of comptechgeeky@gmail.com designates 74.125.82.42 as permitted sender) Received: from [74.125.82.42] (HELO mail-wg0-f42.google.com) (74.125.82.42) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Nov 2013 00:13:01 +0000 Received: by mail-wg0-f42.google.com with SMTP id k14so355674wgh.1 for ; Fri, 08 Nov 2013 16:12:40 -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=dAmkpIRvxyFvVuxl48S9638VUIKLzPQBihhLGZ73/Pg=; b=wOTI8LmhoWhzT8ivGoz85l17/GBwcH/4b+TS2LkVPydeBmW0IC1RfgvYq02Bv5uf2p PdsY6YW1O6F0WqwXd7wVRQiV90xeda2jJFs8eNnSTwQjQMEa8P9q7eMfqldR6JXQoTiB bLDIP+G5BC1X6RQOdiiZmMSpCB/y9Ktf65uMu2KMN0mke3bkuwDlBSY+YDuHMi8IrEgQ o3K0GZP48WJRRBrcyiJDuD87Pwa/1BJpIO4qk0Vdq2abIFTL+d/6tcMpW8uwlP0bFiip fOfPXUz8obuAFJIT6dz4VBvROqIQmtm3PDADnwHsvSK+5jtJmljwIxDMp6tyDNGka5RN 04Ng== X-Received: by 10.180.185.101 with SMTP id fb5mr4302993wic.11.1383955960324; Fri, 08 Nov 2013 16:12:40 -0800 (PST) MIME-Version: 1.0 Received: by 10.180.100.137 with HTTP; Fri, 8 Nov 2013 16:12:20 -0800 (PST) In-Reply-To: References: From: Techy Teck Date: Fri, 8 Nov 2013 16:12:20 -0800 Message-ID: Subject: Re: How to use Curator for Watching the nodes and trigger purpose To: user Content-Type: multipart/alternative; boundary=001a11c2448e6665b704eab35b0a X-Virus-Checked: Checked by ClamAV on apache.org --001a11c2448e6665b704eab35b0a Content-Type: text/plain; charset=ISO-8859-1 This is working for me after I added watchedGetChildren method. Is this the right way to do it? public void eventReceived(CuratorFramework client, CuratorEvent event) throws Exception { // examine event for details System.out.println("Hello World"); watchedGetChildren(client, "/foo"); } On Fri, Nov 8, 2013 at 4:04 PM, Techy Teck wrote: > > 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); > } > } > > > --001a11c2448e6665b704eab35b0a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
This is working for me after I added watchedGetChildren me= thod. Is this the right way to do it?

public void eventReceived(Cura= torFramework client, 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 watchedGetChildren= (client, "/foo");
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 }


On Fri, Nov 8, 2= 013 at 4:04 PM, Techy Teck <comptechgeeky@gmail.com> w= rote:

On Fri, Nov 8, 2013 at 1:3= 6 PM, Cameron McKenzie <mckenzie.cam@gmail.com> wrote:<= br>
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 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 paren= t node after each event. Below is my example.. Do I need to add anything in= eventReceived 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.sleep(50000);
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0 } catch(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 } c= atch (Exception ex) {
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ex.p= rintStackTrace();
=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<Strin= g> watchedGetChildren(CuratorFramework client, String path) throws Excep= tion {
=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 }



--001a11c2448e6665b704eab35b0a--