Created
August 12, 2019 09:08
-
-
Save lankydan/8287ace91fe47e23490d7c7fa52598b1 to your computer and use it in GitHub Desktop.
Corda + Ktor - gracefully disconnecting from node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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