Using Akka 2.1.0 I’m sending a message from one Actor (ActorA) to another (ActorB) and expecting the returned message to be an Option[(String, String)]. ActorB has a val defined as an Enumeration and this is being returned as the second element of the Tuple result.
ActorA uses the Await.result().asInstanceOf[Option[(String, String)] pattern (I know this is bad blocking behavior, but don’t think this explains the behavior I’m seeing), and assigns the result to a val. Later when I try to pull out the second element of the Tuple result I get a scala.Enumeration#Val cannot be cast to java.lang.String cast exception. In previous versions of Akka this did not appear, and in Akka 2.1.0 I would expect the Await.result operation to blow up. Can anyone explain what is going on here?
object MyEnumeration extends Enumeration {
type Enum = Value
val Foo = Value("foo")
val Bar = Value("bar")
}
case class ActorA extends Actor {
implicit val timeout = Timeout(10000)
val result = Await.result((ActorB ? MyMessage), timeout.duration).asInstanceOf[Option[(String, String)]]
val validResult = result.get
val validType = validResult._2 // this is of type Enumeration#Val not String
}
case class ActorB extends Actor {
def myType = MyEnumeration.Foo
def receive = {
case MyMessage =>
sender ! Option((validString, myType))
}
}
It didn’t actually work in Akka 2.0.3. As I understood, you parsed received message differently.