You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@curator.apache.org by Trevor Hartman <tr...@gmail.com> on 2014/03/18 19:27:35 UTC
PathChildrenCache: blocking rebuild that *does* generate events
In PathChildrenCache source, I see rebuild’s docs say:
* NOTE: this is a BLOCKING method. Completely rebuild the internal cache by querying
* for all needed data WITHOUT generating any events to send to listeners.
What if I want to block until cache is fully consistent, yet still fire all corresponding events? StartMode.POST_INITIALIZED_EVENT is nearly what I want, except I want to block until it’s done.
Thanks,
Trevor
Re: PathChildrenCache: blocking rebuild that *does* generate
events
Posted by Trevor Hartman <tr...@gmail.com>.
Makes sense, thank you.
Trevor
From: Jordan Zimmerman jordan@jordanzimmerman.com
Reply: user@curator.apache.org user@curator.apache.org
Date: March 18, 2014 at 12:42:22 PM
To: user@curator.apache.org user@curator.apache.org
Subject: Re: PathChildrenCache: blocking rebuild that *does* generate events
BTW - I think that that comment is misleading… I don’t remember why I wrote such an ominous message.
What if I want to block until cache is fully consistent, yet still fire all corresponding events? StartMode.POST_INITIALIZED_EVENT is nearly what I want, except I want to block until it’s done.
You’d need to write your own blocking code ala:
final CountDownLatch latch = new CountDownLatch(1);
PathChildrenCacheListener myListener = new PathChildrenCacheListener(){
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
if ( event.getType() == INITIALIZED ) {
latch.countDown();
}
}
};
PathChildrenCache cache = …
cache.getListenable().addListener(myListener);
cache.start(StartMode.POST_INITIALIZED_EVENT);
latch.await(…)
From: Trevor Hartman trevorhartman@gmail.com
Reply: user@curator.apache.org user@curator.apache.org
Date: March 18, 2014 at 1:28:29 PM
To: user@curator.apache.org user@curator.apache.org
Subject: PathChildrenCache: blocking rebuild that *does* generate events
In PathChildrenCache source, I see rebuild’s docs say:
* NOTE: this is a BLOCKING method. Completely rebuild the internal cache by querying
* for all needed data WITHOUT generating any events to send to listeners.
What if I want to block until cache is fully consistent, yet still fire all corresponding events? StartMode.POST_INITIALIZED_EVENT is nearly what I want, except I want to block until it’s done.
Thanks,
Trevor
Re: PathChildrenCache: blocking rebuild that *does* generate
events
Posted by Jordan Zimmerman <jo...@jordanzimmerman.com>.
BTW - I think that that comment is misleading… I don’t remember why I wrote such an ominous message.
What if I want to block until cache is fully consistent, yet still fire all corresponding events? StartMode.POST_INITIALIZED_EVENT is nearly what I want, except I want to block until it’s done.
You’d need to write your own blocking code ala:
final CountDownLatch latch = new CountDownLatch(1);
PathChildrenCacheListener myListener = new PathChildrenCacheListener(){
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
if ( event.getType() == INITIALIZED ) {
latch.countDown();
}
}
};
PathChildrenCache cache = …
cache.getListenable().addListener(myListener);
cache.start(StartMode.POST_INITIALIZED_EVENT);
latch.await(…)
From: Trevor Hartman trevorhartman@gmail.com
Reply: user@curator.apache.org user@curator.apache.org
Date: March 18, 2014 at 1:28:29 PM
To: user@curator.apache.org user@curator.apache.org
Subject: PathChildrenCache: blocking rebuild that *does* generate events
In PathChildrenCache source, I see rebuild’s docs say:
* NOTE: this is a BLOCKING method. Completely rebuild the internal cache by querying
* for all needed data WITHOUT generating any events to send to listeners.
What if I want to block until cache is fully consistent, yet still fire all corresponding events? StartMode.POST_INITIALIZED_EVENT is nearly what I want, except I want to block until it’s done.
Thanks,
Trevor