大数据系列修炼-Scala课程95
来源:互联网 发布:印度冷战作用知乎 编辑:程序博客网 时间:2024/05/21 06:53
大数据系列修炼-Scala课程95
核心内容:
1、Akka第一个案例动手实战MasterActor代码详解
1、Akka第一个案例动手实战MasterActor代码详解
1>MasterActor主要的两个作用:
第一:将MapActor需要处理的内容字符串信息发送给MapActor;
第二:实例化MapActor、ReduceActor、AggregateActor,但是因为MasterActor自身也是Actor,所以不能直接创建
这三个Actor,这三个Actor实际上是由Akka系统创建的。
2>UntypedActor通过其onReceive方法接受其它Actor发送过来的消息信息。
相应代码:
MasterActor代码:
package akka.dt.app.java.actors;import akka.actor.ActorRef;import akka.actor.Props;import akka.actor.UntypedActor;import akka.actor.UntypedActorFactory;import akka.dt.app.java.messages.Result;public class MasterActor extends UntypedActor{ private ActorRef aggregateActor = getContext().actorOf( new Props(AggregateActor.class),"aggregate"); private ActorRef reduceActor = getContext().actorOf( new Props(new UntypedActorFactory() { public UntypedActor create(){ return new ReduceActor(aggregateActor); } }),"reduce"); private ActorRef mapActor = getContext().actorOf( new Props(new UntypedActorFactory() { public UntypedActor create(){ return new MapActor(reduceActor); } }),"map"); @Override public void onReceive(Object message) throws Exception{ if(message instanceof String){ mapActor.tell(message); }else if(message instanceof Result){ aggregateActor.tell(message); }else unhandled(message); }}
如有问题,欢迎留言指正!
0 0
- 大数据系列修炼-Scala课程95
- 大数据系列修炼-Scala课程01
- 大数据系列修炼-Scala课程02
- 大数据系列修炼-Scala课程03
- 大数据系列修炼-Scala课程04
- 大数据系列修炼-Scala课程05
- 大数据系列修炼-Scala课程06
- 大数据系列修炼-Scala课程07
- 大数据系列修炼-Scala课程08
- 大数据系列修炼-Scala课程09
- 大数据系列修炼-Scala课程10
- 大数据系列修炼-Scala课程11
- 大数据系列修炼-Scala课程12
- 大数据系列修炼-Scala课程15
- 大数据系列修炼-Scala课程17
- 大数据系列修炼-Scala课程18
- 大数据系列修炼-Scala课程19
- 大数据系列修炼-Scala课程20
- No.04 Xcode(7.x) 蓝牙
- 利用c语言实现简单的通信录
- 大数据系列修炼-Scala课程93
- fzu 2038 Another Postman Problem 递归
- 大数据系列修炼-Scala课程94
- 大数据系列修炼-Scala课程95
- 持久化对象有以下几种状态:
- C++ 运算符重载讲解与经典实例
- 线程池-isShutdown和isTerminated
- 《大话设计模式》--- 第23个:命令模式
- 正则表达式详解
- 黑盒测试、白盒测试、灰盒测试之间区别
- Android Intent学习
- ios基础篇—图标尺寸选择 AppIcon&LaunchImage