From 49e572d06f93ff5fa3238ad8dc3b1ec5be6c8d14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Bon=C3=A9r?= Date: Wed, 14 Jul 2010 14:38:56 +0200 Subject: [PATCH] Fixed bug in Active Object restart, had no default life-cycle defined + added tests --- akka-core/src/main/scala/actor/ActiveObject.scala | 4 ++-- akka-core/src/main/scala/remote/RemoteServer.scala | 14 +++++++++----- .../src/test/scala/ActiveObjectLifecycleSpec.scala | 14 +++++++++++++- .../NestedTransactionalActiveObjectSpec.scala | 10 +--------- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/akka-core/src/main/scala/actor/ActiveObject.scala b/akka-core/src/main/scala/actor/ActiveObject.scala index c794da9f47..b83816f4d2 100644 --- a/akka-core/src/main/scala/actor/ActiveObject.scala +++ b/akka-core/src/main/scala/actor/ActiveObject.scala @@ -687,8 +687,6 @@ private[akka] class Dispatcher(transactionalRequired: Boolean, private var context: Option[ActiveObjectContext] = None private var targetClass:Class[_] = _ - - def this(transactionalRequired: Boolean) = this(transactionalRequired,None) private[actor] def initialize(targetClass: Class[_], targetInstance: AnyRef, ctx: Option[ActiveObjectContext]) = { @@ -701,6 +699,8 @@ private[akka] class Dispatcher(transactionalRequired: Boolean, context = ctx val methods = targetInstance.getClass.getDeclaredMethods.toList + if (self.lifeCycle.isEmpty) self.lifeCycle = Some(LifeCycle(Permanent)) + // See if we have any config define restart callbacks restartCallbacks match { case None => {} diff --git a/akka-core/src/main/scala/remote/RemoteServer.scala b/akka-core/src/main/scala/remote/RemoteServer.scala index 28d087b3e1..f425d8accf 100644 --- a/akka-core/src/main/scala/remote/RemoteServer.scala +++ b/akka-core/src/main/scala/remote/RemoteServer.scala @@ -215,11 +215,15 @@ class RemoteServer extends Logging { def shutdown = synchronized { if (_isRunning) { - RemoteServer.unregister(hostname, port) - openChannels.disconnect - openChannels.close.awaitUninterruptibly - bootstrap.releaseExternalResources - Cluster.deregisterLocalNode(hostname, port) + try { + RemoteServer.unregister(hostname, port) + openChannels.disconnect + openChannels.close.awaitUninterruptibly + bootstrap.releaseExternalResources + Cluster.deregisterLocalNode(hostname, port) + } catch { + case e: java.nio.channels.ClosedChannelException => log.warning("Could not close remote server channel in a graceful way") + } } } diff --git a/akka-core/src/test/scala/ActiveObjectLifecycleSpec.scala b/akka-core/src/test/scala/ActiveObjectLifecycleSpec.scala index 97b01c12ce..2b8e4d502f 100644 --- a/akka-core/src/test/scala/ActiveObjectLifecycleSpec.scala +++ b/akka-core/src/test/scala/ActiveObjectLifecycleSpec.scala @@ -5,7 +5,9 @@ import org.scalatest.{BeforeAndAfterAll, Spec} import org.scalatest.junit.JUnitRunner import org.scalatest.matchers.ShouldMatchers -import se.scalablesolutions.akka.config.ActiveObjectConfigurator +import se.scalablesolutions.akka.actor.ActiveObject._ + +import se.scalablesolutions.akka.config.{OneForOneStrategy, ActiveObjectConfigurator} import se.scalablesolutions.akka.config.JavaConfig._ /** @@ -151,5 +153,15 @@ class ActiveObjectLifecycleSpec extends Spec with ShouldMatchers with BeforeAndA assert(!obj._post) assert(obj._down) } + + it("both preRestart and postRestart methods should be invoked when an actor is restarted") { + val pojo = ActiveObject.newInstance(classOf[SimpleJavaPojo]) + val supervisor = ActiveObject.newInstance(classOf[SimpleJavaPojo]) + link(supervisor,pojo, new OneForOneStrategy(3, 2000),Array(classOf[Throwable])) + pojo.throwException + Thread.sleep(500) + pojo.pre should be(true) + pojo.post should be(true) + } } } \ No newline at end of file diff --git a/akka-core/src/test/scala/NestedTransactionalActiveObjectSpec.scala b/akka-core/src/test/scala/NestedTransactionalActiveObjectSpec.scala index 0a47d1c9d6..d40dd41654 100644 --- a/akka-core/src/test/scala/NestedTransactionalActiveObjectSpec.scala +++ b/akka-core/src/test/scala/NestedTransactionalActiveObjectSpec.scala @@ -17,18 +17,11 @@ import se.scalablesolutions.akka.config.ActiveObjectConfigurator import se.scalablesolutions.akka.config.JavaConfig._ import se.scalablesolutions.akka.actor._ -/* @RunWith(classOf[JUnitRunner]) class NestedTransactionalActiveObjectSpec extends -<<<<<<< HEAD:akka-core/src/test/scala/NestedTransactionalActiveObjectSpec.scala Spec with ShouldMatchers with BeforeAndAfterAll { -======= - Spec with - ShouldMatchers with - BeforeAndAfterAll { ->>>>>>> 38e8bea3fe6a7e9fcc9c5f353124144739bdc234:akka-core/src/test/scala/NestedTransactionalActiveObjectSpec.scala private val conf = new ActiveObjectConfigurator private var messageLog = "" @@ -164,5 +157,4 @@ class NestedTransactionalActiveObjectSpec extends nested.getRefState should equal("init") } } -} -*/ +} \ No newline at end of file