Yes, if you want to keep watching a node after you've been notified that it's changed then you need to add another watch to it.
On Sat, Nov 9, 2013 at 11:12 AM, Techy Teck <[email protected]> wrote: > 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 <[email protected]>wrote: > >> >> On Fri, Nov 8, 2013 at 1:36 PM, Cameron McKenzie >> <[email protected]>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<String> 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<String> 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); >> } >> } >> >> >> >
