Fixed bug in Active Object restart, had no default life-cycle defined + added tests

This commit is contained in:
Jonas Bonér 2010-07-14 14:38:56 +02:00
parent 2541176559
commit 1f09e17d74
4 changed files with 25 additions and 17 deletions

View file

@ -687,8 +687,6 @@ private[akka] class Dispatcher(transactionalRequired: Boolean,
private var context: Option[ActiveObjectContext] = None private var context: Option[ActiveObjectContext] = None
private var targetClass:Class[_] = _ private var targetClass:Class[_] = _
def this(transactionalRequired: Boolean) = this(transactionalRequired,None) def this(transactionalRequired: Boolean) = this(transactionalRequired,None)
private[actor] def initialize(targetClass: Class[_], targetInstance: AnyRef, ctx: Option[ActiveObjectContext]) = { private[actor] def initialize(targetClass: Class[_], targetInstance: AnyRef, ctx: Option[ActiveObjectContext]) = {
@ -701,6 +699,8 @@ private[akka] class Dispatcher(transactionalRequired: Boolean,
context = ctx context = ctx
val methods = targetInstance.getClass.getDeclaredMethods.toList val methods = targetInstance.getClass.getDeclaredMethods.toList
if (self.lifeCycle.isEmpty) self.lifeCycle = Some(LifeCycle(Permanent))
// See if we have any config define restart callbacks // See if we have any config define restart callbacks
restartCallbacks match { restartCallbacks match {
case None => {} case None => {}

View file

@ -215,11 +215,15 @@ class RemoteServer extends Logging {
def shutdown = synchronized { def shutdown = synchronized {
if (_isRunning) { if (_isRunning) {
RemoteServer.unregister(hostname, port) try {
openChannels.disconnect RemoteServer.unregister(hostname, port)
openChannels.close.awaitUninterruptibly openChannels.disconnect
bootstrap.releaseExternalResources openChannels.close.awaitUninterruptibly
Cluster.deregisterLocalNode(hostname, port) 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")
}
} }
} }

View file

@ -5,7 +5,9 @@ import org.scalatest.{BeforeAndAfterAll, Spec}
import org.scalatest.junit.JUnitRunner import org.scalatest.junit.JUnitRunner
import org.scalatest.matchers.ShouldMatchers 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._ import se.scalablesolutions.akka.config.JavaConfig._
/** /**
@ -151,5 +153,15 @@ class ActiveObjectLifecycleSpec extends Spec with ShouldMatchers with BeforeAndA
assert(!obj._post) assert(!obj._post)
assert(obj._down) 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)
}
} }
} }

View file

@ -17,18 +17,11 @@ import se.scalablesolutions.akka.config.ActiveObjectConfigurator
import se.scalablesolutions.akka.config.JavaConfig._ import se.scalablesolutions.akka.config.JavaConfig._
import se.scalablesolutions.akka.actor._ import se.scalablesolutions.akka.actor._
/*
@RunWith(classOf[JUnitRunner]) @RunWith(classOf[JUnitRunner])
class NestedTransactionalActiveObjectSpec extends class NestedTransactionalActiveObjectSpec extends
<<<<<<< HEAD:akka-core/src/test/scala/NestedTransactionalActiveObjectSpec.scala
Spec with Spec with
ShouldMatchers with ShouldMatchers with
BeforeAndAfterAll { BeforeAndAfterAll {
=======
Spec with
ShouldMatchers with
BeforeAndAfterAll {
>>>>>>> 38e8bea3fe6a7e9fcc9c5f353124144739bdc234:akka-core/src/test/scala/NestedTransactionalActiveObjectSpec.scala
private val conf = new ActiveObjectConfigurator private val conf = new ActiveObjectConfigurator
private var messageLog = "" private var messageLog = ""
@ -164,5 +157,4 @@ class NestedTransactionalActiveObjectSpec extends
nested.getRefState should equal("init") nested.getRefState should equal("init")
} }
} }
} }
*/