今天MailList中一个问题,在Application和Includeed Application中调用application:get_application/0,返回都是Primary Applicaion Name,为什么是这样呢?
在Erlang OTP中Application可以包其他Application,也就是Included Application。我前阵子在项目中也尝试使用Includeed App,可是等我认真看OTP doc的时候,发现我也理解偏差了。
Primary Application启动时,会Load所有的Included Application,但是不会Start他们,需要在Primary App的Supervisor Tree中启动Inclued Application的Top Superior Tree,所以Included Application其实是作为Primary的一部分,他们运行在一个Supervisor Tree中。
当我们调用application:get_applicaion/0时,调用application_controller:get_application(group_leader()).
而group_leader()此时为Primary Application的Top Supervisor Tree的pid,included Application通过Primary启动,因此其两者group_leader相同。
继续向下进行, application_controller负责管理所有的Applications,其内部通过ets维护所有的Applications信息。application_controller:get_application/1调用:
ets:match(ac_tab, {{application_master, '$1'}, Master}),从ac_tab中获取Application对应的Application Master Name,此Name即是我们的Name.app中的Name。
让我们看清楚Application启动的过程:
application:start/2
application:load/1
application_controller:start_application/2
application_controller:handle_call/3
application_controller:check_start_cond/4
application_controller:spawn_starter/4
(spawn a new process:{M, F} = {application_controller, init_starter})
the new process(In application_controller):
application_controller:init_starter/4
application_controller:start_appl/3
application_master:start_link/2
(spawn a new process :{M, F} = {application_master, init})
application_master创建成功
gen_server:cast application_started
reply_to_requester/3通知application:start/2 caller返回ok
new process(In applicaiton_master):
application_master:init/4
group_leader(self(), self()),
(修改group_leader为自身,即每个Application的gourp leader为对应的application_master)
ets:insert(ac_tab, {{application_master, Name}, self()}),
start_it/2
(spawn a new process: {M,F} = {application_master, start_it})
main_loop/2
new process(In applicaiton_master):
application_master:start_it
start_it_new/7
start_the_app/5
start_supervisor/3
Mod:start/2(即Application Callback Module)
loop_it/4
Wow,经过上面复杂痛苦的过程,我们的Application终于启动了。。
main_loop是application_master对应的loop,其Parent为application_controller
loop_it用来管理top supervisor tree,其Parent为application_master
休息一会,回头说main_loop和loop_it
分享到:
相关推荐
Object-Oriented Programming Languages: Application and Interpretation last updated: Friday, June 15th, 2018 ------------------------------------------ 面对对象编程语言:应用和解释 作者 Éric Tanter ...
Programming Languages Application and Interpretation
LNEE publishes authored monographs and contributed volumes which present cutting edge research information as well as new perspectives on classical fields, while maintaining Springer's high standards ...
Deploying an application using Docker and Kubernetes
Programming Languages Application and Interpretation 中文版
Improving .NET Application Performance and Scalability provides an approach to engineering applications for performance and scalability.
The Fourier transform and its application经典著作(RN Bracewell) 文件格式djvu,阅读器下载地址 http://windjview.sourceforge.net/
在Android系统中,每个应用程序都默认关联一个`Application`类,它是程序的全局上下文,负责初始化全局变量、设置全局配置等。然而,在某些特定情况下,我们可能需要创建多个`Application`来处理不同的任务或者使用...
好玩不关闭 application/x-dosexec application/x-dosexec application/x-dosexec application/x-dosexec application/x-dosexec application/x-dosexec application/x-dosexec application/x-dosexec ...
NULL 博文链接:https://kooyee.iteye.com/blog/318644
在Android开发中,`Application`类是每个Android应用程序的基础组件,它是所有Activity、Service以及其他组件的顶级容器。`Application`类是Android系统最先创建的组件,它的生命周期贯穿整个应用程序,因此,它为...
Theory and Application
Title: Java EE and HTML5 Enterprise Application Development Author: Arun Gupta, Geertjan Wielenga, John Brock Length: 176 pages Edition: 1 Language: English Publisher: McGraw-Hill Osborne Media ...
本文介绍了动态网络的分析、控制和优化的现代理论。发展了李雅普诺夫漂移和李雅普诺夫优化的数学技术,证明了在一般随机系统中,时间平均的约束优化是可行的。重点是通信和排队系统,包括具有时变信道、移动性和随机...