mirror of https://github.com/reiseburo/offtopic
Move the withCurator method into CuratorPool to use outside of KafkaService
This commit is contained in:
parent
2677018943
commit
69ed3f3cad
|
@ -15,7 +15,7 @@ class KafkaService {
|
|||
def brokers = new ArrayList()
|
||||
def parser = new JsonSlurper()
|
||||
|
||||
withCurator { c ->
|
||||
CuratorPool.withCurator { c ->
|
||||
c.getChildren().forPath(BROKERS_PATH).each { String id ->
|
||||
// Pulling this into a String buffer since parse(byte[]) is
|
||||
// throwing a stackoverflow error
|
||||
|
@ -29,20 +29,9 @@ class KafkaService {
|
|||
|
||||
public static ArrayList fetchTopics() {
|
||||
ArrayList brokers = null
|
||||
withCurator { c ->
|
||||
CuratorPool.withCurator { c ->
|
||||
brokers = c.getChildren().forPath(TOPICS_PATH)
|
||||
}
|
||||
return brokers
|
||||
}
|
||||
|
||||
private static void withCurator(Closure closure) {
|
||||
def curator = null
|
||||
try {
|
||||
curator = CuratorPool.instance.borrowObject()
|
||||
closure.call(curator.client)
|
||||
}
|
||||
finally {
|
||||
CuratorPool.instance.returnObject(curator)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,4 +20,15 @@ class CuratorPool extends GenericObjectPool<CuratorClient>{
|
|||
super(new CuratorClientObjectFactory(zookeepers))
|
||||
println "CREATING WITH ${zookeepers}"
|
||||
}
|
||||
|
||||
public static void withCurator(Closure closure) {
|
||||
def curator = null
|
||||
try {
|
||||
curator = CuratorPool.instance.borrowObject()
|
||||
closure.call(curator.client)
|
||||
}
|
||||
finally {
|
||||
CuratorPool.instance.returnObject(curator)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue