AKKA笔记1
读spark源码,AKKA确实有必要单独研究一下,用在java的项目上也不错
1.maven构建一个akka的java项目,只需要添加一个dependencies
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.10</artifactId>
<version>2.3.14</version>
</dependency>
2. 第一个java AKKA消息驱动程序
1)构建ActorSystem,发送给自定义的MasterActor
import scala.concurrent.Future;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.apply.actor.MasterActor;
import akka.pattern.Patterns;
public class MainTest {
public static void main(String[] args) {
ActorSystem as = ActorSystem.create("test");
ActorRef master = as.actorOf(Props.create(MasterActor.class), "master");
master.tell("start", master);
as.awaitTermination();
}
}
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.actor.UntypedActor;
public class MasterActor extends UntypedActor {
@Override
public void onReceive(Object msg) throws Exception {
System.out.println(""+this.getClass().getSimpleName()+"::sender:"+this.getSender()+" ::self:"+this.getSelf());
}
}
运行结果:
上一篇: SQLLineage.com(SQL优化:列裁剪)
下一篇: socket 通讯编程手册