第96讲:Akka第一个案例动手实战main方法实现中ActorSystem等代码详解学习笔记
来源:互联网 发布:中原g7 知乎 编辑:程序博客网 时间:2024/06/05 09:02
第96讲:Akka第一个案例动手实战main方法实现中ActorSystem等代码详解学习笔记
本讲讲解main方法的具体实现。
1.ActorSystem : 通过ActorSystem.create(name: String)创建ActorSystem
2.main入口代码实现详解
ActorSystem可以看作为container级别(容器型)的内容。其中有很多Actor实例。
/**
* An actor system is a hierarchical group of actors which share common
* configuration, e.g. dispatchers, deployments, remote capabilities and
* addresses. It is also the entry point for createing or looking up actors.
* 在几百台机器的分布式集群上找到其他机器上的actor时,
* 就需要用查找的方式,这就需要ActorSystem.
*/
abstract class ActorSystem extends ActorRefFactory {
import ActorSystem._
def name: String
def settings: Settings
def logConfiguration(): Unit
def create(): ActorSystem = apply()
/**
* Creates a new ActorSystem with the specified name ,
* obtains the current ClassLoader by first inspecting the current threads' getContextClassLoader,
* then tries to walk the stack to find the callers class Loader, then falls back to the ClassLoader
* associated with the ActorSystem class.
* Then it loads the default reference configurationg using the ClassLoader.
*/
def create(name: String): ActorSystem = apply(name)
/**
* Creates a new ActorSystem with the name "default", and the specified Config, then
* obtains the current ClassLoader by first inspecting the current threads' getContextClassLoader,
* then tries to walk the stack to find the callers class Loader, then falls back to the ClassLoader
* associated with the ActorSystem class.
*/
def create(name: String, config: Config): ActorSystem = apply(name, config)
/**
* Creates a new ActorSystem with the name "default", the specified Config, and specified ClassLoader
*/
def create(name: String, config: Config. classLoader: ClassLoader):ActorSystem = apply(name,config,classLoader)
public class HelloAkka {
public static void main(String[] args) throws Exception {
ActorSystem _system = ActorSystem.create("HelloAkka");
ActorRef master = _system.actorOf(new Props(MasterActor.class),"master");
master.tell("Hi! My name is Rocky. I'm so so so so happy to ne here. ");
master.tell("Today, I'm going to read a news article for you. ");
master.tell("I hope I hope you'll like it.")
//
Thread.sleep(500); //现在暂不考虑500mm是否足够。
master.tell(new Result()); //
Thread.sleep(500);
_system.shutdown(); //关闭ActorSystem,这是销毁和资源回收的部分。
}
}
通过new Props(MasterActor.class)创建masterActor后
通过tell的方式给masterActor发信息。
masterActor在onReceive中就会收到信息。
masterActor处理信息的方式是把信息发给mapActor。
消息发送完后睡眠一段时间后再发消息给masterActor。
MasterActor再把消息发给AggregateActor。
AggregateActor收到信息时会打印finalReduceMap。
也可以把结果发回给masterActor。
这是从java角度编写akka代码的完整过程。
下一讲从scala角度看如何用akka框架。
以上内容是从王家林老师DT大数据课程第96讲的学习笔记。
DT大数据微信公众账号:DT_Spark
王家林老师QQ:1740415547
王家林老师微信号:18610086859
第94讲视频网站地址:
17173视频:http://v.17173.com/v_102_608/MjgxNDIwMTc.html
酷6视频:http://v.ku6.com/show/bVwNIlcmDvkr4j3xantZHw...html
56视频:http://www.56.com/u89/v_MTM4NzE2NTkw.html
DT大数据梦工厂1至101集scala的所有视频、PPT和代码在百度云盘的链接:http://pan.baidu.com/share/home?uk=4013289088#category/type=0&qq-pf-to=pcqq.group
- 第96讲:Akka第一个案例动手实战main方法实现中ActorSystem等代码详解学习笔记
- 第94讲:Akka第一个案例动手实战MapActor、ReduceActor、AggregateActor代码详解学习笔记
- 第95讲:Akka第一个案例动手实战MasterActor代码详解学习笔记
- 第92讲:Akka第一个案例动手实战开发环境的搭建,第93讲:Akka第一个案例动手实战开发消息实体类学习笔记
- 第91讲:Akka第一个案例动手实战架构设计学习笔记
- 第91讲:Akka第一个案例动手实战架构设计
- 第92讲:Akka第一个案例动手实战开发环境的搭建
- 第93讲(HelloActor整体介绍):Akka第一个案例动手实战开发消息实体类
- 第97讲:使用SBT开发Akka第一个案例环境搭建详解学习笔记
- 第100讲:使用SBT开发Akka第一个案例源码解析消息、main入口、MasterActor学习笔记
- 第99讲:手动Artifacts打包并运行SBT开发Akka第一个案例学习笔记
- 第107讲:Akka中的Future使用代码实战详解学习笔记
- 第101讲:使用SBT开发Akka第一个案例源码解析MapActor、ReduceActor、AggregateActor学习笔记
- Akka学习笔记:ActorSystem(配置)
- Akka学习笔记:ActorSystem(调度)
- 第000讲-第006讲 从1000个代码案例中学习人工智能和大数据实战
- 第007讲-第011讲 从1000个代码案例中学习人工智能和大数据实战
- 第012讲-第013讲 从1000个代码案例中学习人工智能和大数据实战
- 项目风险管理
- poj 1676 What time is it?(经典模拟)
- 学习java与思维导图
- NYOJ--102--次方求模
- 程序员读书和练习的方法(个人观点)
- 第96讲:Akka第一个案例动手实战main方法实现中ActorSystem等代码详解学习笔记
- iOS开发:通讯录之联系人添加、移动、删除
- AdaultBird--我的黑马程序员之路!Chapter3---多线程同步,同步唤醒和等待,守护线程,String类,基本数据类型包装类,集合框架中的List和Set
- 欢迎使用CSDN-markdown编辑器
- populate next right pointer in each node
- 流水笔记--2015-9-9
- new和二级指针
- 正则表达式。。。
- AngularJs 在ng-repeat中动态使用ng-model进行双向数据绑定