From a1adfd42e874f78a48c4c8b3e658d696f2242d1c Mon Sep 17 00:00:00 2001 From: jboner Date: Fri, 20 Nov 2009 08:29:31 +0100 Subject: [PATCH] cleaned up supervisor and actor api, breaking changes --- .../akka_samples_lift_war_exploded.xml | 105 ---- ...om_google_protobuf_protobuf_java_2_1_0.xml | 13 - .../Maven__net_liftweb_lift_actor_1_1_M6.xml | 13 - .../Maven__net_liftweb_lift_webkit_1_1_M6.xml | 13 - .../Maven__org_mortbay_jetty_jetty_6_1_22.xml | 13 - ...n__org_mortbay_jetty_jetty_util_6_1_22.xml | 13 - ...mortbay_jetty_servlet_api_2_5_20081211.xml | 13 - .idea/workspace.xml | 223 +++++--- .../src/main/scala/actor/ActiveObject.scala | 10 +- akka-actors/src/main/scala/actor/Actor.scala | 29 +- .../src/main/scala/actor/Scheduler.scala | 6 +- .../src/main/scala/actor/Supervisor.scala | 87 ++-- .../ActiveObjectGuiceConfigurator.scala | 2 +- .../EventBasedSingleThreadActorTest.scala | 12 +- ...EventBasedSingleThreadDispatcherTest.scala | 6 +- .../scala/EventBasedThreadPoolActorTest.scala | 12 +- .../EventBasedThreadPoolDispatcherTest.scala | 6 +- .../src/test/scala/InMemoryActorTest.scala | 4 +- .../src/test/scala/RemoteActorTest.scala | 12 +- .../src/test/scala/RemoteSupervisorTest.scala | 479 +++++++++--------- .../src/test/scala/SchedulerTest.scala | 2 +- .../src/test/scala/SupervisorTest.scala | 53 +- .../src/test/scala/ThreadBasedActorTest.scala | 12 +- .../scala/ThreadBasedDispatcherTest.scala | 6 +- akka-amqp/src/main/scala/AMQP.scala | 10 +- akka-amqp/src/main/scala/ExampleSession.scala | 6 +- .../akka/api/InMemNestedStateTest.java | 8 +- .../akka/api/InMemoryStateTest.java | 20 +- .../scala/CassandraPersistentActorSpec.scala | 4 +- .../test/scala/MongoPersistentActorSpec.scala | 4 +- .../src/main/scala/akka/SimpleService.scala | 4 +- .../main/scala/bootstrap/liftweb/Boot.scala | 33 +- .../src/main/scala/SimpleService.scala | 38 +- .../src/main/scala/SimpleService.scala | 104 ++-- akka-security/src/main/scala/Security.scala | 18 +- .../actor/ActiveObject.scala.html | 4 +- .../actor/Actor.scala.html | 4 +- .../actor/Scheduler.scala.html | 4 +- .../actor/Supervisor.scala.html | 2 +- .../scalablesolutions/akka/actor/Actor.html | 2 +- .../akka/actor/ScheduleActor.html | 2 +- .../akka/actor/Scheduler$object.html | 2 +- .../akka/actor/Supervisor.html | 2 +- docs/scaladocs-akka-amqp/AMQP.scala.html | 8 +- .../ExampleSession.scala.html | 6 +- .../akka/amqp/AMQP$object.html | 2 +- .../Security.scala.html | 4 +- .../akka/security/AuthenticationActor.html | 2 +- .../security/BasicAuthenticationActor.html | 2 +- .../security/DigestAuthenticationActor.html | 2 +- .../security/SpnegoAuthenticationActor.html | 2 +- 51 files changed, 637 insertions(+), 806 deletions(-) delete mode 100644 .idea/libraries/Maven__com_google_protobuf_protobuf_java_2_1_0.xml delete mode 100644 .idea/libraries/Maven__net_liftweb_lift_actor_1_1_M6.xml delete mode 100644 .idea/libraries/Maven__net_liftweb_lift_webkit_1_1_M6.xml delete mode 100644 .idea/libraries/Maven__org_mortbay_jetty_jetty_6_1_22.xml delete mode 100644 .idea/libraries/Maven__org_mortbay_jetty_jetty_util_6_1_22.xml delete mode 100644 .idea/libraries/Maven__org_mortbay_jetty_servlet_api_2_5_20081211.xml diff --git a/.idea/artifacts/akka_samples_lift_war_exploded.xml b/.idea/artifacts/akka_samples_lift_war_exploded.xml index 0cff3865c5..9f98b24e5b 100644 --- a/.idea/artifacts/akka_samples_lift_war_exploded.xml +++ b/.idea/artifacts/akka_samples_lift_war_exploded.xml @@ -7,111 +7,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.idea/libraries/Maven__com_google_protobuf_protobuf_java_2_1_0.xml b/.idea/libraries/Maven__com_google_protobuf_protobuf_java_2_1_0.xml deleted file mode 100644 index efe007a64e..0000000000 --- a/.idea/libraries/Maven__com_google_protobuf_protobuf_java_2_1_0.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__net_liftweb_lift_actor_1_1_M6.xml b/.idea/libraries/Maven__net_liftweb_lift_actor_1_1_M6.xml deleted file mode 100644 index 82142fbc1f..0000000000 --- a/.idea/libraries/Maven__net_liftweb_lift_actor_1_1_M6.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__net_liftweb_lift_webkit_1_1_M6.xml b/.idea/libraries/Maven__net_liftweb_lift_webkit_1_1_M6.xml deleted file mode 100644 index a77e2cfc9b..0000000000 --- a/.idea/libraries/Maven__net_liftweb_lift_webkit_1_1_M6.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_mortbay_jetty_jetty_6_1_22.xml b/.idea/libraries/Maven__org_mortbay_jetty_jetty_6_1_22.xml deleted file mode 100644 index 91ee03e168..0000000000 --- a/.idea/libraries/Maven__org_mortbay_jetty_jetty_6_1_22.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_mortbay_jetty_jetty_util_6_1_22.xml b/.idea/libraries/Maven__org_mortbay_jetty_jetty_util_6_1_22.xml deleted file mode 100644 index bf562dadbf..0000000000 --- a/.idea/libraries/Maven__org_mortbay_jetty_jetty_util_6_1_22.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_mortbay_jetty_servlet_api_2_5_20081211.xml b/.idea/libraries/Maven__org_mortbay_jetty_servlet_api_2_5_20081211.xml deleted file mode 100644 index 4863239c0e..0000000000 --- a/.idea/libraries/Maven__org_mortbay_jetty_servlet_api_2_5_20081211.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 7637ebbe50..0dc072b32f 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -62,91 +112,91 @@ - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + @@ -162,19 +212,22 @@ @@ -372,7 +425,8 @@ - + + @@ -384,7 +438,6 @@ - @@ -419,114 +472,116 @@ - - - - - - - - - - - - - - - + - + - + - + - + - + - - + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + diff --git a/akka-actors/src/main/scala/actor/ActiveObject.scala b/akka-actors/src/main/scala/actor/ActiveObject.scala index 2e7ff1249d..dd14cda0a5 100644 --- a/akka-actors/src/main/scala/actor/ActiveObject.scala +++ b/akka-actors/src/main/scala/actor/ActiveObject.scala @@ -127,11 +127,9 @@ object ActiveObject { private[akka] def supervise(restartStrategy: RestartStrategy, components: List[Supervise]): Supervisor = { - object factory extends SupervisorFactory { - override def getSupervisorConfig = SupervisorConfig(restartStrategy, components) - } - val supervisor = factory.newSupervisor - supervisor ! StartSupervisor + val factory = SupervisorFactory(SupervisorConfig(restartStrategy, components)) + val supervisor = factory.newInstance + supervisor.start supervisor } } @@ -325,7 +323,7 @@ private[akka] class Dispatcher(val callbacks: Option[RestartCallbacks]) extends //if (initTxState.isDefined) initTxState.get.setAccessible(true) } - override def receive: PartialFunction[Any, Unit] = { + def receive: PartialFunction[Any, Unit] = { case Invocation(joinPoint, isOneWay, _) => if (Actor.SERIALIZE_MESSAGES) serializeArguments(joinPoint) if (isOneWay) joinPoint.proceed diff --git a/akka-actors/src/main/scala/actor/Actor.scala b/akka-actors/src/main/scala/actor/Actor.scala index 358e27bd54..5aba208a28 100644 --- a/akka-actors/src/main/scala/actor/Actor.scala +++ b/akka-actors/src/main/scala/actor/Actor.scala @@ -70,7 +70,14 @@ object Actor { /** * Actor base trait that should be extended by or mixed to create an Actor with the semantics of the 'Actor Model': * http://en.wikipedia.org/wiki/Actor_model - * + *

+ * An actor has a well-defined (non-cyclic) life-cycle. + *

