Don't allow two different actors (different types) to share the same work stealing dispatcher. Added unit test.

This commit is contained in:
Jan Van Besien 2010-03-19 13:49:49 +01:00
parent 84b7566d34
commit 673bb2b8bb
2 changed files with 43 additions and 2 deletions

View file

@ -161,6 +161,7 @@ class ExecutorBasedEventDrivenWorkStealingDispatcher(_name: String) extends Mess
private[akka] def init = withNewThreadPoolWithLinkedBlockingQueueWithUnboundedCapacity.buildThreadPool
override def register(actor: Actor) = {
verifyActorsAreOfSameType(actor)
super.register(actor)
}
@ -170,8 +171,10 @@ class ExecutorBasedEventDrivenWorkStealingDispatcher(_name: String) extends Mess
actorType = Some(newActor.getClass)
}
case Some(aType) => {
if (aType != newActor.getClass) // TODO: is assignable from ?!
throw new IllegalStateException(String.format("Can't register actor %s in a work stealing dispatcher which already knows actors of type %s", newActor, aType))
if (aType != newActor.getClass)
throw new IllegalStateException(
String.format("Can't register actor %s in a work stealing dispatcher which already knows actors of type %s",
newActor, aType))
}
}

View file

@ -58,4 +58,42 @@ class ExecutorBasedEventDrivenWorkStealingDispatcherTest extends JUnitSuite with
}
})
@Test def canNotUseActorsOfDifferentTypesInSameDispatcher:Unit = {
val first = new FirstActor
val second = new SecondActor
first.start
intercept[IllegalStateException] {
second.start
}
}
class FirstActor extends Actor {
messageDispatcher = poolDispatcher
def receive = {case _ => {}}
}
class SecondActor extends Actor {
messageDispatcher = poolDispatcher
def receive = {case _ => {}}
}
@Test def canNotUseActorsOfDifferentSubTypesInSameDispatcher:Unit = {
val parent = new ParentActor
val child = new ChildActor
parent.start
intercept[IllegalStateException] {
child.start
}
}
class ParentActor extends Actor {
messageDispatcher = poolDispatcher
def receive = {case _ => {}}
}
class ChildActor extends ParentActor {
}
}