Skip to content

Kairo Application

Start your Server, wait for JVM termination, and clean up afterwards, all with a single call: startAndWait().

Install kairo-application.

build.gradle.kts
dependencies {
implementation("software.airborne.kairo:kairo-application")
}

Call startAndWait() inside a kairo block.

fun main() {
kairo {
val server = Server(...)
server.startAndWait(
release = {
server.stop()
},
)
}
}

The release function is called when the JVM terminates.

Kairo Features shut themselves down gracefully when you call server.stop(). If you have other resources that need to be closed, you can also use the release block for that.

fun main() {
kairo {
val server = Server(...)
server.startAndWait(
release = {
server.stop()
LogManager.shutdown() // Shuts down Log4j2 gracefully.
},
)
}
}

Log4j2 automatically installs a shutdown hook that listens for JVM termination, flushing buffers and ignoring future logging calls. This means that you aren’t guaranteed to see any log messages after the JVM terminates. To see Kairo shutdown messages in your logs,

  1. Add shutdownHook="disable" to your log4j2.xml file.
  2. Add LogManager.shutdown() to your release block.