Skip to content

Instantly share code, notes, and snippets.

@ericacm
Last active December 13, 2015 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericacm/4982036 to your computer and use it in GitHub Desktop.
Save ericacm/4982036 to your computer and use it in GitHub Desktop.
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