+ * => NEW (newly created actor) - can't receive messages (yet)
+ *     => STARTED (when 'start' is invoked) - can receive messages
+ *         => SHUT DOWN (when 'exit' is invoked) - can't do anything
+ * 
+ * * @author Jonas Bonér */ trait Actor extends Logging with TransactionManagement { @@ -81,6 +88,7 @@ trait Actor extends Logging with TransactionManagement { // private fields @volatile private var _isRunning: Boolean = false + @volatile private var _isShutDown: Boolean = false private var _hotswap: Option[PartialFunction[Any, Unit]] = None private var _config: Option[AnyRef] = None private val _remoteFlagLock = new ReadWriteLock @@ -144,7 +152,6 @@ trait Actor extends Logging with TransactionManagement { protected[akka] var messageDispatcher: MessageDispatcher = { val dispatcher = Dispatchers.newEventBasedThreadPoolDispatcher(getClass.getName) _mailbox = dispatcher.messageQueue - dispatcher.registerHandler(this, new ActorMessageInvoker(this)) dispatcher } @@ -201,7 +208,7 @@ trait Actor extends Logging with TransactionManagement { *

* Example code: *

-   *   def receive: PartialFunction[Any, Unit] = {
+   *   def receive = {
    *     case Ping =>
    *       println("got a ping")
    *       reply("pong")
@@ -264,7 +271,9 @@ trait Actor extends Logging with TransactionManagement {
    * Starts up the actor and its message queue.
    */
   def start = synchronized  {
+    if (_isShutDown) throw new IllegalStateException("Can't restart an actor that have been shut down with 'exit'")
     if (!_isRunning) {
+      dispatcher.registerHandler(this, new ActorMessageInvoker(this))
       messageDispatcher.start
       _isRunning = true
       //if (isTransactional) this !! TransactionalInit
@@ -273,14 +282,15 @@ trait Actor extends Logging with TransactionManagement {
   }
 
   /**
-   * Stops the actor and its message queue.
+   * Shuts down the actor its dispatcher and message queue.
    */
-  def stop = synchronized {
+  def exit = synchronized {
     if (_isRunning) {
-      dispatcher.unregisterHandler(this)
-      if (dispatcher.isInstanceOf[ThreadBasedDispatcher]) dispatcher.shutdown
+      messageDispatcher.unregisterHandler(this)
+      if (messageDispatcher.isInstanceOf[ThreadBasedDispatcher]) messageDispatcher.shutdown
       // FIXME: Need to do reference count to know if EventBasedThreadPoolDispatcher and EventBasedSingleThreadDispatcher can be shut down
       _isRunning = false
+      _isShutDown = true
       shutdown
     }
   }
@@ -356,7 +366,10 @@ trait Actor extends Logging with TransactionManagement {
     case Some(future) => future.completeWithResult(message)
   }
 
-  def dispatcher = messageDispatcher
+  /**
+   * Get the dispatcher for this actor.
+   */
+  def dispatcher = synchronized { messageDispatcher }
 
   /**
    * Sets the dispatcher for this actor. Needs to be invoked before the actor is started.
diff --git a/akka-actors/src/main/scala/actor/Scheduler.scala b/akka-actors/src/main/scala/actor/Scheduler.scala
index df4d41ff40..6266c17942 100644
--- a/akka-actors/src/main/scala/actor/Scheduler.scala
+++ b/akka-actors/src/main/scala/actor/Scheduler.scala
@@ -30,11 +30,11 @@ case class SchedulerException(msg: String, e: Throwable) extends RuntimeExceptio
 class ScheduleActor(val receiver: Actor, val future: ScheduledFuture[AnyRef]) extends Actor with Logging {
   lifeCycle = Some(LifeCycle(Permanent))
 
-  def receive: PartialFunction[Any, Unit] = {
+  def receive = {
     case UnSchedule =>
       Scheduler.stopSupervising(this)
       future.cancel(true)
-      stop
+      exit
   }
 }
 
@@ -69,7 +69,7 @@ object Scheduler extends Actor {
     service.shutdown
   }
 
-  def receive: PartialFunction[Any, Unit] = {
+  def receive = {
     case _ => {} // ignore all messages
   }
 }
diff --git a/akka-actors/src/main/scala/actor/Supervisor.scala b/akka-actors/src/main/scala/actor/Supervisor.scala
index 429677d6f0..d08150364e 100644
--- a/akka-actors/src/main/scala/actor/Supervisor.scala
+++ b/akka-actors/src/main/scala/actor/Supervisor.scala
@@ -8,12 +8,9 @@ import se.scalablesolutions.akka.config.ScalaConfig._
 import se.scalablesolutions.akka.config.{ConfiguratorRepository, Configurator}
 import se.scalablesolutions.akka.util.Helpers._
 import se.scalablesolutions.akka.util.Logging
-import se.scalablesolutions.akka.dispatch.Dispatchers
 
 import java.util.concurrent.ConcurrentHashMap
 
-import scala.collection.mutable.HashMap
-   
 /**
  * Messages that the supervisor responds to and returns.
  *
@@ -34,42 +31,32 @@ case class OneForOneStrategy(maxNrOfRetries: Int, withinTimeRange: Int) extends
  * 

* Example usage: *

- *  class MySupervisorFactory extends SupervisorFactory {
- *
- *    override protected def getSupervisorConfig: SupervisorConfig = {
- *      SupervisorConfig(
- *        RestartStrategy(OneForOne, 3, 10),
- *        Supervise(
- *          myFirstActor,
- *          LifeCycle(Permanent))
- *        ::
- *        Supervise(
- *          mySecondActor,
- *          LifeCycle(Permanent))
- *        :: Nil)
- *    }
- * }
- * 
- * - * Then create a concrete factory in which we mix in support for the specific implementation of the Service we want to use. - * - *
- * object factory extends MySupervisorFactory
+ *  val factory = SupervisorFactory(
+ *    SupervisorConfig(
+ *      RestartStrategy(OneForOne, 3, 10),
+ *      Supervise(
+ *        myFirstActor,
+ *        LifeCycle(Permanent)) ::
+ *      Supervise(
+ *        mySecondActor,
+ *        LifeCycle(Permanent)) ::
+ *      Nil))
  * 
* * Then create a new Supervisor tree with the concrete Services we have defined. * *
- * val supervisor = factory.newSupervisor
- * supervisor ! Start // start up all managed servers
+ * val supervisor = factory.newInstance
+ * supervisor.start // start up all managed servers
  * 
* * @author Jonas Bonér */ -abstract class SupervisorFactory extends Logging { - def newSupervisor: Supervisor = newSupervisorFor(getSupervisorConfig) +class SupervisorFactory(val config: SupervisorConfig) extends Logging { - def newSupervisorFor(config: SupervisorConfig): Supervisor = config match { + def newInstance: Supervisor = newInstanceFor(config) + + def newInstanceFor(config: SupervisorConfig): Supervisor = config match { case SupervisorConfig(restartStrategy, _) => val supervisor = create(restartStrategy) supervisor.start @@ -77,12 +64,6 @@ abstract class SupervisorFactory extends Logging { supervisor } - /** - * To be overridden by concrete factory. - * Should return the SupervisorConfig for the supervisor. - */ - protected def getSupervisorConfig: SupervisorConfig - protected def create(strategy: RestartStrategy): Supervisor = strategy match { case RestartStrategy(scheme, maxNrOfRetries, timeRange) => scheme match { @@ -92,18 +73,24 @@ abstract class SupervisorFactory extends Logging { } } +object SupervisorFactory { + def apply(config: SupervisorConfig) = new SupervisorFactory(config) +} + /** * NOTE: *

- * The supervisor class is only used for the configuration system when configuring supervisor hierarchies declaratively. - * Should not be used in development. Instead wire the actors together using 'link', 'spawnLink' etc. and set the 'trapExit' - * flag in the actors that should trap error signals and trigger restart. + * The supervisor class is only used for the configuration system when configuring supervisor + * hierarchies declaratively. Should not be used as part of the regular programming API. Instead + * wire the actors together using 'link', 'spawnLink' etc. and set the 'trapExit' flag in the + * actors that should trap error signals and trigger restart. *

* See the ScalaDoc for the SupervisorFactory for an example on how to declaratively wire up actors. * * @author Jonas Bonér */ -class Supervisor private[akka] (handler: FaultHandlingStrategy) extends Actor with Logging with Configurator { +sealed class Supervisor private[akka] (handler: FaultHandlingStrategy) + extends Actor with Logging with Configurator { trapExit = List(classOf[Throwable]) faultHandler = Some(handler) //dispatcher = Dispatchers.newThreadBasedDispatcher(this) @@ -116,23 +103,29 @@ class Supervisor private[akka] (handler: FaultHandlingStrategy) extends Actor wi def isDefined(clazz: Class[_]): Boolean = actors.containsKey(clazz.getName) - def startSupervisor = { + override def start = { ConfiguratorRepository.registerConfigurator(this) actors.values.toArray.toList.foreach(println) - start + super[Actor].start this ! StartSupervisor } - def stopSupervisor = this ! StopSupervisor + def stop = this !? StopSupervisor - protected def receive: PartialFunction[Any, Unit] = { + protected def receive = { case StartSupervisor => - _linkedActors.toArray.toList.asInstanceOf[List[Actor]].foreach { actor => actor.start; log.info("Starting actor: %s", actor) } + _linkedActors.toArray.toList.asInstanceOf[List[Actor]].foreach { actor => + actor.start + log.info("Starting actor: %s", actor) + } case StopSupervisor => - _linkedActors.toArray.toList.asInstanceOf[List[Actor]].foreach { actor => actor.stop; log.info("Stopping actor: %s", actor) } + _linkedActors.toArray.toList.asInstanceOf[List[Actor]].foreach { actor => + actor.exit + log.info("Shutting actor down: %s", actor) + } log.info("Stopping supervisor: %s", this) - stop + exit } def configure(config: SupervisorConfig, factory: SupervisorFactory) = config match { @@ -145,7 +138,7 @@ class Supervisor private[akka] (handler: FaultHandlingStrategy) extends Actor wi startLink(actor) case SupervisorConfig(_, _) => // recursive configuration - val supervisor = factory.newSupervisorFor(server.asInstanceOf[SupervisorConfig]) + val supervisor = factory.newInstanceFor(server.asInstanceOf[SupervisorConfig]) supervisor ! StartSupervisor // FIXME what to do with recursively supervisors? }) diff --git a/akka-actors/src/main/scala/config/ActiveObjectGuiceConfigurator.scala b/akka-actors/src/main/scala/config/ActiveObjectGuiceConfigurator.scala index 2a0d454d22..04f90c331d 100644 --- a/akka-actors/src/main/scala/config/ActiveObjectGuiceConfigurator.scala +++ b/akka-actors/src/main/scala/config/ActiveObjectGuiceConfigurator.scala @@ -133,7 +133,7 @@ private[akka] class ActiveObjectGuiceConfigurator extends ActiveObjectConfigurat supervisor = Some(ActiveObject.supervise(restartStrategy, supervised)) //camelContext.addComponent(AKKA_CAMEL_ROUTING_SCHEME, new ActiveObjectComponent(this)) //camelContext.start - supervisor.get.startSupervisor + supervisor.get.start ConfiguratorRepository.registerConfigurator(this) this } diff --git a/akka-actors/src/test/scala/EventBasedSingleThreadActorTest.scala b/akka-actors/src/test/scala/EventBasedSingleThreadActorTest.scala index d8a3917293..fd9e20e95c 100644 --- a/akka-actors/src/test/scala/EventBasedSingleThreadActorTest.scala +++ b/akka-actors/src/test/scala/EventBasedSingleThreadActorTest.scala @@ -13,7 +13,7 @@ class EventBasedSingleThreadActorTest extends JUnitSuite { class TestActor extends Actor { dispatcher = Dispatchers.newEventBasedSingleThreadDispatcher(uuid) - def receive: PartialFunction[Any, Unit] = { + def receive = { case "Hello" => reply("World") case "Failure" => @@ -25,7 +25,7 @@ class EventBasedSingleThreadActorTest extends JUnitSuite { implicit val timeout = 5000L var oneWay = "nada" val actor = new Actor { - def receive: PartialFunction[Any, Unit] = { + def receive = { case "OneWay" => oneWay = "received" } } @@ -33,7 +33,7 @@ class EventBasedSingleThreadActorTest extends JUnitSuite { val result = actor ! "OneWay" Thread.sleep(100) assert("received" === oneWay) - actor.stop + actor.exit } @Test def shouldSendReplySync = { @@ -42,7 +42,7 @@ class EventBasedSingleThreadActorTest extends JUnitSuite { actor.start val result: String = actor !? "Hello" assert("World" === result) - actor.stop + actor.exit } @Test def shouldSendReplyAsync = { @@ -51,7 +51,7 @@ class EventBasedSingleThreadActorTest extends JUnitSuite { actor.start val result = actor !! "Hello" assert("World" === result.get.asInstanceOf[String]) - actor.stop + actor.exit } @Test def shouldSendReceiveException = { @@ -65,6 +65,6 @@ class EventBasedSingleThreadActorTest extends JUnitSuite { case e => assert("expected" === e.getMessage()) } - actor.stop + actor.exit } } diff --git a/akka-actors/src/test/scala/EventBasedSingleThreadDispatcherTest.scala b/akka-actors/src/test/scala/EventBasedSingleThreadDispatcherTest.scala index af62f475e0..2997c3b4f5 100644 --- a/akka-actors/src/test/scala/EventBasedSingleThreadDispatcherTest.scala +++ b/akka-actors/src/test/scala/EventBasedSingleThreadDispatcherTest.scala @@ -50,9 +50,9 @@ class EventBasedSingleThreadDispatcherTest extends JUnitSuite { internalTestMessagesDispatchedToHandlersAreExecutedInFIFOOrder } - val key1 = new Actor { def receive: PartialFunction[Any, Unit] = { case _ => {}} } - val key2 = new Actor { def receive: PartialFunction[Any, Unit] = { case _ => {}} } - val key3 = new Actor { def receive: PartialFunction[Any, Unit] = { case _ => {}} } + val key1 = new Actor { def receive = { case _ => {}} } + val key2 = new Actor { def receive = { case _ => {}} } + val key3 = new Actor { def receive = { case _ => {}} } private def internalTestMessagesDispatchedToTheSameHandlerAreExecutedSequentially: Unit = { val guardLock = new ReentrantLock diff --git a/akka-actors/src/test/scala/EventBasedThreadPoolActorTest.scala b/akka-actors/src/test/scala/EventBasedThreadPoolActorTest.scala index 168a20ff9c..b6747a9119 100644 --- a/akka-actors/src/test/scala/EventBasedThreadPoolActorTest.scala +++ b/akka-actors/src/test/scala/EventBasedThreadPoolActorTest.scala @@ -9,7 +9,7 @@ class EventBasedThreadPoolActorTest extends JUnitSuite { private val unit = TimeUnit.MILLISECONDS class TestActor extends Actor { - def receive: PartialFunction[Any, Unit] = { + def receive = { case "Hello" => reply("World") case "Failure" => @@ -21,7 +21,7 @@ class EventBasedThreadPoolActorTest extends JUnitSuite { implicit val timeout = 5000L var oneWay = "nada" val actor = new Actor { - def receive: PartialFunction[Any, Unit] = { + def receive = { case "OneWay" => oneWay = "received" } } @@ -29,7 +29,7 @@ class EventBasedThreadPoolActorTest extends JUnitSuite { val result = actor ! "OneWay" Thread.sleep(100) assert("received" === oneWay) - actor.stop + actor.exit } @Test def shouldSendReplySync = { @@ -38,7 +38,7 @@ class EventBasedThreadPoolActorTest extends JUnitSuite { actor.start val result: String = actor !? "Hello" assert("World" === result) - actor.stop + actor.exit } @Test def shouldSendReplyAsync = { @@ -47,7 +47,7 @@ class EventBasedThreadPoolActorTest extends JUnitSuite { actor.start val result = actor !! "Hello" assert("World" === result.get.asInstanceOf[String]) - actor.stop + actor.exit } @Test def shouldSendReceiveException = { @@ -61,6 +61,6 @@ class EventBasedThreadPoolActorTest extends JUnitSuite { case e => assert("expected" === e.getMessage()) } - actor.stop + actor.exit } } diff --git a/akka-actors/src/test/scala/EventBasedThreadPoolDispatcherTest.scala b/akka-actors/src/test/scala/EventBasedThreadPoolDispatcherTest.scala index 7391c348d9..84d778a39d 100644 --- a/akka-actors/src/test/scala/EventBasedThreadPoolDispatcherTest.scala +++ b/akka-actors/src/test/scala/EventBasedThreadPoolDispatcherTest.scala @@ -13,9 +13,9 @@ import se.scalablesolutions.akka.actor.Actor class EventBasedThreadPoolDispatcherTest extends JUnitSuite { private var threadingIssueDetected: AtomicBoolean = null - val key1 = new Actor { def receive: PartialFunction[Any, Unit] = { case _ => {}} } - val key2 = new Actor { def receive: PartialFunction[Any, Unit] = { case _ => {}} } - val key3 = new Actor { def receive: PartialFunction[Any, Unit] = { case _ => {}} } + val key1 = new Actor { def receive = { case _ => {}} } + val key2 = new Actor { def receive = { case _ => {}} } + val key3 = new Actor { def receive = { case _ => {}} } @Before def setUp = { diff --git a/akka-actors/src/test/scala/InMemoryActorTest.scala b/akka-actors/src/test/scala/InMemoryActorTest.scala index 83c105d69f..cd06b80d0a 100644 --- a/akka-actors/src/test/scala/InMemoryActorTest.scala +++ b/akka-actors/src/test/scala/InMemoryActorTest.scala @@ -30,7 +30,7 @@ class InMemStatefulActor extends Actor { private lazy val vectorState = TransactionalState.newVector[String] private lazy val refState = TransactionalState.newRef[String] - def receive: PartialFunction[Any, Unit] = { + def receive = { case GetMapState(key) => reply(mapState.get(key).get) case GetVectorSize => @@ -79,7 +79,7 @@ class InMemStatefulActor extends Actor { @serializable class InMemFailerActor extends Actor { makeTransactionRequired - def receive: PartialFunction[Any, Unit] = { + def receive = { case "Failure" => throw new RuntimeException("expected") } diff --git a/akka-actors/src/test/scala/RemoteActorTest.scala b/akka-actors/src/test/scala/RemoteActorTest.scala index a187c3f16a..447ada87f6 100644 --- a/akka-actors/src/test/scala/RemoteActorTest.scala +++ b/akka-actors/src/test/scala/RemoteActorTest.scala @@ -11,14 +11,14 @@ object Global { var oneWay = "nada" } class RemoteActorSpecActorUnidirectional extends Actor { - def receive: PartialFunction[Any, Unit] = { + def receive = { case "OneWay" => Global.oneWay = "received" } } class RemoteActorSpecActorBidirectional extends Actor { - def receive: PartialFunction[Any, Unit] = { + def receive = { case "Hello" => reply("World") case "Failure" => @@ -46,7 +46,7 @@ class RemoteActorTest extends JUnitSuite { val result = actor ! "OneWay" Thread.sleep(100) assert("received" === Global.oneWay) - actor.stop + actor.exit } @Test @@ -57,7 +57,7 @@ class RemoteActorTest extends JUnitSuite { actor.start val result: String = actor !? "Hello" assert("World" === result) - actor.stop + actor.exit } @Test @@ -68,7 +68,7 @@ class RemoteActorTest extends JUnitSuite { actor.start val result = actor !! "Hello" assert("World" === result.get.asInstanceOf[String]) - actor.stop + actor.exit } @Test @@ -84,6 +84,6 @@ class RemoteActorTest extends JUnitSuite { case e => assert("expected" === e.getMessage()) } - actor.stop + actor.exit } } diff --git a/akka-actors/src/test/scala/RemoteSupervisorTest.scala b/akka-actors/src/test/scala/RemoteSupervisorTest.scala index 5aefa0d0a1..2150707fac 100644 --- a/akka-actors/src/test/scala/RemoteSupervisorTest.scala +++ b/akka-actors/src/test/scala/RemoteSupervisorTest.scala @@ -13,18 +13,18 @@ import org.junit.Test object Log { var messageLog: String = "" - var oneWayLog: String = "" + var oneWayLog: String = "" } + /** * @author Jonas Bonér */ -class RemoteSupervisorTest extends JUnitSuite { - +class RemoteSupervisorTest extends JUnitSuite { akka.Config.config new Thread(new Runnable() { - def run = { - RemoteServer.start - } + def run = { + RemoteServer.start + } }).start Thread.sleep(1000) @@ -277,166 +277,166 @@ class RemoteSupervisorTest extends JUnitSuite { } } */ - + /* - @Test def shouldOneWayKillSingleActorAllForOne = { - Logg.messageLog = "" - val sup = getSingleActorAllForOneSupervisor - sup ! StartSupervisor - Thread.sleep(500) - intercept[RuntimeException] { - pingpong1 ! BinaryString("Die") - } - Thread.sleep(500) - expect("DIE") { - Logg.messageLog - } - } + @Test def shouldOneWayKillSingleActorAllForOne = { + Logg.messageLog = "" + val sup = getSingleActorAllForOneSupervisor + sup ! StartSupervisor + Thread.sleep(500) + intercept[RuntimeException] { + pingpong1 ! BinaryString("Die") + } + Thread.sleep(500) + expect("DIE") { + Logg.messageLog + } + } - @Test def shouldOneWayCallKillCallSingleActorAllForOne = { - Logg.messageLog = "" - val sup = getSingleActorAllForOneSupervisor - sup ! StartSupervisor - Thread.sleep(500) - expect("pong") { - (pingpong1 ! BinaryString("Ping")).getOrElse("nil") - } - Thread.sleep(500) - expect("ping") { - Logg.messageLog - } - intercept[RuntimeException] { - pingpong1 ! BinaryString("Die") - } - Thread.sleep(500) - expect("pingDIE") { - Logg.messageLog - } - expect("pong") { - (pingpong1 ! BinaryString("Ping")).getOrElse("nil") - } - Thread.sleep(500) - expect("pingDIEping") { - Logg.messageLog - } - } + @Test def shouldOneWayCallKillCallSingleActorAllForOne = { + Logg.messageLog = "" + val sup = getSingleActorAllForOneSupervisor + sup ! StartSupervisor + Thread.sleep(500) + expect("pong") { + (pingpong1 ! BinaryString("Ping")).getOrElse("nil") + } + Thread.sleep(500) + expect("ping") { + Logg.messageLog + } + intercept[RuntimeException] { + pingpong1 ! BinaryString("Die") + } + Thread.sleep(500) + expect("pingDIE") { + Logg.messageLog + } + expect("pong") { + (pingpong1 ! BinaryString("Ping")).getOrElse("nil") + } + Thread.sleep(500) + expect("pingDIEping") { + Logg.messageLog + } + } - @Test def shouldOneWayKillMultipleActorsOneForOne = { - Logg.messageLog = "" - val sup = getMultipleActorsOneForOneConf - sup ! StartSupervisor - Thread.sleep(500) - intercept[RuntimeException] { - pingpong3 ! BinaryString("Die") - } - Thread.sleep(500) - expect("DIE") { - Logg.messageLog - } - } + @Test def shouldOneWayKillMultipleActorsOneForOne = { + Logg.messageLog = "" + val sup = getMultipleActorsOneForOneConf + sup ! StartSupervisor + Thread.sleep(500) + intercept[RuntimeException] { + pingpong3 ! BinaryString("Die") + } + Thread.sleep(500) + expect("DIE") { + Logg.messageLog + } + } - def tesOneWayCallKillCallMultipleActorsOneForOne = { - Logg.messageLog = "" - val sup = getMultipleActorsOneForOneConf - sup ! StartSupervisor - Thread.sleep(500) - expect("pong") { - (pingpong1 ! BinaryString("Ping")).getOrElse("nil") - } - Thread.sleep(500) - expect("pong") { - (pingpong2 ! BinaryString("Ping")).getOrElse("nil") - } - Thread.sleep(500) - expect("pong") { - (pingpong3 ! BinaryString("Ping")).getOrElse("nil") - } - Thread.sleep(500) - expect("pingpingping") { - Logg.messageLog - } - intercept[RuntimeException] { - pingpong2 ! BinaryString("Die") - } - Thread.sleep(500) - expect("pingpingpingDIE") { - Logg.messageLog - } - expect("pong") { - (pingpong1 ! BinaryString("Ping")).getOrElse("nil") - } - Thread.sleep(500) - expect("pong") { - (pingpong2 ! BinaryString("Ping")).getOrElse("nil") - } - Thread.sleep(500) - expect("pong") { - (pingpong3 ! BinaryString("Ping")).getOrElse("nil") - } - Thread.sleep(500) - expect("pingpingpingDIEpingpingping") { - Logg.messageLog - } - } + def tesOneWayCallKillCallMultipleActorsOneForOne = { + Logg.messageLog = "" + val sup = getMultipleActorsOneForOneConf + sup ! StartSupervisor + Thread.sleep(500) + expect("pong") { + (pingpong1 ! BinaryString("Ping")).getOrElse("nil") + } + Thread.sleep(500) + expect("pong") { + (pingpong2 ! BinaryString("Ping")).getOrElse("nil") + } + Thread.sleep(500) + expect("pong") { + (pingpong3 ! BinaryString("Ping")).getOrElse("nil") + } + Thread.sleep(500) + expect("pingpingping") { + Logg.messageLog + } + intercept[RuntimeException] { + pingpong2 ! BinaryString("Die") + } + Thread.sleep(500) + expect("pingpingpingDIE") { + Logg.messageLog + } + expect("pong") { + (pingpong1 ! BinaryString("Ping")).getOrElse("nil") + } + Thread.sleep(500) + expect("pong") { + (pingpong2 ! BinaryString("Ping")).getOrElse("nil") + } + Thread.sleep(500) + expect("pong") { + (pingpong3 ! BinaryString("Ping")).getOrElse("nil") + } + Thread.sleep(500) + expect("pingpingpingDIEpingpingping") { + Logg.messageLog + } + } - @Test def shouldOneWayKillMultipleActorsAllForOne = { - Logg.messageLog = "" - val sup = getMultipleActorsAllForOneConf - sup ! StartSupervisor - Thread.sleep(500) - intercept[RuntimeException] { - pingpong2 ! BinaryString("Die") - } - Thread.sleep(500) - expect("DIEDIEDIE") { - Logg.messageLog - } - } + @Test def shouldOneWayKillMultipleActorsAllForOne = { + Logg.messageLog = "" + val sup = getMultipleActorsAllForOneConf + sup ! StartSupervisor + Thread.sleep(500) + intercept[RuntimeException] { + pingpong2 ! BinaryString("Die") + } + Thread.sleep(500) + expect("DIEDIEDIE") { + Logg.messageLog + } + } - def tesOneWayCallKillCallMultipleActorsAllForOne = { - Logg.messageLog = "" - val sup = getMultipleActorsAllForOneConf - sup ! StartSupervisor - Thread.sleep(500) - expect("pong") { - pingpong1 ! BinaryString("Ping") - } - Thread.sleep(500) - expect("pong") { - (pingpong2 ! BinaryString("Ping")).getOrElse("nil") - } - Thread.sleep(500) - expect("pong") { - (pingpong3 ! BinaryString("Ping")).getOrElse("nil") - } - Thread.sleep(500) - expect("pingpingping") { - Logg.messageLog - } - intercept[RuntimeException] { - pingpong2 ! BinaryString("Die") - } - Thread.sleep(500) - expect("pingpingpingDIEDIEDIE") { - Logg.messageLog - } - expect("pong") { - (pingpong1 ! BinaryString("Ping")).getOrElse("nil") - } - Thread.sleep(500) - expect("pong") { - (pingpong2 ! BinaryString("Ping")).getOrElse("nil") - } - Thread.sleep(500) - expect("pong") { - (pingpong3 ! BinaryString("Ping")).getOrElse("nil") - } - Thread.sleep(500) - expect("pingpingpingDIEDIEDIEpingpingping") { - Logg.messageLog - } - } - */ + def tesOneWayCallKillCallMultipleActorsAllForOne = { + Logg.messageLog = "" + val sup = getMultipleActorsAllForOneConf + sup ! StartSupervisor + Thread.sleep(500) + expect("pong") { + pingpong1 ! BinaryString("Ping") + } + Thread.sleep(500) + expect("pong") { + (pingpong2 ! BinaryString("Ping")).getOrElse("nil") + } + Thread.sleep(500) + expect("pong") { + (pingpong3 ! BinaryString("Ping")).getOrElse("nil") + } + Thread.sleep(500) + expect("pingpingping") { + Logg.messageLog + } + intercept[RuntimeException] { + pingpong2 ! BinaryString("Die") + } + Thread.sleep(500) + expect("pingpingpingDIEDIEDIE") { + Logg.messageLog + } + expect("pong") { + (pingpong1 ! BinaryString("Ping")).getOrElse("nil") + } + Thread.sleep(500) + expect("pong") { + (pingpong2 ! BinaryString("Ping")).getOrElse("nil") + } + Thread.sleep(500) + expect("pong") { + (pingpong3 ! BinaryString("Ping")).getOrElse("nil") + } + Thread.sleep(500) + expect("pingpingpingDIEDIEDIEpingpingping") { + Logg.messageLog + } + } + */ /* @Test def shouldNestedSupervisorsTerminateFirstLevelActorAllForOne = { @@ -467,34 +467,29 @@ class RemoteSupervisorTest extends JUnitSuite { pingpong1 = new RemotePingPong1Actor pingpong1.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT) - object factory extends SupervisorFactory { - override def getSupervisorConfig: SupervisorConfig = { - SupervisorConfig( - RestartStrategy(AllForOne, 3, 100), - Supervise( - pingpong1, - LifeCycle(Permanent)) - :: Nil) - } - } - factory.newSupervisor + val factory = SupervisorFactory( + SupervisorConfig( + RestartStrategy(AllForOne, 3, 100), + Supervise( + pingpong1, + LifeCycle(Permanent)) + :: Nil)) + + factory.newInstance } def getSingleActorOneForOneSupervisor: Supervisor = { pingpong1 = new RemotePingPong1Actor pingpong1.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT) - object factory extends SupervisorFactory { - override def getSupervisorConfig: SupervisorConfig = { - SupervisorConfig( - RestartStrategy(OneForOne, 3, 100), - Supervise( - pingpong1, - LifeCycle(Permanent)) - :: Nil) - } - } - factory.newSupervisor + val factory = SupervisorFactory( + SupervisorConfig( + RestartStrategy(OneForOne, 3, 100), + Supervise( + pingpong1, + LifeCycle(Permanent)) + :: Nil)) + factory.newInstance } def getMultipleActorsAllForOneConf: Supervisor = { @@ -505,25 +500,22 @@ class RemoteSupervisorTest extends JUnitSuite { pingpong3 = new RemotePingPong3Actor pingpong3.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT) - object factory extends SupervisorFactory { - override def getSupervisorConfig: SupervisorConfig = { - SupervisorConfig( - RestartStrategy(AllForOne, 3, 100), - Supervise( - pingpong1, - LifeCycle(Permanent)) - :: - Supervise( - pingpong2, - LifeCycle(Permanent)) - :: - Supervise( - pingpong3, - LifeCycle(Permanent)) - :: Nil) - } - } - factory.newSupervisor + val factory = SupervisorFactory( + SupervisorConfig( + RestartStrategy(AllForOne, 3, 100), + Supervise( + pingpong1, + LifeCycle(Permanent)) + :: + Supervise( + pingpong2, + LifeCycle(Permanent)) + :: + Supervise( + pingpong3, + LifeCycle(Permanent)) + :: Nil)) + factory.newInstance } def getMultipleActorsOneForOneConf: Supervisor = { @@ -534,25 +526,22 @@ class RemoteSupervisorTest extends JUnitSuite { pingpong3 = new RemotePingPong3Actor pingpong3.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT) - object factory extends SupervisorFactory { - override def getSupervisorConfig: SupervisorConfig = { - SupervisorConfig( - RestartStrategy(OneForOne, 3, 100), - Supervise( - pingpong1, - LifeCycle(Permanent)) - :: - Supervise( - pingpong2, - LifeCycle(Permanent)) - :: - Supervise( - pingpong3, - LifeCycle(Permanent)) - :: Nil) - } - } - factory.newSupervisor + val factory = SupervisorFactory( + SupervisorConfig( + RestartStrategy(OneForOne, 3, 100), + Supervise( + pingpong1, + LifeCycle(Permanent)) + :: + Supervise( + pingpong2, + LifeCycle(Permanent)) + :: + Supervise( + pingpong3, + LifeCycle(Permanent)) + :: Nil)) + factory.newInstance } def getNestedSupervisorsAllForOneConf: Supervisor = { @@ -563,34 +552,30 @@ class RemoteSupervisorTest extends JUnitSuite { pingpong3 = new RemotePingPong3Actor pingpong3.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT) - object factory extends SupervisorFactory { - override def getSupervisorConfig: SupervisorConfig = { - SupervisorConfig( - RestartStrategy(AllForOne, 3, 100), - Supervise( - pingpong1, - LifeCycle(Permanent)) - :: - SupervisorConfig( - RestartStrategy(AllForOne, 3, 100), - Supervise( - pingpong2, - LifeCycle(Permanent)) + val factory = SupervisorFactory( + SupervisorConfig( + RestartStrategy(AllForOne, 3, 100), + Supervise( + pingpong1, + LifeCycle(Permanent)) :: - Supervise( - pingpong3, - LifeCycle(Permanent)) - :: Nil) - :: Nil) - } - } - factory.newSupervisor - } - + SupervisorConfig( + RestartStrategy(AllForOne, 3, 100), + Supervise( + pingpong2, + LifeCycle(Permanent)) + :: + Supervise( + pingpong3, + LifeCycle(Permanent)) + :: Nil) + :: Nil)) + factory.newInstance + } } @serializable class RemotePingPong1Actor extends Actor { - override def receive: PartialFunction[Any, Unit] = { + def receive = { case BinaryString("Ping") => Log.messageLog += "ping" reply("pong") @@ -601,26 +586,28 @@ class RemoteSupervisorTest extends JUnitSuite { case BinaryString("Die") => throw new RuntimeException("DIE") } + override protected def postRestart(reason: AnyRef, config: Option[AnyRef]) { Log.messageLog += reason.asInstanceOf[Exception].getMessage } } @serializable class RemotePingPong2Actor extends Actor { - override def receive: PartialFunction[Any, Unit] = { + def receive = { case BinaryString("Ping") => Log.messageLog += "ping" reply("pong") case BinaryString("Die") => throw new RuntimeException("DIE") } + override protected def postRestart(reason: AnyRef, config: Option[AnyRef]) { Log.messageLog += reason.asInstanceOf[Exception].getMessage } } @serializable class RemotePingPong3Actor extends Actor { - override def receive: PartialFunction[Any, Unit] = { + def receive = { case BinaryString("Ping") => Log.messageLog += "ping" reply("pong") diff --git a/akka-actors/src/test/scala/SchedulerTest.scala b/akka-actors/src/test/scala/SchedulerTest.scala index 029872a295..389fba7012 100644 --- a/akka-actors/src/test/scala/SchedulerTest.scala +++ b/akka-actors/src/test/scala/SchedulerTest.scala @@ -11,7 +11,7 @@ class SchedulerTest extends JUnitSuite { var count = 0 case object Tick val actor = new Actor() { - def receive: PartialFunction[Any, Unit] = { + def receive = { case Tick => count += 1 }} actor.start diff --git a/akka-actors/src/test/scala/SupervisorTest.scala b/akka-actors/src/test/scala/SupervisorTest.scala index 7bba332e69..f2a98727d6 100644 --- a/akka-actors/src/test/scala/SupervisorTest.scala +++ b/akka-actors/src/test/scala/SupervisorTest.scala @@ -4,7 +4,7 @@ package se.scalablesolutions.akka.actor -import config.ScalaConfig._ +import se.scalablesolutions.akka.config.ScalaConfig._ import org.scalatest.junit.JUnitSuite import org.junit.Test @@ -453,33 +453,27 @@ class SupervisorTest extends JUnitSuite { pingpong1 = new PingPong1Actor - object factory extends SupervisorFactory { - override def getSupervisorConfig: SupervisorConfig = { + val factory = SupervisorFactory( SupervisorConfig( RestartStrategy(AllForOne, 3, 100), Supervise( pingpong1, LifeCycle(Permanent)) - :: Nil) - } - } - factory.newSupervisor + :: Nil)) + factory.newInstance } def getSingleActorOneForOneSupervisor: Supervisor = { pingpong1 = new PingPong1Actor - object factory extends SupervisorFactory { - override def getSupervisorConfig: SupervisorConfig = { + val factory = SupervisorFactory( SupervisorConfig( RestartStrategy(OneForOne, 3, 100), Supervise( pingpong1, LifeCycle(Permanent)) - :: Nil) - } - } - factory.newSupervisor + :: Nil)) + factory.newInstance } def getMultipleActorsAllForOneConf: Supervisor = { @@ -487,8 +481,7 @@ class SupervisorTest extends JUnitSuite { pingpong2 = new PingPong2Actor pingpong3 = new PingPong3Actor - object factory extends SupervisorFactory { - override def getSupervisorConfig: SupervisorConfig = { + val factory = SupervisorFactory( SupervisorConfig( RestartStrategy(AllForOne, 3, 100), Supervise( @@ -502,10 +495,8 @@ class SupervisorTest extends JUnitSuite { Supervise( pingpong3, LifeCycle(Permanent)) - :: Nil) - } - } - factory.newSupervisor + :: Nil)) + factory.newInstance } def getMultipleActorsOneForOneConf: Supervisor = { @@ -513,8 +504,7 @@ class SupervisorTest extends JUnitSuite { pingpong2 = new PingPong2Actor pingpong3 = new PingPong3Actor - object factory extends SupervisorFactory { - override def getSupervisorConfig: SupervisorConfig = { + val factory = SupervisorFactory( SupervisorConfig( RestartStrategy(OneForOne, 3, 100), Supervise( @@ -528,10 +518,8 @@ class SupervisorTest extends JUnitSuite { Supervise( pingpong3, LifeCycle(Permanent)) - :: Nil) - } - } - factory.newSupervisor + :: Nil)) + factory.newInstance } def getNestedSupervisorsAllForOneConf: Supervisor = { @@ -539,8 +527,7 @@ class SupervisorTest extends JUnitSuite { pingpong2 = new PingPong2Actor pingpong3 = new PingPong3Actor - object factory extends SupervisorFactory { - override def getSupervisorConfig: SupervisorConfig = { + val factory = SupervisorFactory( SupervisorConfig( RestartStrategy(AllForOne, 3, 100), Supervise( @@ -557,14 +544,12 @@ class SupervisorTest extends JUnitSuite { pingpong3, LifeCycle(Permanent)) :: Nil) - :: Nil) - } - } - factory.newSupervisor + :: Nil)) + factory.newInstance } class PingPong1Actor extends Actor { - override def receive: PartialFunction[Any, Unit] = { + def receive = { case Ping => messageLog += "ping" reply("pong") @@ -581,7 +566,7 @@ class SupervisorTest extends JUnitSuite { } class PingPong2Actor extends Actor { - override def receive: PartialFunction[Any, Unit] = { + def receive = { case Ping => messageLog += "ping" reply("pong") @@ -594,7 +579,7 @@ class SupervisorTest extends JUnitSuite { } class PingPong3Actor extends Actor { - override def receive: PartialFunction[Any, Unit] = { + def receive = { case Ping => messageLog += "ping" reply("pong") diff --git a/akka-actors/src/test/scala/ThreadBasedActorTest.scala b/akka-actors/src/test/scala/ThreadBasedActorTest.scala index 6d30ec58db..56762a7321 100644 --- a/akka-actors/src/test/scala/ThreadBasedActorTest.scala +++ b/akka-actors/src/test/scala/ThreadBasedActorTest.scala @@ -13,7 +13,7 @@ class ThreadBasedActorTest extends JUnitSuite { class TestActor extends Actor { dispatcher = Dispatchers.newThreadBasedDispatcher(this) - def receive: PartialFunction[Any, Unit] = { + def receive = { case "Hello" => reply("World") case "Failure" => @@ -25,7 +25,7 @@ class ThreadBasedActorTest extends JUnitSuite { implicit val timeout = 5000L var oneWay = "nada" val actor = new Actor { - def receive: PartialFunction[Any, Unit] = { + def receive = { case "OneWay" => oneWay = "received" } } @@ -33,7 +33,7 @@ class ThreadBasedActorTest extends JUnitSuite { val result = actor ! "OneWay" Thread.sleep(100) assert("received" === oneWay) - actor.stop + actor.exit } @Test def shouldSendReplySync = { @@ -42,7 +42,7 @@ class ThreadBasedActorTest extends JUnitSuite { actor.start val result: String = actor !? "Hello" assert("World" === result) - actor.stop + actor.exit } @Test def shouldSendReplyAsync = { @@ -51,7 +51,7 @@ class ThreadBasedActorTest extends JUnitSuite { actor.start val result = actor !! "Hello" assert("World" === result.get.asInstanceOf[String]) - actor.stop + actor.exit } @Test def shouldSendReceiveException = { @@ -65,6 +65,6 @@ class ThreadBasedActorTest extends JUnitSuite { case e => assert("expected" === e.getMessage()) } - actor.stop + actor.exit } } diff --git a/akka-actors/src/test/scala/ThreadBasedDispatcherTest.scala b/akka-actors/src/test/scala/ThreadBasedDispatcherTest.scala index e5f4a6f1d4..1495257a7f 100644 --- a/akka-actors/src/test/scala/ThreadBasedDispatcherTest.scala +++ b/akka-actors/src/test/scala/ThreadBasedDispatcherTest.scala @@ -13,9 +13,9 @@ import se.scalablesolutions.akka.actor.Actor class ThreadBasedDispatcherTest extends JUnitSuite { private var threadingIssueDetected: AtomicBoolean = null - val key1 = new Actor { def receive: PartialFunction[Any, Unit] = { case _ => {}} } - val key2 = new Actor { def receive: PartialFunction[Any, Unit] = { case _ => {}} } - val key3 = new Actor { def receive: PartialFunction[Any, Unit] = { case _ => {}} } + val key1 = new Actor { def receive = { case _ => {}} } + val key2 = new Actor { def receive = { case _ => {}} } + val key3 = new Actor { def receive = { case _ => {}} } class TestMessageHandle(handleLatch: CountDownLatch) extends MessageInvoker { val guardLock: Lock = new ReentrantLock diff --git a/akka-amqp/src/main/scala/AMQP.scala b/akka-amqp/src/main/scala/AMQP.scala index 6dddd7a377..0c2376a905 100644 --- a/akka-amqp/src/main/scala/AMQP.scala +++ b/akka-amqp/src/main/scala/AMQP.scala @@ -32,7 +32,7 @@ import java.io.IOException * val consumer = AMQP.newConsumer(params, hostname, port, exchange, ExchangeType.Direct, Serializer.ScalaJSON, None, 100) * * consumer ! MessageConsumerListener(queue, routingKey, new Actor() { - * def receive: PartialFunction[Any, Unit] = { + * def receive = { * case Message(payload, _, _, _, _) => log.debug("Received message: %s", payload) * } * }) @@ -208,7 +208,7 @@ object AMQP extends Actor { override def shutdown = { connections.values.asScala.foreach(_ ! Stop) - stop + exit } /** @@ -236,7 +236,7 @@ object AMQP extends Actor { channel.basicPublish(exchangeName, routingKey, mandatory, immediate, properties, payload.asInstanceOf[Array[Byte]]) case Stop => disconnect - stop + exit } protected def setupChannel = { @@ -323,7 +323,7 @@ object AMQP extends Actor { case Stop => listeners.elements.toList.map(_._2).foreach(unregisterListener(_)) disconnect - stop + exit case message: Message => handleIllegalMessage("AMQP.Consumer [" + this + "] can't be used to send messages, ignoring message [" + message + "]") @@ -401,7 +401,7 @@ object AMQP extends Actor { case Some(tag) => channel.basicCancel(tag) unlink(listener.actor) - listener.actor.stop + listener.actor.exit log.debug("Message consumer is cancelled and shut down [%s]", listener) } } diff --git a/akka-amqp/src/main/scala/ExampleSession.scala b/akka-amqp/src/main/scala/ExampleSession.scala index 3054080b8f..574b825470 100644 --- a/akka-amqp/src/main/scala/ExampleSession.scala +++ b/akka-amqp/src/main/scala/ExampleSession.scala @@ -30,7 +30,7 @@ object ExampleSession { def direct = { val consumer = AMQP.newConsumer(CONFIG, HOSTNAME, PORT, IM, ExchangeType.Direct, None, 100, false, false, Map[String, AnyRef]()) consumer ! MessageConsumerListener("@george_bush", "direct", new Actor() { - def receive: PartialFunction[Any, Unit] = { + def receive = { case Message(payload, _, _, _, _) => log.info("@george_bush received message from: %s", new String(payload.asInstanceOf[Array[Byte]])) } }) @@ -41,12 +41,12 @@ object ExampleSession { def fanout = { val consumer = AMQP.newConsumer(CONFIG, HOSTNAME, PORT, CHAT, ExchangeType.Fanout, None, 100, false, false, Map[String, AnyRef]()) consumer ! MessageConsumerListener("@george_bush", "", new Actor() { - def receive: PartialFunction[Any, Unit] = { + def receive = { case Message(payload, _, _, _, _) => log.info("@george_bush received message from: %s", new String(payload.asInstanceOf[Array[Byte]])) } }) consumer ! MessageConsumerListener("@barack_obama", "", new Actor() { - def receive: PartialFunction[Any, Unit] = { + def receive = { case Message(payload, _, _, _, _) => log.info("@barack_obama received message from: %s", new String(payload.asInstanceOf[Array[Byte]])) } }) diff --git a/akka-fun-test-java/src/test/java/se/scalablesolutions/akka/api/InMemNestedStateTest.java b/akka-fun-test-java/src/test/java/se/scalablesolutions/akka/api/InMemNestedStateTest.java index 1d70324a1a..26c6747eca 100644 --- a/akka-fun-test-java/src/test/java/se/scalablesolutions/akka/api/InMemNestedStateTest.java +++ b/akka-fun-test-java/src/test/java/se/scalablesolutions/akka/api/InMemNestedStateTest.java @@ -17,7 +17,7 @@ public class InMemNestedStateTest extends TestCase { final private ActiveObjectConfigurator conf = new ActiveObjectConfigurator(); - protected void setUp() { + public InMemNestedStateTest() { conf.configure( new RestartStrategy(new AllForOne(), 3, 5000), new Component[]{ @@ -26,7 +26,7 @@ public class InMemNestedStateTest extends TestCase { new Component(InMemStatefulNested.class, new LifeCycle(new Permanent()), 10000000), new Component(InMemFailer.class, new LifeCycle(new Permanent()), 1000) //new Component("inmem-clasher", InMemClasher.class, InMemClasherImpl.class, new LifeCycle(new Permanent()), 100000) - }).inject().supervise(); + }).supervise(); Config.config(); InMemStateful stateful = conf.getInstance(InMemStateful.class); stateful.init(); @@ -34,10 +34,6 @@ public class InMemNestedStateTest extends TestCase { nested.init(); } - protected void tearDown() { - conf.stop(); - } - public void testMapShouldNotRollbackStateForStatefulServerInCaseOfSuccess() throws Exception { InMemStateful stateful = conf.getInstance(InMemStateful.class); stateful.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state diff --git a/akka-fun-test-java/src/test/java/se/scalablesolutions/akka/api/InMemoryStateTest.java b/akka-fun-test-java/src/test/java/se/scalablesolutions/akka/api/InMemoryStateTest.java index 3dbe92ca75..e29e8ef81f 100644 --- a/akka-fun-test-java/src/test/java/se/scalablesolutions/akka/api/InMemoryStateTest.java +++ b/akka-fun-test-java/src/test/java/se/scalablesolutions/akka/api/InMemoryStateTest.java @@ -9,7 +9,9 @@ import junit.framework.TestCase; import se.scalablesolutions.akka.Config; import se.scalablesolutions.akka.config.*; import se.scalablesolutions.akka.config.ActiveObjectConfigurator; + import static se.scalablesolutions.akka.config.JavaConfig.*; + import se.scalablesolutions.akka.actor.*; import se.scalablesolutions.akka.Kernel; @@ -18,27 +20,23 @@ public class InMemoryStateTest extends TestCase { final private ActiveObjectConfigurator conf = new ActiveObjectConfigurator(); - protected void setUp() { + public InMemoryStateTest() { Config.config(); conf.configure( new RestartStrategy(new AllForOne(), 3, 5000), new Component[]{ new Component(InMemStateful.class, new LifeCycle(new Permanent()), - //new RestartCallbacks("preRestart", "postRestart")), - 10000), + //new RestartCallbacks("preRestart", "postRestart")), + 10000), new Component(InMemFailer.class, new LifeCycle(new Permanent()), - 10000) - }).inject().supervise(); - InMemStateful stateful = conf.getInstance(InMemStateful.class); - stateful.init(); + 10000) + }).supervise(); + InMemStateful stateful = conf.getInstance(InMemStateful.class); + stateful.init(); } - protected void tearDown() { - conf.stop(); - } - public void testMapShouldNotRollbackStateForStatefulServerInCaseOfSuccess() { InMemStateful stateful = conf.getInstance(InMemStateful.class); stateful.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state diff --git a/akka-persistence/src/test/scala/CassandraPersistentActorSpec.scala b/akka-persistence/src/test/scala/CassandraPersistentActorSpec.scala index 28fe92651b..305763eba3 100644 --- a/akka-persistence/src/test/scala/CassandraPersistentActorSpec.scala +++ b/akka-persistence/src/test/scala/CassandraPersistentActorSpec.scala @@ -35,7 +35,7 @@ class CassandraPersistentActor extends Actor { private lazy val vectorState: PersistentVector = PersistentState.newVector(CassandraStorageConfig()) private lazy val refState: PersistentRef = PersistentState.newRef(CassandraStorageConfig()) - def receive: PartialFunction[Any, Unit] = { + def receive = { case GetMapState(key) => reply(mapState.get(key).get) case GetVectorSize => @@ -67,7 +67,7 @@ class CassandraPersistentActor extends Actor { @serializable class PersistentFailerActor extends Actor { makeTransactionRequired - def receive: PartialFunction[Any, Unit] = { + def receive = { case "Failure" => throw new RuntimeException("expected") } diff --git a/akka-persistence/src/test/scala/MongoPersistentActorSpec.scala b/akka-persistence/src/test/scala/MongoPersistentActorSpec.scala index 4fc18e8967..b04b2d04b4 100644 --- a/akka-persistence/src/test/scala/MongoPersistentActorSpec.scala +++ b/akka-persistence/src/test/scala/MongoPersistentActorSpec.scala @@ -32,7 +32,7 @@ class BankAccountActor extends Actor { private lazy val accountState: PersistentMap = PersistentState.newMap(MongoStorageConfig()) private lazy val txnLog: PersistentVector = PersistentState.newVector(MongoStorageConfig()) - def receive: PartialFunction[Any, Unit] = { + def receive = { // check balance case Balance(accountNo) => txnLog.add("Balance:" + accountNo) @@ -176,7 +176,7 @@ class BankAccountActor extends Actor { txnLog = PersistentState.newVector(MongoStorageConfig()) } - def receive: PartialFunction[Any, Unit] = { + def receive = { // check balance case Balance(accountNo) => txnLog.add("Balance:" + accountNo) diff --git a/akka-samples-lift/src/main/scala/akka/SimpleService.scala b/akka-samples-lift/src/main/scala/akka/SimpleService.scala index 8f7537f5bf..b4bbd52157 100644 --- a/akka-samples-lift/src/main/scala/akka/SimpleService.scala +++ b/akka-samples-lift/src/main/scala/akka/SimpleService.scala @@ -29,7 +29,7 @@ class SimpleService extends Actor { @Produces(Array("text/html")) def count = (this !! Tick).getOrElse(

Error in counter

) - override def receive: PartialFunction[Any, Unit] = { + def receive = { case Tick => if (hasStartedTicking) { val counter = storage.get(KEY).get.asInstanceOf[Integer].intValue storage.put(KEY, new Integer(counter + 1)) @@ -62,7 +62,7 @@ class PersistentSimpleService extends Actor { @Produces(Array("text/html")) def count = (this !! Tick).getOrElse(

Error in counter

) - override def receive: PartialFunction[Any, Unit] = { + def receive = { case Tick => if (hasStartedTicking) { val counter = storage.get(KEY).get.asInstanceOf[Integer].intValue storage.put(KEY, new Integer(counter + 1)) diff --git a/akka-samples-lift/src/main/scala/bootstrap/liftweb/Boot.scala b/akka-samples-lift/src/main/scala/bootstrap/liftweb/Boot.scala index ae32e277b6..553d90b277 100644 --- a/akka-samples-lift/src/main/scala/bootstrap/liftweb/Boot.scala +++ b/akka-samples-lift/src/main/scala/bootstrap/liftweb/Boot.scala @@ -4,7 +4,6 @@ import _root_.net.liftweb.util._ import _root_.net.liftweb.http._ import _root_.net.liftweb.sitemap._ import _root_.net.liftweb.sitemap.Loc._ -//import _root_.net.liftweb.common._ import _root_.net.liftweb.http.auth._ import Helpers._ @@ -15,9 +14,9 @@ import se.scalablesolutions.akka.util.Logging import sample.lift.{PersistentSimpleService, SimpleService} /** - * A class that's instantiated early and run. It allows the application - * to modify lift's environment - */ + * A class that's instantiated early and run. It allows the application + * to modify lift's environment + */ class Boot { def boot { // where to search snippet @@ -37,21 +36,17 @@ class Boot { LiftRules.passNotFoundToChain = true - object factory extends SupervisorFactory { - override def getSupervisorConfig: SupervisorConfig = { - SupervisorConfig( - RestartStrategy(OneForOne, 3, 100), - Supervise( - new SimpleService, - LifeCycle(Permanent)) :: - Supervise( - new PersistentSimpleService, - LifeCycle(Permanent)) :: - Nil) - } - } - val supervisor = factory.newSupervisor - supervisor.startSupervisor + val factory = SupervisorFactory( + SupervisorConfig( + RestartStrategy(OneForOne, 3, 100), + Supervise( + new SimpleService, + LifeCycle(Permanent)) :: + Supervise( + new PersistentSimpleService, + LifeCycle(Permanent)) :: + Nil)) + factory.newInstance.start // Build SiteMap // val entries = Menu(Loc("Home", List("index"), "Home")) :: Nil diff --git a/akka-samples-scala/src/main/scala/SimpleService.scala b/akka-samples-scala/src/main/scala/SimpleService.scala index 6cb6ed0b8f..e5642171b7 100644 --- a/akka-samples-scala/src/main/scala/SimpleService.scala +++ b/akka-samples-scala/src/main/scala/SimpleService.scala @@ -18,24 +18,20 @@ import org.atmosphere.util.XSSHtmlFilter import org.atmosphere.cpr.BroadcastFilter class Boot { - object factory extends SupervisorFactory { - override def getSupervisorConfig: SupervisorConfig = { - SupervisorConfig( - RestartStrategy(OneForOne, 3, 100), - Supervise( - new SimpleService, - LifeCycle(Permanent)) :: - Supervise( - new Chat, - LifeCycle(Permanent)) :: - Supervise( - new PersistentSimpleService, - LifeCycle(Permanent)) - :: Nil) - } - } - val supervisor = factory.newSupervisor - supervisor.startSupervisor + val factory = SupervisorFactory( + SupervisorConfig( + RestartStrategy(OneForOne, 3, 100), + Supervise( + new SimpleService, + LifeCycle(Permanent)) :: + Supervise( + new Chat, + LifeCycle(Permanent)) :: + Supervise( + new PersistentSimpleService, + LifeCycle(Permanent)) + :: Nil)) + factory.newInstance.start } /** @@ -58,7 +54,7 @@ class SimpleService extends Actor { @Produces(Array("text/html")) def count = (this !! Tick).getOrElse(Error in counter) - override def receive: PartialFunction[Any, Unit] = { + def receive = { case Tick => if (hasStartedTicking) { val counter = storage.get(KEY).get.asInstanceOf[Integer].intValue storage.put(KEY, new Integer(counter + 1)) @@ -91,7 +87,7 @@ class PersistentSimpleService extends Actor { @Produces(Array("text/html")) def count = (this !! Tick).getOrElse(Error in counter) - override def receive: PartialFunction[Any, Unit] = { + def receive = { case Tick => if (hasStartedTicking) { val counter = storage.get(KEY).get.asInstanceOf[Integer].intValue storage.put(KEY, new Integer(counter + 1)) @@ -121,7 +117,7 @@ class Chat extends Actor with Logging { s toString } - override def receive: PartialFunction[Any, Unit] = { + def receive = { case Chat(who, what, msg) => { what match { case "login" => reply("System Message__" + who + " has joined.") diff --git a/akka-samples-security/src/main/scala/SimpleService.scala b/akka-samples-security/src/main/scala/SimpleService.scala index 05bbd75f7b..a0950a2f38 100644 --- a/akka-samples-security/src/main/scala/SimpleService.scala +++ b/akka-samples-security/src/main/scala/SimpleService.scala @@ -11,75 +11,69 @@ import se.scalablesolutions.akka.security.{DigestAuthenticationActor, UserInfo} import se.scalablesolutions.akka.state.TransactionalState class Boot { + val factory = SupervisorFactory( + SupervisorConfig( + RestartStrategy(OneForOne, 3, 100), + // Dummy implementations of all authentication actors + // see akka.conf to enable one of these for the AkkaSecurityFilterFactory + Supervise( + new BasicAuthenticationService, + LifeCycle(Permanent)) :: + /** + Supervise( + new DigestAuthenticationService, + LifeCycle(Permanent)) :: + Supervise( + new SpnegoAuthenticationService, + LifeCycle(Permanent)) :: + **/ + Supervise( + new SecureTickActor, + LifeCycle(Permanent)):: Nil)) - object factory extends SupervisorFactory { - override def getSupervisorConfig: SupervisorConfig = { - SupervisorConfig( - RestartStrategy(OneForOne, 3, 100), - // Dummy implementations of all authentication actors - // see akka.conf to enable one of these for the AkkaSecurityFilterFactory - Supervise( - new BasicAuthenticationService, - LifeCycle(Permanent)) :: - /** - Supervise( - new DigestAuthenticationService, - LifeCycle(Permanent)) :: - Supervise( - new SpnegoAuthenticationService, - LifeCycle(Permanent)) :: - **/ - Supervise( - new SecureTickActor, - LifeCycle(Permanent)):: Nil) - } - - } - - val supervisor = factory.newSupervisor - supervisor.startSupervisor + val supervisor = factory.newInstance + supervisor.start } /* * In akka.conf you can set the FQN of any AuthenticationActor of your wish, under the property name: akka.rest.authenticator */ class DigestAuthenticationService extends DigestAuthenticationActor { - //If you want to have a distributed nonce-map, you can use something like below, - //don't forget to configure your standalone Cassandra instance - // - //makeTransactionRequired - //override def mkNonceMap = PersistentState.newMap(CassandraStorageConfig()).asInstanceOf[scala.collection.mutable.Map[String,Long]] + //If you want to have a distributed nonce-map, you can use something like below, + //don't forget to configure your standalone Cassandra instance + // + //makeTransactionRequired + //override def mkNonceMap = PersistentState.newMap(CassandraStorageConfig()).asInstanceOf[scala.collection.mutable.Map[String,Long]] - //Use an in-memory nonce-map as default - override def mkNonceMap = new scala.collection.mutable.HashMap[String,Long] + //Use an in-memory nonce-map as default + override def mkNonceMap = new scala.collection.mutable.HashMap[String, Long] - //Change this to whatever you want - override def realm = "test" + //Change this to whatever you want + override def realm = "test" - //Dummy method that allows you to log on with whatever username with the password "bar" - override def userInfo(username : String) : Option[UserInfo] = Some(UserInfo(username,"bar","ninja" :: "chef" :: Nil)) + //Dummy method that allows you to log on with whatever username with the password "bar" + override def userInfo(username: String): Option[UserInfo] = Some(UserInfo(username, "bar", "ninja" :: "chef" :: Nil)) } class BasicAuthenticationService extends BasicAuthenticationActor { - //Change this to whatever you want - override def realm = "test" + //Change this to whatever you want + override def realm = "test" - //Dummy method that allows you to log on with whatever username - def verify(odc : Option[BasicCredentials]) : Option[UserInfo] = odc match { - case Some(dc) => userInfo(dc.username) - case _ => None - } + //Dummy method that allows you to log on with whatever username + def verify(odc: Option[BasicCredentials]): Option[UserInfo] = odc match { + case Some(dc) => userInfo(dc.username) + case _ => None + } - //Dummy method that allows you to log on with whatever username with the password "bar" - def userInfo(username : String) : Option[UserInfo] = Some(UserInfo(username,"bar","ninja" :: "chef" :: Nil)) + //Dummy method that allows you to log on with whatever username with the password "bar" + def userInfo(username: String): Option[UserInfo] = Some(UserInfo(username, "bar", "ninja" :: "chef" :: Nil)) } class SpnegoAuthenticationService extends SpnegoAuthenticationActor { - - def rolesFor(user: String) = "ninja" :: "chef" :: Nil + def rolesFor(user: String) = "ninja" :: "chef" :: Nil } @@ -87,16 +81,16 @@ class SpnegoAuthenticationService extends SpnegoAuthenticationActor { * a REST Actor with class level paranoia settings to deny all access * * The interesting part is - * @RolesAllowed - * @PermitAll - * @DenyAll + * @RolesAllowed + * @PermitAll + * @DenyAll */ import java.lang.Integer import javax.annotation.security.{RolesAllowed, DenyAll, PermitAll} import javax.ws.rs.{GET, Path, Produces} + @Path("/secureticker") class SecureTickActor extends Actor with Logging { - makeTransactionRequired case object Tick @@ -131,11 +125,13 @@ class SecureTickActor extends Actor with Logging { def paranoiaTick = tick def tick = (this !! Tick) match { - case(Some(counter)) => (Tick: {counter}) + case (Some(counter)) => (Tick: + {counter} + ) case _ => (Error in counter) } - override def receive: PartialFunction[Any, Unit] = { + def receive = { case Tick => if (hasStartedTicking) { val counter = storage.get(KEY).get.intValue storage.put(KEY, counter + 1) diff --git a/akka-security/src/main/scala/Security.scala b/akka-security/src/main/scala/Security.scala index da02640f36..c8964cb506 100644 --- a/akka-security/src/main/scala/Security.scala +++ b/akka-security/src/main/scala/Security.scala @@ -264,17 +264,18 @@ trait DigestAuthenticationActor extends AuthenticationActor[DigestCredentials] { override def receive = authenticate orElse invalidateNonces override def unauthorized: Response = { - val nonce = randomString(64); + val nonce = randomString(64) nonceMap.put(nonce, System.currentTimeMillis) unauthorized(nonce, "auth", randomString(64)) } def unauthorized(nonce: String, qop: String, opaque: String): Response = { - Response.status(401).header("WWW-Authenticate", + Response.status(401).header( + "WWW-Authenticate", "Digest realm=\"" + realm + "\", " + - "qop=\"" + qop + "\", " + - "nonce=\"" + nonce + "\", " + - "opaque=\"" + opaque + "\"").build + "qop=\"" + qop + "\", " + + "nonce=\"" + nonce + "\", " + + "opaque=\"" + opaque + "\"").build } //Tests wether the specified credentials are valid @@ -284,9 +285,10 @@ trait DigestAuthenticationActor extends AuthenticationActor[DigestCredentials] { val ha1 = h(auth.userName + ":" + auth.realm + ":" + user.password) val ha2 = h(auth.method + ":" + auth.uri) - val response = h(ha1 + ":" + auth.nonce + ":" + - auth.nc + ":" + auth.cnonce + ":" + - auth.qop + ":" + ha2) + val response = h( + ha1 + ":" + auth.nonce + ":" + + auth.nc + ":" + auth.cnonce + ":" + + auth.qop + ":" + ha2) (response == auth.response) && (nonceMap.getOrElse(auth.nonce, -1) != -1) } diff --git a/docs/scaladocs-akka-actors/actor/ActiveObject.scala.html b/docs/scaladocs-akka-actors/actor/ActiveObject.scala.html index 1e86256495..2cc8b693e2 100644 --- a/docs/scaladocs-akka-actors/actor/ActiveObject.scala.html +++ b/docs/scaladocs-akka-actors/actor/ActiveObject.scala.html @@ -135,7 +135,7 @@ object ActiveObject { private[akka] def supervise(restartStrategy: RestartStrategy, components: List[Supervise]): Supervisor = { - object factory extends SupervisorFactory { + val factory = SupervisorFactory { override def getSupervisorConfig = SupervisorConfig(restartStrategy, components) } val supervisor = factory.newSupervisor @@ -333,7 +333,7 @@ private[akka] class Dispatcher(val callbacks: Option[RestartCallbacks]) extends //if (initTxState.isDefined) initTxState.get.setAccessible(true) } - override def receive: PartialFunction[Any, Unit] = { + def receive = { case Invocation(joinPoint, isOneWay, _) => if (Actor.SERIALIZE_MESSAGES) serializeArguments(joinPoint) if (isOneWay) joinPoint.proceed diff --git a/docs/scaladocs-akka-actors/actor/Actor.scala.html b/docs/scaladocs-akka-actors/actor/Actor.scala.html index e6dcc18edb..646df38c48 100644 --- a/docs/scaladocs-akka-actors/actor/Actor.scala.html +++ b/docs/scaladocs-akka-actors/actor/Actor.scala.html @@ -158,7 +158,7 @@ trait Actor extends Logging with TransactionManagement { * <p/> * Example code: * <pre> - * def receive: PartialFunction[Any, Unit] = { + * def receive = { * case Ping => * println("got a ping") * reply("pong") @@ -171,7 +171,7 @@ trait Actor extends Logging with TransactionManagement { * } * </pre> */ - protected def receive: PartialFunction[Any, Unit] + protected def receive /** * User overridable callback/setting. diff --git a/docs/scaladocs-akka-actors/actor/Scheduler.scala.html b/docs/scaladocs-akka-actors/actor/Scheduler.scala.html index 5bca802c80..ff8e609167 100644 --- a/docs/scaladocs-akka-actors/actor/Scheduler.scala.html +++ b/docs/scaladocs-akka-actors/actor/Scheduler.scala.html @@ -38,7 +38,7 @@ case class SchedulerException(msg: String, e: Throwable) extends RuntimeExceptio class ScheduleActor(val receiver: Actor, val future: ScheduledFuture[AnyRef]) extends Actor with Logging { lifeCycleConfig = Some(LifeCycle(Permanent)) - def receive: PartialFunction[Any, Unit] = { + def receive = { case UnSchedule => Scheduler.stopSupervising(this) future.cancel(true) @@ -77,7 +77,7 @@ object Scheduler extends Actor { service.shutdown } - def receive: PartialFunction[Any, Unit] = { + def receive = { case _ => {} // ignore all messages } } diff --git a/docs/scaladocs-akka-actors/actor/Supervisor.scala.html b/docs/scaladocs-akka-actors/actor/Supervisor.scala.html index 18ca63a33c..7a92cdda45 100644 --- a/docs/scaladocs-akka-actors/actor/Supervisor.scala.html +++ b/docs/scaladocs-akka-actors/actor/Supervisor.scala.html @@ -133,7 +133,7 @@ class Supervisor private[akka] (handler: FaultHandlingStrategy) extends Actor wi def stopSupervisor = this ! StopSupervisor - protected def receive: PartialFunction[Any, Unit] = { + protected def receive = { case StartSupervisor => linkedActors.toArray.toList.asInstanceOf[List[Actor]].foreach { actor => actor.start; log.info("Starting actor: %s", actor) } diff --git a/docs/scaladocs-akka-actors/se/scalablesolutions/akka/actor/Actor.html b/docs/scaladocs-akka-actors/se/scalablesolutions/akka/actor/Actor.html index 059539ef3e..972addab96 100644 --- a/docs/scaladocs-akka-actors/se/scalablesolutions/akka/actor/Actor.html +++ b/docs/scaladocs-akka-actors/se/scalablesolutions/akka/actor/Actor.html @@ -278,7 +278,7 @@

Example code:

-     def receive: PartialFunction[Any, Unit] = {
+     def receive = {
        case Ping =>
          println("got a ping")
          reply("pong")
diff --git a/docs/scaladocs-akka-actors/se/scalablesolutions/akka/actor/ScheduleActor.html b/docs/scaladocs-akka-actors/se/scalablesolutions/akka/actor/ScheduleActor.html
index f4bf833de8..81436a04f7 100644
--- a/docs/scaladocs-akka-actors/se/scalablesolutions/akka/actor/ScheduleActor.html
+++ b/docs/scaladocs-akka-actors/se/scalablesolutions/akka/actor/ScheduleActor.html
@@ -287,7 +287,7 @@
    

Example code:

-     def receive: PartialFunction[Any, Unit] = {
+     def receive = {
        case Ping =>
          println("got a ping")
          reply("pong")
diff --git a/docs/scaladocs-akka-actors/se/scalablesolutions/akka/actor/Scheduler$object.html b/docs/scaladocs-akka-actors/se/scalablesolutions/akka/actor/Scheduler$object.html
index 8380573c7a..8d5529b56e 100644
--- a/docs/scaladocs-akka-actors/se/scalablesolutions/akka/actor/Scheduler$object.html
+++ b/docs/scaladocs-akka-actors/se/scalablesolutions/akka/actor/Scheduler$object.html
@@ -282,7 +282,7 @@
    

Example code:

-     def receive: PartialFunction[Any, Unit] = {
+     def receive = {
        case Ping =>
          println("got a ping")
          reply("pong")
diff --git a/docs/scaladocs-akka-actors/se/scalablesolutions/akka/actor/Supervisor.html b/docs/scaladocs-akka-actors/se/scalablesolutions/akka/actor/Supervisor.html
index 7a7d04b067..f19c18da1a 100644
--- a/docs/scaladocs-akka-actors/se/scalablesolutions/akka/actor/Supervisor.html
+++ b/docs/scaladocs-akka-actors/se/scalablesolutions/akka/actor/Supervisor.html
@@ -311,7 +311,7 @@
    

Example code:

-     def receive: PartialFunction[Any, Unit] = {
+     def receive = {
        case Ping =>
          println("got a ping")
          reply("pong")
diff --git a/docs/scaladocs-akka-amqp/AMQP.scala.html b/docs/scaladocs-akka-amqp/AMQP.scala.html
index 4d30a70242..3757fa33b5 100644
--- a/docs/scaladocs-akka-amqp/AMQP.scala.html
+++ b/docs/scaladocs-akka-amqp/AMQP.scala.html
@@ -41,7 +41,7 @@ import java.io.IOException
  *   val consumer = AMQP.newConsumer(params, hostname, port, exchange, ExchangeType.Direct, Serializer.ScalaJSON, None, 100)
  *
  *   consumer ! MessageConsumerListener(queue, routingKey, new Actor() {
- *     def receive: PartialFunction[Any, Unit] = {
+ *     def receive = {
  *       case Message(payload, _, _, _, _) => log.debug("Received message: %s", payload)
  *     }
  *   })
@@ -209,7 +209,7 @@ object AMQP extends Actor {
 
     log.info("AMQP.Producer [%s] is started", toString)
 
-    def receive: PartialFunction[Any, Unit] = {
+    def receive = {
       case message @ Message(payload, routingKey, mandatory, immediate, properties) =>
         log.debug("Sending message [%s]", message)
         channel.basicPublish(exchangeName, routingKey, mandatory, immediate, properties, serializer.out(payload))
@@ -312,7 +312,7 @@ object AMQP extends Actor {
       listener.tag = Some(listenerTag)
     }
 
-    def receive: PartialFunction[Any, Unit] = {
+    def receive = {
       case listener: MessageConsumerListener =>
         startLink(listener.actor)
         listeners.put(listener, listener)
@@ -425,7 +425,7 @@ object AMQP extends Actor {
     override def postRestart(reason: AnyRef, config: Option[AnyRef]) = reconnect(initReconnectDelay)
   }
 
-  def receive: PartialFunction[Any, Unit] = {
+  def receive = {
     case _ => {} // ignore all messages
   }
 }
diff --git a/docs/scaladocs-akka-amqp/ExampleSession.scala.html b/docs/scaladocs-akka-amqp/ExampleSession.scala.html
index a937fbf14f..6495493289 100644
--- a/docs/scaladocs-akka-amqp/ExampleSession.scala.html
+++ b/docs/scaladocs-akka-amqp/ExampleSession.scala.html
@@ -40,7 +40,7 @@ object ExampleSession {
   def direct = {
     val consumer = AMQP.newConsumer(CONFIG, HOSTNAME, PORT, IM, ExchangeType.Direct, SERIALIZER, None, 100, false, false, Map[String, AnyRef]())
     consumer ! MessageConsumerListener("@george_bush", "direct", new Actor() {
-      def receive: PartialFunction[Any, Unit] = {
+      def receive = {
         case Message(payload, _, _, _, _) => log.info("@george_bush received message from: %s", payload)
       }
     })
@@ -51,12 +51,12 @@ object ExampleSession {
   def fanout = {
     val consumer = AMQP.newConsumer(CONFIG, HOSTNAME, PORT, CHAT, ExchangeType.Fanout, SERIALIZER, None, 100, false, false, Map[String, AnyRef]())
     consumer ! MessageConsumerListener("@george_bush", "", new Actor() {
-      def receive: PartialFunction[Any, Unit] = {
+      def receive = {
         case Message(payload, _, _, _, _) => log.info("@george_bush received message from: %s", payload)
       }
     })
     consumer ! MessageConsumerListener("@barack_obama", "", new Actor() {
-      def receive: PartialFunction[Any, Unit] = {
+      def receive = {
         case Message(payload, _, _, _, _) => log.info("@barack_obama received message from: %s", payload)
       }
     })
diff --git a/docs/scaladocs-akka-amqp/se/scalablesolutions/akka/amqp/AMQP$object.html b/docs/scaladocs-akka-amqp/se/scalablesolutions/akka/amqp/AMQP$object.html
index 827f8ffac8..ed8087c7c1 100644
--- a/docs/scaladocs-akka-amqp/se/scalablesolutions/akka/amqp/AMQP$object.html
+++ b/docs/scaladocs-akka-amqp/se/scalablesolutions/akka/amqp/AMQP$object.html
@@ -63,7 +63,7 @@
    val consumer = AMQP.newConsumer(params, hostname, port, exchange, ExchangeType.Direct, Serializer.ScalaJSON, None, 100)
 
    consumer ! MessageConsumerListener(queue, routingKey, new Actor() {
-     def receive: PartialFunction[Any, Unit] = {
+     def receive = {
        case Message(payload, _, _, _, _) => log.debug("Received message: %s", payload)
      }
    })
diff --git a/docs/scaladocs-akka-security/Security.scala.html b/docs/scaladocs-akka-security/Security.scala.html
index ce150f8bfc..8620ec9d74 100644
--- a/docs/scaladocs-akka-security/Security.scala.html
+++ b/docs/scaladocs-akka-security/Security.scala.html
@@ -211,7 +211,7 @@ trait AuthenticationActor[C <: Credentials] extends Actor with Logging
         }
     }
 
-    override def receive: PartialFunction[Any, Unit] = authenticate
+    def receive = authenticate
 
     //returns the string value of the "Authorization"-header of the request
     def auth(r : Req) = r.getHeaderValue("Authorization")
@@ -284,7 +284,7 @@ trait DigestAuthenticationActor extends AuthenticationActor[DigestCredentials]
     Scheduler.schedule(this, InvalidateNonces, noncePurgeInterval, noncePurgeInterval, TimeUnit.MILLISECONDS )
 
     //authenticate or invalidate nonces
-    override def receive: PartialFunction[Any, Unit] = authenticate orElse invalidateNonces
+    def receive = authenticate orElse invalidateNonces
 
     override def unauthorized : Response =
     {
diff --git a/docs/scaladocs-akka-security/se/scalablesolutions/akka/security/AuthenticationActor.html b/docs/scaladocs-akka-security/se/scalablesolutions/akka/security/AuthenticationActor.html
index 9d9812df82..460dd68825 100644
--- a/docs/scaladocs-akka-security/se/scalablesolutions/akka/security/AuthenticationActor.html
+++ b/docs/scaladocs-akka-security/se/scalablesolutions/akka/security/AuthenticationActor.html
@@ -253,7 +253,7 @@
         receive..
       
       
-        override def receive
+        def receive
         
         
       
diff --git a/docs/scaladocs-akka-security/se/scalablesolutions/akka/security/BasicAuthenticationActor.html b/docs/scaladocs-akka-security/se/scalablesolutions/akka/security/BasicAuthenticationActor.html
index 3afa719cdb..2e4f01c012 100644
--- a/docs/scaladocs-akka-security/se/scalablesolutions/akka/security/BasicAuthenticationActor.html
+++ b/docs/scaladocs-akka-security/se/scalablesolutions/akka/security/BasicAuthenticationActor.html
@@ -251,7 +251,7 @@
         receive..
       
       
-        override def receive
+        def receive
         
         
       
diff --git a/docs/scaladocs-akka-security/se/scalablesolutions/akka/security/DigestAuthenticationActor.html b/docs/scaladocs-akka-security/se/scalablesolutions/akka/security/DigestAuthenticationActor.html
index 97195537fa..e33418278a 100644
--- a/docs/scaladocs-akka-security/se/scalablesolutions/akka/security/DigestAuthenticationActor.html
+++ b/docs/scaladocs-akka-security/se/scalablesolutions/akka/security/DigestAuthenticationActor.html
@@ -321,7 +321,7 @@
         receive..
       
       
-        override def receive
+        def receive
         
         
       
diff --git a/docs/scaladocs-akka-security/se/scalablesolutions/akka/security/SpnegoAuthenticationActor.html b/docs/scaladocs-akka-security/se/scalablesolutions/akka/security/SpnegoAuthenticationActor.html
index 8cf953060b..ab70c641ee 100644
--- a/docs/scaladocs-akka-security/se/scalablesolutions/akka/security/SpnegoAuthenticationActor.html
+++ b/docs/scaladocs-akka-security/se/scalablesolutions/akka/security/SpnegoAuthenticationActor.html
@@ -276,7 +276,7 @@
         receive..
       
       
-        override def receive
+        def receive