akka 介绍-Actor 基础
Actors
Actors 是一个非常轻的并发实例,基于事件驱动的异步信息处理.模式匹配是Actor处理信息的手段。它是对并发、锁、分布系统的高度抽象。你只需要关注工作流。
例子:
package akka.io
import akka.actor.ActorLogging
import akka.actor.Actor
import akka.actor.ActorSystem
import akka.actor.Props
case class Greeting(who: String)
class GreetingActor extends Actor with ActorLogging {
def receive = {
case Greeting(who) => log.info("Hello " + who)
}
}
object GreetingActor extends App {
val system = ActorSystem("MySystem");
val greeter = system.actorOf(Props[GreetingActor],name="greeter")
greeter ! Greeting("Charlie Parker")
system.shutdown
}