Instantly share code, notes, and snippets.

Embed
What would you like to do?
def startServer(serverStartFunc: () => Unit) {
val serverStarted = new Semaphore(0)
var serverStartException: Option[Exception] = None
startThread("startZookeeper") {
try {
log.info("Starting ZooKeeper server. clientPort=" + clientPort +
" class=" + zkServer.getClass.getName)
serverStartFunc()
serverStarted.release()
} catch {
case ioex: IOException =>
log.error("ZooKeeper Failed - data directory corruption: " +
ioex.getMessage, ioex)
serverStartException = Some(ioex)
case ex: Exception =>
log.error("ZooKeeper Failed: " + ex.getMessage, ex)
serverStartException = Some(ex)
}
}
if (!serverStarted.tryAcquire(waitingSec, TimeUnit.SECONDS)) {
serverStartException match {
case Some(ex) => throw new RuntimeException(ex)
case None =>
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment