Fixed #675 : preStart() is called twice when creating new instance of TypedActor
This commit is contained in:
parent
48d06de589
commit
12dfba899f
2 changed files with 52 additions and 4 deletions
|
|
@ -445,9 +445,8 @@ object TypedActor {
|
|||
* @param intfClass interface the typed actor implements
|
||||
* @param targetClass implementation class of the typed actor
|
||||
*/
|
||||
def newInstance[T](intfClass: Class[T], targetClass: Class[_]): T = {
|
||||
def newInstance[T](intfClass: Class[T], targetClass: Class[_]): T =
|
||||
newInstance(intfClass, targetClass, TypedActorConfiguration())
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for typed actor.
|
||||
|
|
@ -759,7 +758,6 @@ object TypedActor {
|
|||
val typedActor =
|
||||
if (instance.isInstanceOf[TypedActor]) instance.asInstanceOf[TypedActor]
|
||||
else throw new IllegalArgumentException("Actor [" + targetClass.getName + "] is not a sub class of 'TypedActor'")
|
||||
typedActor.preStart
|
||||
typedActor
|
||||
}
|
||||
|
||||
|
|
@ -768,7 +766,6 @@ object TypedActor {
|
|||
val typedActor =
|
||||
if (instance.isInstanceOf[TypedActor]) instance.asInstanceOf[TypedActor]
|
||||
else throw new IllegalArgumentException("Actor [" + instance.getClass.getName + "] is not a sub class of 'TypedActor'")
|
||||
typedActor.preStart
|
||||
typedActor
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
|
||||
*/
|
||||
|
||||
package akka.actor
|
||||
|
||||
import org.scalatest.Spec
|
||||
import org.scalatest.Assertions
|
||||
import org.scalatest.matchers.ShouldMatchers
|
||||
import org.scalatest.BeforeAndAfterEach
|
||||
import org.scalatest.junit.JUnitRunner
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import Issue675Spec._
|
||||
|
||||
|
||||
object Issue675Spec {
|
||||
var l = collection.mutable.ListBuffer.empty[String]
|
||||
|
||||
trait RegistrationService {
|
||||
def register(user: String, cred: String): Unit
|
||||
}
|
||||
|
||||
class RegistrationServiceImpl extends TypedActor with RegistrationService {
|
||||
def register(user: String, cred: String): Unit = {}
|
||||
|
||||
override def preStart() {
|
||||
l += "RegistrationServiceImpl.preStart() called"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class Issue675Spec extends
|
||||
Spec with
|
||||
ShouldMatchers with
|
||||
BeforeAndAfterEach {
|
||||
|
||||
override def afterEach() {
|
||||
Actor.registry.shutdownAll
|
||||
}
|
||||
|
||||
describe("TypedActor preStart method") {
|
||||
it("should be invoked once") {
|
||||
import Issue675Spec._
|
||||
val simplePojo = TypedActor.newInstance(classOf[RegistrationService], classOf[RegistrationServiceImpl])
|
||||
l.size should equal(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue