Reputation: 999
In akka, it's easy to read the global config via system.settings.config if in an actor.
However, if I have a plain singleton object which needs to read the config from the actorSystem, how should I do?
Assuming I don't want do use configFactory to do the same config file parse/fallback again.
Thanks
Leon
Upvotes: 2
Views: 989
Reputation: 11479
As cmbaxter said, if you have a reference to the actor system, use that, if you don't, well, maybe you could change your code so that you would have a reference to it. If that is impossible, then you could read the config using configFactory and put somewhere your singleton has access and also use that configuration as a parameter to the actor system when you create that instead of letting it read the config from disk.
object MyConfig {
private val myConfig = ??? // however you want to load your config
private val regularConfig = ConfigFactory.load();
// now you can access it from anywhere you want
val config = myConfig.withFallback(regularConfig);
}
Somewhere else:
val system = ActorSystem("my-system", MyConfig.config)
Upvotes: 1