演员如何选择另一个演员系统不同的演员?
考虑下面的场景,其中有两个actor系统,并且SparePartsProducerAActor必须监视BikeProducerActor。如何实施?
object Main extends App{
val bikeCompanyActorSystem=ActorSystem("BikeCompanyActorSystem")
val sparePartsCompanyActorSystem=ActorSystem("SparePartsActorSystem")
val bikeProduceActor=bikeCompanyActorSystem.actorOf(BikeProducerActor.props,"BikeProducer")
val sparePartsProducerAActor=sparePartsCompanyActorSystem.actorOf(SparePartsProducerAActor.props,"SparePartsProducerA")
sparePartsProducerAActor ! Common.watchBikeProducer
}
class BikeProducerActor extends Actor{
def receive={
case BikeProducerActor.produceBikes => println("Producing bikes")
case BikeProducerActor.stopProduction => println("Stopping production due to failure in model"); self ! Kill
}
}
class SparePartsProducerAActor extends Actor{
def receive={
case Common.watchBikeProducer => println("watching the bike producer");context.actorSelection("//user/BikeProducer") ! BikeProducerActor.produceBikes
}
}