0
我是新來斯卡拉演員,我不知道爲什麼我的代碼不編譯。 顯然是'?'不是成員,我已經導入了akka.actors.patern._,但它仍然不起作用。 任何人都可以澄清這個黑暗的事情嗎? 謝謝!斯卡拉,圖書館akka.actor
import akka.actor.{Actor, ActorRef}
import akka.pattern._
class Registry extends Actor {
import Registry._
var registry:Map[String, Any] = Map()
def receive = {
case Lookup(name) => sender ! registry.get(name)
}
}
object Registry {
import akka.actor.{ActorSystem, Props}
case class Lookup(name: String)
// create dedicated actor infrastructure
val system = ActorSystem("myActorInfrastructure")
// create actor with a name and register it with the infrastructure
def apply(name: String) = system.actorOf(Props(new Registry()), name)
}
class Tweeter(val name: String, val regist:Registry, var followers:List[ActorRef]=List()) extends Actor{
import Tweeter._
def receive = {
case Follow(user) => {
//Here is the error
(regist!? Lookup(name)) match{
case Some(a:ActorRef) => a ! AddFollower(sender)
}
}
case AddFollower(follower) => followers = follower::followers
}
}
object Tweeter {
import akka.actor.{ActorSystem, Props}
case class Follow(user: String)
case class AddFollower(follower: ActorRef)
def apply(name: String, annuaire:Registry) = Registry.system.actorOf(Props(new Tweeter(name,annuaire)))
}
一般來說,最好使用演員調度員在上,因爲這將有一個綁定到演員系統生命週期的演員來執行期貨 - 它會關機當演員系統呢。 – johanandren