Skip to content

Instantly share code, notes, and snippets.

@lankydan
Created August 12, 2019 09: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 lankydan/8287ace91fe47e23490d7c7fa52598b1 to your computer and use it in GitHub Desktop.
Save lankydan/8287ace91fe47e23490d7c7fa52598b1 to your computer and use it in GitHub Desktop.
Corda + Ktor - gracefully disconnecting from node
fun NettyApplicationEngine.addShutdownHook() {
Runtime.getRuntime().addShutdownHook(Thread {
stop(1, 1, TimeUnit.SECONDS)
})
Thread.currentThread().join()
}
fun Application.addShutdownEvent(connection: CordaRPCConnection) {
environment.monitor.subscribe(ApplicationStopped) {
connection.notifyServerAndClose()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment