WIP: Remodeling events
[aquarium] / src / main / scala / gr / grnet / aquarium / Configurator.scala
index fe2eca1..8811a9f 100644 (file)
 
 package gr.grnet.aquarium
 
-import actor.ActorProvider
-import com.ckkloverdos.props.Props
-import com.ckkloverdos.convert.Converters.{DefaultConverters => TheDefaultConverters}
-import processor.actor.{UserEventProcessorService, ResourceEventProcessorService}
-import store._
-import util.{Lifecycle, Loggable}
+import events.im.IMEventModel
 import java.io.File
+
 import com.ckkloverdos.maybe._
+import com.ckkloverdos.props.Props
+import com.ckkloverdos.convert.Converters.{DefaultConverters => TheDefaultConverters}
+
+import gr.grnet.aquarium.service._
+import gr.grnet.aquarium.util.{Lifecycle, Loggable}
+import gr.grnet.aquarium.store._
 
 /**
  * The master configurator. Responsible to load all of application configuration and provide the relevant services.
@@ -79,9 +81,9 @@ class Configurator(val props: Props) extends Loggable {
 
   }
 
-  private[this] lazy val _actorProvider: ActorProvider = {
-    val instance = newInstance[ActorProvider](props.getEx(Keys.actor_provider_class))
-    logger.info("Loaded ActorProvider: %s".format(instance.getClass))
+  private[this] lazy val _actorProvider: ActorProviderService = {
+    val instance = newInstance[ActorProviderService](props.getEx(Keys.actor_provider_class))
+    logger.info("Loaded ActorProviderService: %s".format(instance.getClass))
     instance
   }
 
@@ -123,10 +125,10 @@ class Configurator(val props: Props) extends Loggable {
     }
   }
 
-  private[this] lazy val _userEventStoreM: Maybe[UserEventStore] = {
+  private[this] lazy val _imEventStoreM: Maybe[IMEventStore] = {
     props.get(Keys.user_event_store_class) map { className ⇒
-      val instance = newInstance[UserEventStore](className)
-      logger.info("Overriding UserEventStore provisioning. Implementation given by: %s".format(instance.getClass))
+      val instance = newInstance[IMEventStore](className)
+      logger.info("Overriding IMEventStore provisioning. Implementation given by: %s".format(instance.getClass))
       instance
     }
   }
@@ -190,9 +192,11 @@ class Configurator(val props: Props) extends Loggable {
     }
   }
 
-  private[this] lazy val _resEventProc: ResourceEventProcessorService = new ResourceEventProcessorService
+  private[this] lazy val _resEventProc = new ResourceEventProcessorService
 
-  private[this] lazy val _imEventProc: UserEventProcessorService = new UserEventProcessorService
+  private[this] lazy val _imEventProc = new IMEventProcessorService
+
+  private[this] lazy val _lifecycleServices = List(AkkaService, _restService, _actorProvider, _resEventProc, _imEventProc)
 
   def get(key: String, default: String = ""): String = props.getOr(key, default)
 
@@ -225,18 +229,11 @@ class Configurator(val props: Props) extends Loggable {
   }
 
   def startServices(): Unit = {
-    _restService.start()
-    _actorProvider.start()
-    _resEventProc.start()
-    _imEventProc.start()
+    _lifecycleServices.foreach(_.start())
   }
 
   def stopServices(): Unit = {
-    _imEventProc.stop()
-    _resEventProc.stop()
-    _restService.stop()
-    _actorProvider.stop()
-
+    _lifecycleServices.reverse.foreach(_.stop())
 //    akka.actor.Actor.registry.shutdownAll()
   }
 
@@ -268,10 +265,10 @@ class Configurator(val props: Props) extends Loggable {
     }
   }
 
-  def userEventStore = {
-    _userEventStoreM match {
+  def imEventStore = {
+    _imEventStoreM match {
       case Just(es) ⇒ es
-      case _        ⇒ storeProvider.userEventStore
+      case _        ⇒ storeProvider.imEventStore
     }
   }
 
@@ -291,12 +288,6 @@ class Configurator(val props: Props) extends Loggable {
     new Configurator(newProps)
   }
 
-  // FIXME: This is instead of props.getInt which currently contains a bug.
-  // FIXME: Fix the original bug and delete this method
-  def getInt(name: String): Maybe[Int] = {
-    props.get(name).map(_.toInt)
-  }
-
   def eventsStoreFolder = _eventsStoreFolder
 
   def adminCookie: MaybeOption[String] = props.get(Configurator.Keys.admin_cookie) match {
@@ -360,7 +351,7 @@ object Configurator {
     final val version = "version"
 
     /**
-     * The fully qualified name of the class that implements the `ActorProvider`.
+     * The fully qualified name of the class that implements the `ActorProviderService`.
      * Will be instantiated reflectively and should have a public default constructor.
      */
     final val actor_provider_class = "actor.provider.class"
@@ -545,8 +536,8 @@ object Configurator {
     final val events_store_folder = "events.store.folder"
 
     /**
-     * If set to `true`, then an IM event that cannot be parsed to [[gr.grnet.aquarium.logic.events.UserEvent]] is
-     * saved to the [[gr.grnet.aquarium.store.UserEventStore]].
+     * If set to `true`, then an IM event that cannot be parsed to [[gr.grnet.aquarium.events.im.IMEventModel]] is
+     * saved to the [[gr.grnet.aquarium.store.IMEventStore]].
      */
     final val save_unparsed_event_im = "save.unparsed.event.im"
 
@@ -556,4 +547,9 @@ object Configurator {
      */
     final val admin_cookie = "admin.cookie"
   }
+
+  object HTTP {
+    final val RESTAdminHeaderName = "X-Aquarium-Admin-Cookie"
+    final val RESTAdminHeaderNameLowerCase = RESTAdminHeaderName.toLowerCase
+  }
 }