- 浏览: 571953 次
- 性别:
- 来自: 广州杭州
文章分类
最新评论
-
bohc:
谢谢,搞了两天了,现在才算是找到问题所在,解决了。
文件在使用FileChannel.map后不能被删除(Windows上) -
zhang0000jun:
在jdk1.8中执行正好和楼主的结果相反,请指教
从Java视角理解CPU缓存(CPU Cache) -
在世界的中心呼喚愛:
forenroll 写道请问楼主的那个分析工具cachemis ...
从Java视角理解CPU缓存(CPU Cache) -
xgj1988:
我这里打出的结果是: 0 L1-dcache-load-mis ...
从Java视角理解CPU缓存(CPU Cache) -
thebye85:
请教下大神,为什么频繁的park会导致大量context sw ...
从Java视角理解CPU上下文切换(Context Switch)
7 Applications
This chapter should be read in conjunction with app(4)
and application(3)
.
7.1 Application Concept
When we have written code implementing some specific functionality, we might want to make the code into an application, that is a component that can be started and stopped as a unit, and which can be re-used in other systems as well.
To do this, we create an application callback module, where we describe how the application should be started and stopped.
Then, an application specification is needed, which is put in an application resource file. Among other things, we specify which modules the application consists of and the name of the callback module.
If we use systools
, the Erlang/OTP tools for packaging code (see Releases), the code for each application is placed in a separate directory following a pre-defined directory structure.
7.2 Application Callback Module
How to start and stop the code for the application, i.e. the supervision tree, is described by two callback functions:
start(StartType, StartArgs) -> {ok, Pid} | {ok, Pid, State}
stop(State)
start
is called when starting the application and should create the supervision tree by starting the top supervisor. It is expected to return the pid of the top supervisor and an optional term State
, which defaults to []. This term is passed as-is to stop
.
StartType
is usually the atom normal
. It has other values only in the case of a takeover or failover, see Distributed Applications. StartArgs
is defined by the key mod
in the application resource file file.
stop/1
is called after the application has been stopped and should do any necessary cleaning up. Note that the actual stopping of the application, that is the shutdown of the supervision tree, is handled automatically as described in Starting and Stopping Applications.
Example of an application callback module for packaging the supervision tree from the Supervisor chapter:
-module(ch_app).
-behaviour(application).
-export([start/2, stop/1]).
start(_Type, _Args) ->
ch_sup:start_link().
stop(_State) ->
ok.
A library application, which can not be started or stopped, does not need any application callback module.<!----><!---->
7.3 Application Resource File
To define an application, we create an application specification which is put in an application resource file, or in short .app
file:
{application, Application, [Opt1,...,OptN]}.
Application
, an atom, is the name of the application. The file must be named Application.app
.
Application
, 一个原子, 是此应用的名称. 文件名必须为Application.app
.
Each Opt
is a tuple {Key, Value}
which define a certain property of the application. All keys are optional. Default values are used for any omitted keys.
The contents of a minimal .app
file for a library application libapp
looks like this:
{application, libapp, []}.
The contents of a minimal .app
file ch_app.app
for a supervision tree application like ch_app
looks like this:
{application, ch_app,
[{mod, {ch_app,[]}}]}.
The key mod
defines the callback module and start argument of the application, in this case ch_app
and [], respectively. This means that
mod
键定义了应用的回调模块和start 参数, 在这儿分别是ch_app
和 []。它等同于
代码
- ch_app:start(normal, [])
will be called when the application should be started and
在应用启动时被调用且
代码
- ch_app:stop([])
will be called when the application has been stopped.
在应用停止时被调用.
When using systools
, the Erlang/OTP tools for packaging code (see Releases), the keys description
, vsn
, modules
, registered
and applications
should also be specified:
{application, ch_app,
[{description, "Channel allocator"},
{vsn, "1"},
{modules, [ch_app, ch_sup, ch3]},
{registered, [ch3]},
{applications, [kernel, stdlib, sasl]},
{mod, {ch_app,[]}}
]}.
description
vsn
modules
systools
uses this list when generating boot scripts and tar files. A module must be defined in one and only one application. Defaults to []. registered
systools
uses this list to detect name clashes between applications. Defaults to []. applications
systools
uses this list to generate correct boot scripts. Defaults to [], but note that all applications have dependencies to at least kernel
and stdlib
. The syntax and contents of of the application resource file are described in detail in app(4)
.<!----><!---->
7.4 Directory Structure
When packaging code using systools
, the code for each application is placed in a separate directory lib/Application-Vsn
, where Vsn
is the version number.
This may be useful to know, even if systools
is not used, since Erlang/OTP itself is packaged according to the OTP principles and thus comes with this directory structure. The code server (see code(3)
) will automatically use code from the directory with the highest version number, if there are more than one version of an application present.
The application directory structure can of course be used in the development environment as well. The version number may then be omitted from the name.
The application directory have the following sub-directories:
-
src
-
ebin
-
priv
-
include
src
ebin
beam
files. The .app
file is also placed here. priv
code:priv_dir/1
should be used to access this directory. include
7.5 Application Controller
When an Erlang runtime system is started, a number of processes are started as part of the Kernel application. One of these processes is the application controller process, registered as application_controller
.
All operations on applications are coordinated by the application controller. It is interfaced through the functions in the module application
, see application(3)
. In particular, applications can be loaded, unloaded, started and stopped.<!---->
7.6 Loading and Unloading Applications
Before an application can be started, it must be loaded. The application controller reads and stores the information from the .app
file.
1> application:load(ch_app).
ok
2> application:loaded_applications().
[{kernel,"ERTS CXC 138 10","2.8.1.3"},
{stdlib,"ERTS CXC 138 10","1.11.4.3"},
{ch_app,"Channel allocator","1"}]
An application that has been stopped, or has never been started, can be unloaded. The information about the application is erased from the internal database of the application controller.
3> application:unload(ch_app).
ok
4> application:loaded_applications().
[{kernel,"ERTS CXC 138 10","2.8.1.3"},
{stdlib,"ERTS CXC 138 10","1.11.4.3"}]
Loading/unloading an application does not load/unload the code used by the application. Code loading is done the usual way. |
7.7 Starting and Stopping Applications
An application is started by calling:
5> application:start(ch_app).
ok
6> application:which_applications().
[{kernel,"ERTS CXC 138 10","2.8.1.3"},
{stdlib,"ERTS CXC 138 10","1.11.4.3"},
{ch_app,"Channel allocator","1"}]
If the application is not already loaded, the application controller will first load it using application:load/1
. It will check the value of the applications
key, to ensure that all applications that should be started before this application are running.<!---->
The application controller then creates an application master for the application. The application master is the group leader of all the processes in the application. The application master starts the application by calling the application callback function start/2
in the module, and with the start argument, defined by the mod
key in the .app
file.
An application is stopped, but not unloaded, by calling:
7> application:stop(ch_app).
ok
The application master stops the application by telling the top supervisor to shutdown. The top supervisor tells all its child processes to shutdown etc. and the entire tree is terminated in reversed start order. The application master then calls the application callback function stop/1
in the module defined by the mod
key.<!---->
7.8 Configuring an Application
An application can be configured using configuration parameters. These are a list of {Par, Val}
tuples specified by a key env
in the .app
file.
{application, ch_app,
[{description, "Channel allocator"},
{vsn, "1"},
{modules, [ch_app, ch_sup, ch3]},
{registered, [ch3]},
{applications, [kernel, stdlib, sasl]},
{mod, {ch_app,[]}},
{env, [{file, "/usr/local/log"}]}
]}.
Par
should be an atom, Val
is any term. The application can retrieve the value of a configuration parameter by calling application:get_env(App, Par)
or a number of similar functions, see application(3)
.
Example:
% erl
Erlang (BEAM) emulator version 5.2.3.6 [hipe] [threads:0]
Eshell V5.2.3.6 (abort with ^G)
1> application:start(ch_app).
ok
2> application:get_env(ch_app, file).
{ok,"/usr/local/log"}
The values in the .app
file can be overridden by values in a system configuration file. This is a file which contains configuration parameters for relevant applications:
[{Application1, [{Par11,Val11},...]},
...,
{ApplicationN, [{ParN1,ValN1},...]}].
The system configuration should be called Name.config
and Erlang should be started with the command line argument -config Name
. See config(4)
for more information.
Example: A file test.config
is created with the following contents:
[{ch_app, [{file, "testlog"}]}].
The value of file
will override the value of file
as defined in the .app
file:
% erl -config test
Erlang (BEAM) emulator version 5.2.3.6 [hipe] [threads:0]
Eshell V5.2.3.6 (abort with ^G)
1> application:start(ch_app).
ok
2> application:get_env(ch_app, file).
{ok,"testlog"}
If release handling is used, exactly one system configuration file should be used and that file should be called sys.config
The values in the .app
file, as well as the values in a system configuration file, can be overridden directly from the command line:
% erl -ApplName Par1 Val1 ... ParN ValN
Example:
% erl -ch_app file '"testlog"'<!---->
Erlang (BEAM) emulator version 5.2.3.6 [hipe] [threads:0]
Eshell V5.2.3.6 (abort with ^G)
1> application:start(ch_app).
ok
2> application:get_env(ch_app, file).
{ok,"testlog"}
7.9 Application Start Types
A start type is defined when starting the application:
application:start(Application, Type)
application:start(Application)
is the same as calling application:start(Application, temporary)
. The type can also be permanent
or transient
:
- If a permanent application terminates, all other applications and the runtime system are also terminated.
- If a transient application terminates with reason
normal
, this is reported but no other applications are terminated. If a transient application terminates abnormally, that is with any other reason thannormal
, all other applications and the runtime system are also terminated. - If a temporary application terminates, this is reported but no other applications are terminated.
It is always possible to stop an application explicitly by calling application:stop/1
. Regardless of the mode, no other applications will be affected.
Note that transient mode is of little practical use, since when a supervision tree terminates, the reason is set to shutdown
, not normal
.
发表评论
-
ubuntu安装otp R11B 的一些记录
2007-11-16 12:30 2781新的ubuntu系统会缺少一些工具 和lib. 用apt-ge ... -
emulator调试日志: driver篇
2007-10-08 16:35 2273--------- driver篇 ------------- ... -
修正Programming Erlang中linked driver实例的小问题
2007-10-08 14:50 2445也许很多人碰上过, 用example1_lid:sta ... -
emulator调试日志: port篇
2007-10-06 16:14 2371------------------ port 篇 ----- ... -
supervisor一小技巧
2007-09-04 13:20 1777simple_one_for_one可以让supervisor ... -
gen_server
2007-08-29 21:52 1898State用来存数据, 任何erlang term都行 ge ... -
application
2007-08-29 02:01 1717用pman 可以看出application controlle ... -
epmd源码学习
2007-07-26 10:14 1998注: 此处节点是指分布式中分布在各终端的点, 而结点是指存在数 ... -
Tracing和dbg
2007-07-15 21:49 2532代码不必用特殊的标记(比如debug_info)来编译,也可以 ... -
ets,dets与大数据存储
2007-07-15 12:49 4931ets与dets都是用来存大数据的机制 ets是Erl ... -
用telnet来与ejabberd交互
2007-07-11 15:41 3195看了一篇文章,觉得用telnet来调试ejabberd也是一种 ... -
ejabberd管理页面和客户端
2007-07-11 00:23 9721转战到97机器。在ejabber.config加上这么一行. ... -
ejabberd在linux平台的安装与配置
2007-07-05 21:17 11919这些天捣鼓了下ejabberd,准备研究它的代码,做为榜样~ ... -
mnesia相关笔记
2007-06-29 12:17 2310当前版本OTP 5.5的mensia建表的表名可以和记录名不一 ... -
erlang网络编程的几个性能调优和注意点
2007-06-26 09:56 17848前些天给echo_server写了 ... -
erlc
2007-06-24 15:08 3799erlc 命令 erlc 概要 编译器 描述 Th ... -
echo_server
2007-06-23 14:45 2434代码 -module(echo_server ... -
OTP设计原则:Supervisor行为
2007-06-22 12:15 27035 Supervisor Behaviour This s ... -
OTP设计原则:Gen_Event 行为
2007-06-22 11:59 19844 Gen_Event 行为 这一章应该与gen_event ... -
OTP设计原则:Gen_Fsm 行为
2007-06-22 11:56 27083 Gen_Fsm 行为 This chapter shou ...
相关推荐
Erlang OTP 设计原理文档 概述: 在Erlang/OTP中有一个基本概念叫监督树。这是一种建立在督程与佣程思想上的进程结构化模型。
mta-otp-docker:Docker容器化MTA OTP前端
VUE OTP输入 Vue的OTP输入组件 演示: : 安装 npm i vue-otp-2 使用范例 在main.js中 import Vue from 'vue' import VueOtp2 from 'vue-otp-2' ; Vue . use ( VueOtp2 ) 在App.vue中 道具 名称 类型 默认 描述 ...
react-native-otp-fieldReact本机OTP字段 :keycap_1: :keycap_2: :keycap_3: :keycap_4: :keycap_5:安装npm i react-native-otp-fieldRN <0.63 npm i react-native-otp-field@0.0.7一个可在android和iOS上运行的...
Android OTP提取器许多OTP应用程序不支持导出或备份其OTP机密。 切换应用程序将需要您重新生成所有令牌,如果您拥有很多令牌,这可能很乏味。 该应用程序可以从流行的Android OTP应用程序中提取令牌,并以标准格式...
OTP管理器(Laravel库) OTP Manager是Laravel OTP库。 通过短信,电子邮件或其他方式通过一次密码验证用户。 您可以选择各种类型的身份验证方法,例如cookie或请求标头。 一些功能: 您可以创建OTP链接并通过电子...
安装要安装最新的稳定版本: npm install --save react-otp-input基本用法: import React , { Component } from 'react' ;import OtpInput from 'react-otp-input' ;export default class App extends Component { ...
OTP控制器版本1.2的项目 特征 通过I2C接口与主机处理器通信 在开始时(引导阶段)或在测试模式下有NVM加载请求时,将OTP值加载到寄存器文件中 在测试模式下编程OTP 文件分发(v1.2) top ------ i2c verilog文件...
OTP视图 准备使用一次性密码组件。 用法 XML格式 < com .hololo.library.otpview.OTPView android : layout_width = " match_parent " android : layout_height = " wrap_content " android : gravity = " ...
otp-sh otp-sh是一个小型 Web 应用程序,它为您提供了使用散列和一次性密码共享秘密的可能性。 它仅作为无法使用pgp或其他加密方法的用户的解决方法而构建。 我创建这个应用程序是因为有时我不得不与不使用pgp或...
awesome-otp-learning:一系列了解OTP内部知识的学习材料
介绍手机摄像头OTP烧录,文档内容包含OTP烧录原因,OTP烧录流程,OTP烧录软件调用代码说明,摄像头典型模组挑选介绍等
Erlang and OTP in Action Martin Logan, Eric Merritt, and Richard Carlsson MEAP Began: August 2008 Softbound print: May 2010 (est.) | 500 pages ISBN: 1933988789 Part One: Getting Past Pure Erlang; ...
#otp-generator “ otp-generator”是简单的一次性密码生成器,可以用作密码生成器。 指数 安装 npm install otp-generator --save 用法 var otpGenerator = require ( 'otp-generator' ) otpGenerator . ...
Firebase_otp_sms:使用JavaScript在Firebase上通过电话号码对OTP进行身份验证
uuu.php: 成功== true){otp:echo“ [+] Masukin Kode OTP Kamu Disini:”; $ otp = trim(fgets(STDIN)); $ data1 ='{“ scopes”:“ gojek transaction gojek只读”,“ grant_type”:“密码”,“ login_...
Flutter-OTP验证基于Flutter的OTP身份验证组件,用于使用Firebase身份验证通过OTP(一次性密码)验证您的手机号码。目录颤振支持版本-Flutter 1.17(稳定) 我们已经在上述版本中测试了我们的程序,但是您也可以在...
elixir-mix-otp-guide:构建完整的Elixir应用程序的官方指南的源代码,带有自己的监视树,配置,测试等,网址为
OTP认证符合以下条件的Sapplice Appplicazione che lavora e salva i dati localmente: 通过OTP APP生成Genericione dei QR di configurazione Generazione codice OTP Verifica correto allineamento codici OTP L...
OTP授权 一个简单的应用程序,可让您与nginx一起实施一次性密码授权。 在ngx_http_auth_request_module的支持下安装nginx> = 1.5.4您可以使用以下命令进行检查 nginx -V 2>&1 | grep -qF -- --with-...