diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2017-06-14 15:27:01 +0200 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2017-06-14 15:28:56 +0200 |
commit | c987afd5aeacd8dd639637b391d6a8004a8a44a3 (patch) | |
tree | 1e0178b8de5b8f1927f6e3562dc840434c11a0f3 /kamon-core | |
parent | 856993f1adbab9a413e2c66b468699257557903f (diff) | |
download | Kamon-c987afd5aeacd8dd639637b391d6a8004a8a44a3.tar.gz Kamon-c987afd5aeacd8dd639637b391d6a8004a8a44a3.tar.bz2 Kamon-c987afd5aeacd8dd639637b391d6a8004a8a44a3.zip |
add onReconfigureHooks to Kamon
Diffstat (limited to 'kamon-core')
-rw-r--r-- | kamon-core/src/main/scala/kamon/Kamon.scala | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/kamon-core/src/main/scala/kamon/Kamon.scala b/kamon-core/src/main/scala/kamon/Kamon.scala index d7864de5..81cd3f56 100644 --- a/kamon-core/src/main/scala/kamon/Kamon.scala +++ b/kamon-core/src/main/scala/kamon/Kamon.scala @@ -26,9 +26,13 @@ import scala.concurrent.Future import java.time.Duration import io.opentracing.ActiveSpan.Continuation +import org.slf4j.LoggerFactory + +import scala.util.Try object Kamon extends MetricLookup with ReporterRegistry with io.opentracing.Tracer { + private val logger = LoggerFactory.getLogger("kamon.Kamon") @volatile private var _config = ConfigFactory.load() @volatile private var _environment = Environment.fromConfig(_config) @volatile private var _filters = Filters.fromConfig(_config) @@ -36,6 +40,7 @@ object Kamon extends MetricLookup with ReporterRegistry with io.opentracing.Trac private val _metrics = new MetricRegistry(_config) private val _reporters = new ReporterRegistryImpl(_metrics, _config) private val _tracer = new Tracer(Kamon, _reporters, _config) + private var _onReconfigureHooks = Seq.empty[OnReconfigureHook] def environment: Environment = _environment @@ -49,6 +54,12 @@ object Kamon extends MetricLookup with ReporterRegistry with io.opentracing.Trac _filters = Filters.fromConfig(config) _metrics.reconfigure(config) _reporters.reconfigure(config) + + _onReconfigureHooks.foreach(hook => { + Try(hook.onReconfigure(config)).failed.foreach(error => + logger.error("Exception occurred while trying to run a OnReconfigureHook", error) + ) + }) } @@ -157,4 +168,16 @@ object Kamon extends MetricLookup with ReporterRegistry with io.opentracing.Trac def filter(filterName: String, pattern: String): Boolean = _filters.accept(filterName, pattern) + + /** + * 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: OnReconfigureHook): Unit = synchronized { + _onReconfigureHooks = hook +: _onReconfigureHooks + } +} + +trait OnReconfigureHook { + def onReconfigure(newConfig: Config): Unit } |