选择不同演员系统中的演员

时间:2017-01-10 11:37:41

标签: scala akka actor

演员如何选择另一个演员系统不同的演员?

考虑下面的场景,其中有两个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
 }
}

0 个答案:

没有答案