Refactor Aquarium to make it more configurable
[aquarium] / src / main / scala / gr / grnet / aquarium / service / SimpleLocalRoleableActorProviderService.scala
index 62ec9c2..6b1f6b8 100644 (file)
@@ -37,22 +37,25 @@ package gr.grnet.aquarium.service
 
 import com.ckkloverdos.props.Props
 import akka.actor.ActorRef
-import gr.grnet.aquarium.Configurable
+import gr.grnet.aquarium.{AquariumAwareSkeleton, Configurable}
 import java.util.concurrent.ConcurrentHashMap
 import gr.grnet.aquarium.util.Loggable
-import gr.grnet.aquarium.util.date.TimeHelpers
 import gr.grnet.aquarium.actor.message.config.{AquariumPropertiesLoaded, ActorProviderConfigured}
 import gr.grnet.aquarium.actor._
 
-
 /**
  * All actors are provided locally.
  *
  * @author Christos KK Loverdos <loverdos@gmail.com>.
  */
-class SimpleLocalRoleableActorProviderService extends RoleableActorProviderService with Configurable with Loggable {
+class SimpleLocalRoleableActorProviderService
+  extends RoleableActorProviderService
+     with AquariumAwareSkeleton
+     with Configurable
+     with Loggable {
+
   private[this] val actorCache = new ConcurrentHashMap[ActorRole, ActorRef]
-  private[this] var _props: Props = _
+  @volatile private[this] var _props: Props = _
 
   def propertyPrefix = None
 
@@ -60,7 +63,7 @@ class SimpleLocalRoleableActorProviderService extends RoleableActorProviderServi
     this._props = props
   }
 
-  private[this] def __doStart(): Unit = {
+  def start(): Unit = {
     // Start and configure actors
     import SimpleLocalRoleableActorProviderService.RolesToBeStarted
 
@@ -69,20 +72,15 @@ class SimpleLocalRoleableActorProviderService extends RoleableActorProviderServi
     }
   }
 
-  def start(): Unit = {
-    logStarting()
-    val (ms0, ms1, _) = TimeHelpers.timed {
-      __doStart()
-    }
-    logStarted(ms0, ms1)
-  }
-
   def stop(): Unit = {
-    logStopped(TimeHelpers.nowMillis(), TimeHelpers.nowMillis())
   }
 
   private[this] def _newActor(role: ActorRole): ActorRef = {
-    val actorRef = akka.actor.Actor.actorOf(role.actorType).start()
+    val actorFactory = (_class: Class[_ <: RoleableActor]) ⇒ {
+      aquarium.newInstance(_class, _class.getName)
+    }
+
+    val actorRef = akka.actor.Actor.actorOf(actorFactory(role.actorType)).start()
 
     val propsMsg = AquariumPropertiesLoaded(this._props)
     if(role.canHandleConfigurationMessage(propsMsg)) {