Exploring using curator's TreeCache for grabbing an entire ZK sub-tree

This commit is contained in:
R. Tyler Croy 2015-01-17 14:42:24 -08:00
parent 3a61835cf6
commit 70f0d61e7b
3 changed files with 34 additions and 2 deletions

View File

@ -21,6 +21,10 @@ test {
events "passed", "skipped", "failed", "standardOut", "standardError"
}
}
run {
args zookeeperHosts
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -1,3 +1,4 @@
org.gradle.daemon=true
bintrayUser=
bintrayKey=
zookeeperHosts=

View File

@ -2,15 +2,42 @@ package com.github.lookout.verspaetung
import org.apache.curator.retry.ExponentialBackoffRetry
import org.apache.curator.framework.CuratorFrameworkFactory
import org.apache.curator.framework.CuratorFramework
import org.apache.zookeeper.KeeperException
import org.apache.curator.framework.recipes.cache.TreeCache
import org.apache.curator.framework.recipes.cache.TreeCacheListener
class Main {
static void main(String[] args) {
println "Running!"
println "Running ${args}"
ExponentialBackoffRetry retry = new ExponentialBackoffRetry(1000, 3)
def client = CuratorFrameworkFactory.newClient('lookout-zk-stage1-0.flexilis.org:2181', retry)
CuratorFramework client = CuratorFrameworkFactory.newClient(args[0], retry)
client.start()
TreeCache cache = new TreeCache(client, '/kafka_spout')
println cache
cache.listenable.addListener([
childEvent: { cl, ev ->
println "EV: ${ev}"
}
] as TreeCacheListener)
cache.start()
println 'started..'
Boolean foundChildren = false
Map children = null
while ((children == null) || children.isEmpty()) {
children = cache.getCurrentChildren('/kafka_spout')
println "CHILDREN: ${children}"
Thread.sleep(100)
}
[1, 2, 3].each { Thread.sleep(300) }
return
client.children.forPath('/consumers').each { path ->
try {