diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2018-08-30 10:40:53 +0200 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2018-08-30 10:40:53 +0200 |
commit | e4abea098ef4d6e71a805812bfa95c14bd9002b5 (patch) | |
tree | f5fcb8222e293f420a9e7c06953805a7428d0f0e /kamon-core/src/main/scala/kamon/Configuration.scala | |
parent | 794fbf02664ac8c31072d8b955d897901f1f22e0 (diff) | |
download | Kamon-e4abea098ef4d6e71a805812bfa95c14bd9002b5.tar.gz Kamon-e4abea098ef4d6e71a805812bfa95c14bd9002b5.tar.bz2 Kamon-e4abea098ef4d6e71a805812bfa95c14bd9002b5.zip |
working on context tags and http propagation improvements
Diffstat (limited to 'kamon-core/src/main/scala/kamon/Configuration.scala')
-rw-r--r-- | kamon-core/src/main/scala/kamon/Configuration.scala | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/kamon-core/src/main/scala/kamon/Configuration.scala b/kamon-core/src/main/scala/kamon/Configuration.scala new file mode 100644 index 00000000..bd286792 --- /dev/null +++ b/kamon-core/src/main/scala/kamon/Configuration.scala @@ -0,0 +1,57 @@ +package kamon + +import scala.util.Try +import com.typesafe.config.{Config, ConfigFactory} +import org.slf4j.LoggerFactory + +trait Configuration { self: ClassLoading => + private val logger = LoggerFactory.getLogger(classOf[Configuration]) + private var _currentConfig: Config = ConfigFactory.load(self.classLoader()) + private var _onReconfigureHooks = Seq.empty[Configuration.OnReconfigureHook] + + + /** + * Retrieve Kamon's current configuration. + */ + def config(): Config = + _currentConfig + + /** + * Supply a new Config instance to rule Kamon's world. + */ + def reconfigure(newConfig: Config): Unit = synchronized { + _currentConfig = newConfig + _onReconfigureHooks.foreach(hook => { + Try(hook.onReconfigure(newConfig)).failed.foreach(error => + logger.error("Exception occurred while trying to run a OnReconfigureHook", error) + ) + }) + } + + /** + * Register a reconfigure hook that will be run when the a call to Kamon.reconfigure(config) is performed. All + * registered hooks will run sequentially in the same Thread that calls Kamon.reconfigure(config). + */ + def onReconfigure(hook: Configuration.OnReconfigureHook): Unit = synchronized { + _onReconfigureHooks = hook +: _onReconfigureHooks + } + + /** + * Register a reconfigure hook that will be run when the a call to Kamon.reconfigure(config) is performed. All + * registered hooks will run sequentially in the same Thread that calls Kamon.reconfigure(config). + */ + def onReconfigure(hook: (Config) => Unit): Unit = { + onReconfigure(new Configuration.OnReconfigureHook { + override def onReconfigure(newConfig: Config): Unit = hook.apply(newConfig) + }) + } + +} + +object Configuration { + + trait OnReconfigureHook { + def onReconfigure(newConfig: Config): Unit + } + +} |