com.codemettle.akkasnmp4j.util.SettingsCompanion.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of akka-snmp4j_2.11 Show documentation
Show all versions of akka-snmp4j_2.11 Show documentation
Library to aid usage of SNMP4J in Scala + Akka
The newest version!
package com.codemettle.akkasnmp4j.util
import com.typesafe.config.Config
import akka.actor.{ActorRefFactory, ActorSystem}
/**
* Created by steven on 9/19/2017.
*
* I've looked at spray and akka source before, so this isn't clean room or anything
*/
abstract class SettingsCompanion[T](path: String) {
private var cache = Map.empty[ActorSystem, T]
private def materialize(system: ActorSystem): T =
cache.getOrElse(system, {
val t = fromSubConfig(system.settings.config.getConfig(path))
cache += (system -> t)
t
})
def apply(arf: ActorRefFactory): T = materialize(actorSystem(arf))
def fromSubConfig(c: Config): T
}