Hi,
In my application, I'd like to broadcast a time unit every 2 sec to all actors instances of Worker. The time unit is sent by the master to all the worker
I am trying to send a broadcast message to set of workers by the master actor, but it doesn't work with me. I attach my test code here. There is a compile error in the line
router ! Broadcast("any message")
"Error: value is not a member of akka.routing.Router" Could anyone tell me what is the problem here.
import akka.actor._
import akka.routing.{ ActorRefRoutee, RoundRobinRoutingLogic, Router }
import akka.routing.Broadcast
import akka.routing.Router
import akka.routing.RouterActor
object Messages{
object Work
object Terminated
}
object MainRouterDriver extends App {
import Messages._
// an actor needs an ActorSystem
val system = ActorSystem("HelloSystem")
// create and start the actor
val routingMaster = system.actorOf(Props[Master], name = "helloactor")
// send the actor two messages
routingMaster ! Work
}
class Worker extends Actor{
def receive = {
case _ =>
println("Hi I am a Worker")
}
}
class Master extends Actor {
var router = {
val routees = Vector.fill(5) {
val r = context.actorOf(Props[Worker])
context watch r
ActorRefRoutee(r)
}
akka.routing.Router(RoundRobinRoutingLogic(), routees)
}
def receive = {
case Work =>
router ! Broadcast("any message")
}
}