curator-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Trevor Hartman <trevorhart...@gmail.com>
Subject Re: PathChildrenCache: blocking rebuild that *does* generate events
Date Tue, 18 Mar 2014 18:46:31 GMT
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
Mime
View raw message