The Artima Developer Community
Sponsored Link

Akka Concurrency Forum
ClassCastException in Altimer after refactoring in section 6.2

4 replies on 1 page. Most recent reply: Nov 16, 2012 5:13 AM by Eric Loots

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Shing Hing Man

Posts: 9
Nickname: 84423
Registered: Oct, 2012

ClassCastException in Altimer after refactoring in section 6.2 Posted: Nov 5, 2012 4:11 AM
Reply to this message Reply
Advertisement
I am using Scala 2.9.2 and Akka 2.0.2.

After I have done the refactoring described in Section 6.2,
I get the following ClassCastException in Altimeter when I run Avionics:

java.lang.ClassCastException: net.sf.akka.avionics.Altimeter cannot be cast to net.sf.akka.avionics.EventSource
at net.sf.akka.avionics.Altimeter.receive(Altimeter.scala:74)
at akka.actor.Actor$class.$init$(Actor.scala:343)
at net.sf.akka.avionics.Altimeter.<init>(Altimeter.scala:21)


Line 74 in my Altimeter is
def receive = eventSourceReceive orElse altimeterReceive

I fixed the above ClassCastException by replacing

val altimeter = context.actorOf(Props[Altimeter])

with
val altimeter = context.actorOf(Props(Altimeter()))

in the class Plane.


Shing


Derek Wyatt

Posts: 69
Nickname: dwyatt
Registered: Oct, 2012

Re: ClassCastException in Altimer after refactoring in section 6.2 Posted: Nov 6, 2012 4:42 PM
Reply to this message Reply
Yeah, sorry about that. I didn't include the change in the book, but we'll get it in the next release.

I would advise against using the versions you're using though... there's been a LOT of change in 2.10 and 2.1. If it's possible to upgrade, please do.

Andreas Gies

Posts: 15
Nickname: 84653
Registered: Nov, 2012

Re: ClassCastException in Altimer after refactoring in section 6.2 Posted: Nov 14, 2012 4:32 PM
Reply to this message Reply
I was running into the same issue and have taken the advice to go to Scala 2.10.0-RC and akka 2.1.

Codewise I think I am now in line with what is in the book except for the Avionics class, where the Duration construction did not work in my code. Perhaps I am just missing the point. The time settings on my end are now:

implicit val timeOut = Timeout(5000);

or

system.scheduler.scheduleOnce(FiniteDuration(1, "s"))

Also, the package scala.concurrent.util.duration seems to have vanished. Perhaps thats because its a newer RC of Scala 2.10.


As a side note, I am using IntelliJ as my IDE and had everything up and running with 2.9.2 based Scala. Switching to 2.10-RC2 killed my SBT plugin and I finally reverted to maven. I think it's probably me not getting the entire picture of how things play together.

If you are interested, I can share the maven settings in case other IntelliJ users have the same problem.


Great book, btw. I really like the writing style.

Andreas

TC Chung

Posts: 1
Nickname: 84551
Registered: Nov, 2012

Re: ClassCastException in Altimer after refactoring in section 6.2 Posted: Nov 14, 2012 9:55 PM
Reply to this message Reply
Use this build.sbt to get the latest versions in Scala, Akka, and ScalaTest


name := "AkkaInvestigation"

version := "0.1"

scalaVersion := "2.10.0-RC2"

resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"

resolvers += "OSS Sonatype Public" at "https://oss.sonatype.org/content/groups/public/"

libraryDependencies ++= Seq(
"org.scalatest" % "scalatest_2.10.0-RC2" % "2.0.M4-B2" % "test",
"com.typesafe.akka" %% "akka-testkit" % "2.1.0-RC2" cross CrossVersion.full,
"com.typesafe.akka" %% "akka-actor" % "2.1.0-RC2" cross CrossVersion.full
)


As for the duration package, I believe it has been moved to


import scala.concurrent.duration._

Eric Loots

Posts: 5
Nickname: 84502
Registered: Nov, 2012

Re: ClassCastException in Altimer after refactoring in section 6.2 Posted: Nov 16, 2012 5:13 AM
Reply to this message Reply
Thanks TC, that really helped!

Flat View: This topic has 4 replies on 1 page
Topic: Ch 14: Testing using multiple JVMs versus mulitple ActorSystems in one JVM Previous Topic   Next Topic Topic: I'll be off the air for a few days

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use