Use stop() instead of PoisonPill
authorChristos KK Loverdos <loverdos@gmail.com>
Thu, 3 May 2012 09:21:54 +0000 (12:21 +0300)
committerChristos KK Loverdos <loverdos@gmail.com>
Thu, 3 May 2012 09:21:54 +0000 (12:21 +0300)
src/main/scala/gr/grnet/aquarium/actor/service/user/UserActor.scala
src/main/scala/gr/grnet/aquarium/actor/service/user/UserActorCache.scala
src/main/scala/gr/grnet/aquarium/service/RESTActorService.scala
src/main/scala/gr/grnet/aquarium/util/LazyLoggable.scala
src/test/scala/gr/grnet/aquarium/rest/actor/service/SprayPingServiceTest.scala

index 4b75c7b..865aa02 100644 (file)
@@ -47,7 +47,6 @@ import gr.grnet.aquarium.actor.message.service.router._
 import message.config.{ActorProviderConfigured, AquariumPropertiesLoaded}
 import gr.grnet.aquarium.event.im.IMEventModel
 import akka.config.Supervision.Temporary
-import akka.actor.PoisonPill
 import gr.grnet.aquarium.{AquariumException, Configurator}
 
 
@@ -67,7 +66,7 @@ class UserActor extends ReflectiveRoleableActor {
       UserActorCache.invalidate(this._userID)
     }
 
-    self ! PoisonPill
+    self.stop()
   }
 
   override protected def onThrowable(t: Throwable, message: AnyRef) = {
index 3bf0700..6cf1d05 100644 (file)
@@ -56,29 +56,28 @@ object UserActorCache extends Lifecycle {
       .removalListener(EvictionListener)
       .build()
 
-  private[this] object EvictionListener
-    extends RemovalListener[String, ActorRef] with Loggable {
+  private[this] object EvictionListener extends RemovalListener[String, ActorRef] with Loggable {
 
-    def onRemoval(p1: RemovalNotification[String, ActorRef]) {
-      val userId = p1.getKey
-      val userActor = p1.getValue
+    def onRemoval(rn: RemovalNotification[String, ActorRef]) {
+      val userID = rn.getKey
+      val userActor = rn.getValue
 
-      logger.debug("Parking UserActor for userId = %s".format(userId))
+      logger.debug("Parking UserActor for userID = %s".format(userID))
       UserActorSupervisor.supervisor.unlink(userActor)
       // Check this is received after any currently servicing business logic message.
       userActor.stop()
     }
   }
 
-  def start() {}
+  def start() = {}
 
   def stop() = {
     cache.invalidateAll
     cache.cleanUp
-  };
+  }
 
-  def put(userId: String, userActor: ActorRef): Unit =
-    cache.put(userId, userActor)
+  def put(userID: String, userActor: ActorRef): Unit =
+    cache.put(userID, userActor)
 
   def get(userID: String): Option[ActorRef] =
     cache.getIfPresent(userID) match {
index a8890c6..4e962b7 100644 (file)
@@ -71,8 +71,8 @@ class RESTActorService extends Lifecycle with Loggable {
   def stop(): Unit = {
     LogHelpers.logStopping(logger)
     val (ms0, ms1, _) = TimeHelpers.timed {
-      this._serverActor ! PoisonPill
-      this._clientActor ! PoisonPill
+      this._serverActor.stop()
+      this._clientActor.stop()
     }
     LogHelpers.logStopped(logger, ms0, ms1)
   }
index b5bb749..873a09b 100644 (file)
@@ -75,7 +75,7 @@ trait LazyLoggable {
     LogHelpers.logStopped(this.logger, ms0, ms1, fmt, args: _*)
   }
 
-  protected def logChainOfCauses(t: Throwable): Unit = {
-    logger.error("Oops!\n{}", chainOfCausesForLogging(t))
+  protected def logChainOfCauses(t: Throwable, caughtTraceIndex: Int = 2): Unit = {
+    logger.error("Oops!\n{}", chainOfCausesForLogging(t, caughtTraceIndex + 1))
   }
 }
index b1234eb..f9c8e8a 100644 (file)
@@ -43,7 +43,7 @@ import gr.grnet.aquarium.util.Loggable
 import org.junit.Assume._
 import gr.grnet.aquarium.LogicTestsAssumptions
 import cc.spray.can._
-import akka.actor.{Actor, PoisonPill}
+import akka.actor.Actor
 import org.slf4j.LoggerFactory
 import akka.config.{Config ⇒ AkkaConfig}
 
@@ -143,9 +143,9 @@ class SprayPingServiceTest extends Loggable {
           logger.error("Error: %s".format(other))
       }
 
-      server  ! PoisonPill
-      client  ! PoisonPill
-      service ! PoisonPill
+      server.stop()
+      client.stop()
+      service.stop()
     }
 
     Thread sleep 100