diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2015-01-29 03:42:27 +0100 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2015-01-29 03:42:27 +0100 |
commit | 75bd9503aebee628da394a935816991e7a790092 (patch) | |
tree | f4df3333826cec805fadc14894579f1bc1054279 /kamon-core/src/main/scala/kamon/ModuleSupervisor.scala | |
parent | 61089a75240f5cc21b056087f1d633dd31981c61 (diff) | |
parent | 9839db9d46312435822b6b5faffbbc445af80077 (diff) | |
download | Kamon-75bd9503aebee628da394a935816991e7a790092.tar.gz Kamon-75bd9503aebee628da394a935816991e7a790092.tar.bz2 Kamon-75bd9503aebee628da394a935816991e7a790092.zip |
Merge branch 'wip/improve-metric-recorders-infrastructure'
Conflicts:
kamon-system-metrics/src/main/scala/kamon/system/SystemMetricsCollector.scala
Diffstat (limited to 'kamon-core/src/main/scala/kamon/ModuleSupervisor.scala')
-rw-r--r-- | kamon-core/src/main/scala/kamon/ModuleSupervisor.scala | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/kamon-core/src/main/scala/kamon/ModuleSupervisor.scala b/kamon-core/src/main/scala/kamon/ModuleSupervisor.scala new file mode 100644 index 00000000..7e82f80a --- /dev/null +++ b/kamon-core/src/main/scala/kamon/ModuleSupervisor.scala @@ -0,0 +1,49 @@ +package kamon + +import _root_.akka.actor +import _root_.akka.actor._ +import kamon.ModuleSupervisor.CreateModule + +import scala.concurrent.{ Future, Promise } +import scala.util.Success + +object ModuleSupervisor extends ExtensionId[ModuleSupervisorExtension] with ExtensionIdProvider { + + def lookup(): ExtensionId[_ <: actor.Extension] = ModuleSupervisor + def createExtension(system: ExtendedActorSystem): ModuleSupervisorExtension = new ModuleSupervisorExtensionImpl(system) + + case class CreateModule(name: String, props: Props, childPromise: Promise[ActorRef]) +} + +trait ModuleSupervisorExtension extends actor.Extension { + def createModule(name: String, props: Props): Future[ActorRef] +} + +class ModuleSupervisorExtensionImpl(system: ExtendedActorSystem) extends ModuleSupervisorExtension { + import system.dispatcher + private val supervisor = system.actorOf(Props[ModuleSupervisor], "kamon") + + def createModule(name: String, props: Props): Future[ActorRef] = Future {} flatMap { _: Unit ⇒ + val modulePromise = Promise[ActorRef]() + supervisor ! CreateModule(name, props, modulePromise) + modulePromise.future + } +} + +class ModuleSupervisor extends Actor with ActorLogging { + + def receive = { + case CreateModule(name, props, childPromise) ⇒ createChildModule(name, props, childPromise) + } + + def createChildModule(name: String, props: Props, childPromise: Promise[ActorRef]): Unit = { + + context.child(name).map { alreadyAvailableModule ⇒ + log.warning("Received a request to create module [{}] but the module is already available, returning the existent one.") + childPromise.complete(Success(alreadyAvailableModule)) + + } getOrElse { + childPromise.complete(Success(context.actorOf(props, name))) + } + } +} |