WIP: ResourceEvent-related refactorings
[aquarium] / src / main / scala / gr / grnet / aquarium / actor / service / router / RouterActor.scala
index 9fe11cf..7677b23 100644 (file)
@@ -39,10 +39,13 @@ package router
 
 import gr.grnet.aquarium.util.shortClassNameOf
 import gr.grnet.aquarium.service.RoleableActorProviderService
-import message.service.router._
 import akka.actor.ActorRef
 import user.{UserActorCache, UserActorSupervisor}
 import message.config.{AquariumPropertiesLoaded, ActorProviderConfigured}
+import gr.grnet.aquarium.actor.message.event.{ProcessResourceEvent, ProcessIMEvent}
+import gr.grnet.aquarium.actor.message.admin.PingAllRequest
+import gr.grnet.aquarium.actor.message.{UserActorRequestMessage, GetUserStateRequest, GetUserBalanceRequest}
+import gr.grnet.aquarium.{AquariumException, AquariumInternalError}
 
 /**
  * Business logic router. Incoming messages are routed to appropriate destinations. Replies are routed back
@@ -68,19 +71,46 @@ class RouterActor extends ReflectiveRoleableActor {
     UserActorCache.get(userID) match {
       case Some(userActorRef) ⇒
         userActorRef
+
       case None ⇒
         _launchUserActor(userID)
     }
   }
 
-  private[this] def _forwardToUserActor(userID: String, m: RouterMessage): Unit = {
-    try {
-      _findOrCreateUserActor(userID) forward m
+  private[this] def _forwardToUserActor(userID: String, m: UserActorRequestMessage): Unit = {
+    _findOrCreateUserActor(userID) forward m
+  }
+
 
-    } catch { case t: Throwable ⇒
-      logger.error("While forwarding to user actor for userID = %s".format(userID), t)
-      // FIXME: We have a message that never gets to the user actor.
-      // FIXME: We should probably shut the user actor down.
+  /**
+   * Handles an exception that occurred while servicing a message.
+   *
+   * @param t
+   * The exception.
+   * @param servicingMessage
+   * The message that was being served while the exception happened.
+   * Note that the message can be `null`, in which case the exception
+   * is an NPE.
+   */
+  override protected def onThrowable(t: Throwable, servicingMessage: AnyRef) = {
+    logChainOfCauses(t)
+
+    def logIgnore(e: Throwable) = {
+      logger.error("Ignoring %s".format(shortClassNameOf(e)), e)
+    }
+
+    t match {
+      case e: Error ⇒
+        throw e
+
+      case e: AquariumInternalError ⇒
+        logIgnore(e)
+
+      case e: AquariumException ⇒
+        logIgnore(e)
+
+      case e: Throwable ⇒
+        logIgnore(e)
     }
   }
 
@@ -97,11 +127,11 @@ class RouterActor extends ReflectiveRoleableActor {
      _forwardToUserActor(m.imEvent.userID, m)
   }
 
-  def onRequestUserBalance(m: RequestUserBalance): Unit = {
+  def onGetUserBalanceRequest(m: GetUserBalanceRequest): Unit = {
     _forwardToUserActor(m.userID, m)
   }
 
-  def onUserRequestGetState(m: UserRequestGetState): Unit = {
+  def onGetUserStateRequest(m: GetUserStateRequest): Unit = {
     _forwardToUserActor(m.userID, m)
   }
 
@@ -109,8 +139,7 @@ class RouterActor extends ReflectiveRoleableActor {
     _forwardToUserActor(m.rcEvent.userID, m)
   }
 
-  def onAdminRequestPingAll(m: AdminRequestPingAll): Unit = {
-
+  def onPingAllRequest(m: PingAllRequest): Unit = {
   }
 
   override def postStop = {