aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/main/scala/kamon/metric/RecorderRegistry.scala
blob: 99974032f2a4152b5870e52c535f8b6a5a15c5f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package kamon
package metric

import com.typesafe.config.Config
import kamon.metric.instrument.InstrumentFactory

import scala.collection.concurrent.TrieMap


trait RecorderRegistry {
  def getRecorder(entity: Entity): EntityRecorder
  def getRecorder(name: String, category: String, tags: Map[String, String]): EntityRecorder

  def removeRecorder(entity: Entity): Boolean
  def removeRecorder(name: String, category: String, tags: Map[String, String]): Boolean
}

class RecorderRegistryImpl(config: Config) extends RecorderRegistry {
  private val instrumentFactory = InstrumentFactory(config.getConfig("kamon.metric.instrument-factory"))
  private val entities = TrieMap.empty[Entity, EntityRecorder with EntitySnapshotProducer]

  override def getRecorder(entity: Entity): EntityRecorder = {
    entities.atomicGetOrElseUpdate(entity, new DefaultEntityRecorder(entity, instrumentFactory))
  }

  override def getRecorder(name: String, category: String, tags: Map[String, String]): EntityRecorder = ???

  override def removeRecorder(entity: Entity): Boolean = ???

  override def removeRecorder(name: String, category: String, tags: Map[String, String]): Boolean = ???

  private[kamon] def snapshot(): Seq[EntitySnapshot] = {
    entities.values.map(_.snapshot()).toSeq
  }
}