Reputation: 26008
Here is a part of code involving akka:
abstract class AkkaBaseClass[T <: AkkaClass1, U <: Loger] extends Actor {
protected val val1 = context.actorOf(Props[T])
protected val val2 = context.actorOf(Props[U])
def receive = {
case "test" => {
implicit val timeout = Timeout(Config.timeout seconds)
val future = val1 ? "request"
val result = Await.result(future, timeout.duration).asInstanceOf[List[ActorRef]]
sender ! result
}
case "log" => val2 ! "log"
}
class AkkaClass1 extends Actor { .... }
trait Loger extends Actor { ..... }
There are 2 errors:
No ClassTag available for T and No ClassTag available for U
But T
and U
are not arrays. What do I do about that?
Upvotes: 2
Views: 3605
Reputation: 26579
Please do not block on Futures if not required:
Here's a solution to your problem.
abstract class AkkaBaseClass[T <: AkkaClass1 : ClassTag, U <: Loger : ClassTag] extends Actor {
protected val val1 = context.actorOf(Props[T])
protected val val2 = context.actorOf(Props[U])
def receive = {
case "test" => val1 forward "request"
case "log" => val2 ! "log"
}
class AkkaClass1 extends Actor { .... }
trait Loger extends Actor { ..... }
Upvotes: 3
Reputation: 297155
Though you omitted the place where the errors took place, I'm guessing they are happening at Props
. It is probably the case that Props
take an implicit ClassTag
as a parameter, particularly since it doesn't take any other parameter. And though a ClassTag
is used by array creation, it can also be used for other things, such as getting a Class
that can then be used to instantiate classes by reflection, or as a reference when comparing instances received.
To solve it, declare AkkaBaseClass
like this:
import scala.reflect.ClassTag
abstract class AkkaBaseClass[T <: AkkaClass1 : ClassTag, U <: Loger : ClassTag] extends Actor {
Upvotes: 8