https://kotlinlang.org logo
#announcements
Title
# announcements
c

Cyril Scetbon

10/04/2019, 1:30 PM
Hey, any documentation reference on how to read configuration parameters from files and reload the app on configuration changes ?
b

Big Chungus

10/04/2019, 1:33 PM
Well you can always start an app as a coroutines job and then have a separate coroutine periodically checking for config changes. When it detects the changes, cancel app job and spawn a new one. It's pretty simple to implement
c

Cyril Scetbon

10/04/2019, 1:34 PM
I would prefer using something that already exists as a library/module
b

Big Chungus

10/04/2019, 1:34 PM
Oh. Never heard of one I'm affraid.
👌 1
But again, I don't think there's a need for such a library. Here's a pseudo-code for it:
Copy code
fun main() {
  runBlocking{
    var config = TODO("Read initial config as data class")
    var app = launch(Dispatchers.Main) {
      initApp(config)
    }
    launch(Dispatchers.Default) {
      delay(TODO("Check interval"))
      val currentConfig = TODO("Read config")
      if(config != currentConfig) {
       app.cancelAndJoin()
        config = currentConfig
        app = launch(Dispatchers.Main) {
          initApp(config)
        }
      }
    }
  }
}
m

Matteo Mirk

10/04/2019, 1:58 PM
If you don’t mind using a Java library, OWNER offers a hot reload functionality for properties, plus lots more: http://owner.aeonbits.org/docs/reload/
a

Alowaniak

10/04/2019, 1:58 PM
Also there's
WatchService
to detect changes
1
m

Matteo Mirk

10/04/2019, 2:01 PM
otherwise try looking into these libs, maybe there’s some with hot reloading https://kotlin.libhunt.com/categories/5622-configuration
9 Views