- 浏览: 28655 次
- 性别:
- 来自: 广州
最新评论
原英文文档:http://www.erlang.org/erldoc?q=&x=0&y=0
Tips:看到网页右边的搜索功能了么,保存这个实用网页吧。
一个实现事件处理功能行为模块,可以动态的删除和增加任意数量事件的事件管理器(event_manager),事件管理器使用这个模块将实现一套标准的接口功能,包括跟踪和错误报告功能。同样他也适合OTP 监控树(supervision tree)
每个事件处理程序被实现为一个回调模块导出一组预定义的功能:
每一个事件处理程序都是一个回调模块,一个事件管理器必可以动态的增加和删除事件回调,所以gen_event 会比其它behaviours(gen_server,gen_fsm)容错更新好,如果安装好的事件处理回调失败(fails with Reason or returns a bad value Term),这个事件管理器是不会失败的,他会删除这个事件回调,并调用对应事件的terminate/2.如果给的参数如:{error,{'EXIT',Reasion}} or {error,Term},其它事件是不会受到影响的。
事件管理不会自动处理(trap)exit signals,%%手动调用 process_flag(trap_exit, true).
如果事件管理器回调返回值里面hibernation有可以进入休眠状态(hibernation),这对于长期处于空闲状态的server来说非常好,不过此特性会使用2个垃圾回收器(when hibernating and shortly after waking up),不适合处理非常多的事件管理器。只要其中一个事件处理返回hibernate就会使event manager进入休眠状态。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
创建一个事件管理器进程(event_manager)这个函数会被supervisor调用创建,保证event_manager与supervisor相连接(link),
如果EventMrName={local,Name},event manager 会像用register/2注册一样本地注册。
如果EventMrName={global,GlobalName},event manager 会像用global:register_name/2注册一样本地注册。
如果不提供Name就不会注册。
如果EventMrName = {via,Module,ViaName} event manager会使用Module里面自己定义的register_name/2,unregister_name/1,whereis_name/1 and send/2,这些函数的功能和global里面功能一致,否则{via,Module,ViaName}无用
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
创建一个独立的event manager 进程,例如没有监控树,其它参见start_link/0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a
给event manager 增加一个新的事件回调(event handler),会调用Module:init/1来初始化他的状态
EventMgr 参数可以:pid(),Name,{Name,Node}(如果这个事件管理注册在其它节点上){global,GlobalName}{via,Module,ViaName}
Args 参数是传给Module:init/1使用的
如果Module:init/1返回一个正确的值,event manager会增加event handler,此函数也会返回ok.
如果Module:init/1带Reason的失败或返回{error,Reasion} 这具event hander会被忽略,此函数会返回{'EXIT',Reason}或{error,Reason}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
和add_handler/3一样添加一个event handler,但会在event handler 和被调用的进程之间添加监控连接(supervise ther connection),
如果这个进程terminateswith Reason event manager 会用Module:terminate/2 {stop,Reason} 把这个event handler 删除
如果event handler 被删除,event manager 会发{gen_event_EXIT,Handler,Reason}给进程(the calling process):这时的Reason会有以下:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
向已增加在event manager里面所有的event handler都发一个Event(MSG).event manager会调用所有的event handler的Module:handler_event/2.
notify 是异步的:在消息发出后立即返回,sync_notify同步的,会在所有的event_handler处理完消息后返回ok.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
一个同步call(和gen_server:call差不多)不过会指定对应的Hander来处理Request.Handler内使用handler_call/2来处理Request.
TimeOut 是一个比0大的毫秒级或infinity.默认值为50000ms.如果规定时间内没有返回,就会call fails.
Repeal会返回Module:handle_call/2返回,如果 event handler没有安装,会返回{error,bad_module}.callback会分别返回Reason Term ,这个函数就会返回{error,{'EXIT',Reason},{error,Term}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
删除event manager(EvenMgrRef)里面对应的Handler,调用Handler:terminate(Args,State).来终结这个事件.
Result:返回Handler:terminate(Args,State)的返回值,如果没有找到安装的事件返回{error,module_not_found}.
如果失败了就会回调返回Reason.此函数返回:{'EXIT',Reason}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
在event manager (EventMgrRef)用Handler1代替Handler2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
与swap_handler/3一致,但是会Handler2和the calling process里面建立连接.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
返回event manager的事件Event handler列表
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
terminates the event manager 在此之前会对安装好的事件调用Module:terminate(stop,...).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
event handler里面的callback函数
当一个新的event handler被加入event manager时,这个函数会被调用.
调用gen_event:add_sup_handler/3,swap_handler/3 swap_sup_handler
返回{ok,State,hibernate}时event manager会进入休眠状态:等待下次事件发生
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
当event manager收到用notify/2或sync_notify/2发送的消息时会调用:所有安装过的事件的Handler:handler_event/2
返回{swap_handler,Args1,NewState,Handler2,Args2}时会调用Term = Module:terminate(Args1,NewState),Module2:init(Args2,Term) 【基本和swap_handler/3相同】
返回remove_handler 时会调用Module:terminate(remove_handler,State).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
使用gen_event:call/3发出的信息,与handle_event类似,不过是同步的。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
收到除用gen_event:call/3,gen_event:notify/3,gen_event:sync_notify/3之外的任何消息。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
在要完成删除,清理工作时会调用。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
更新版本用,这个一直不懂,反正现在没人用到
Tips:看到网页右边的搜索功能了么,保存这个实用网页吧。
一个实现事件处理功能行为模块,可以动态的删除和增加任意数量事件的事件管理器(event_manager),事件管理器使用这个模块将实现一套标准的接口功能,包括跟踪和错误报告功能。同样他也适合OTP 监控树(supervision tree)
每个事件处理程序被实现为一个回调模块导出一组预定义的功能:
每一个事件处理程序都是一个回调模块,一个事件管理器必可以动态的增加和删除事件回调,所以gen_event 会比其它behaviours(gen_server,gen_fsm)容错更新好,如果安装好的事件处理回调失败(fails with Reason or returns a bad value Term),这个事件管理器是不会失败的,他会删除这个事件回调,并调用对应事件的terminate/2.如果给的参数如:{error,{'EXIT',Reasion}} or {error,Term},其它事件是不会受到影响的。
事件管理不会自动处理(trap)exit signals,%%手动调用 process_flag(trap_exit, true).
如果事件管理器回调返回值里面hibernation有可以进入休眠状态(hibernation),这对于长期处于空闲状态的server来说非常好,不过此特性会使用2个垃圾回收器(when hibernating and shortly after waking up),不适合处理非常多的事件管理器。只要其中一个事件处理返回hibernate就会使event manager进入休眠状态。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
start_link() -> Result start_link(EventMgrName) -> Result Types:EventMgrName = {local,Name} | {global,GlobalName} | {via,Module,ViaName} Name = atom() GlobalName = ViaName = term() Result = {ok,Pid} | {error,{already_started,Pid}} Pid = pid()
创建一个事件管理器进程(event_manager)这个函数会被supervisor调用创建,保证event_manager与supervisor相连接(link),
如果EventMrName={local,Name},event manager 会像用register/2注册一样本地注册。
如果EventMrName={global,GlobalName},event manager 会像用global:register_name/2注册一样本地注册。
如果不提供Name就不会注册。
如果EventMrName = {via,Module,ViaName} event manager会使用Module里面自己定义的register_name/2,unregister_name/1,whereis_name/1 and send/2,这些函数的功能和global里面功能一致,否则{via,Module,ViaName}无用
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
start() -> Result start(EventMgrName) -> Result Types: EventMgrName = {local,Name} | {global,GlobalName} | {via,Module,ViaName} Name = atom() GlobalName = ViaName = term() Result = {ok,Pid} | {error,{already_started,Pid}} Pid = pid()
创建一个独立的event manager 进程,例如没有监控树,其它参见start_link/0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a
add_handler(EventMgrRef, Handler, Args) -> Result Types: EventMgr = Name | {Name,Node} | {global,GlobalName} | {via,Module,ViaName} | pid() Name = Node = atom() GlobalName = ViaName = term() Handler = Module | {Module,Id} Module = atom() Id = term() Args = term() Result = ok | {'EXIT',Reason} | term() Reason = term()
给event manager 增加一个新的事件回调(event handler),会调用Module:init/1来初始化他的状态
EventMgr 参数可以:pid(),Name,{Name,Node}(如果这个事件管理注册在其它节点上){global,GlobalName}{via,Module,ViaName}
Args 参数是传给Module:init/1使用的
如果Module:init/1返回一个正确的值,event manager会增加event handler,此函数也会返回ok.
如果Module:init/1带Reason的失败或返回{error,Reasion} 这具event hander会被忽略,此函数会返回{'EXIT',Reason}或{error,Reason}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
add_sup_handler(EventMgrRef, Handler, Args) -> Result Types: EventMgr = Name | {Name,Node} | {global,GlobalName} | {via,Module,ViaName} | pid() Name = Node = atom() GlobalName = ViaName = term() Handler = Module | {Module,Id} Module = atom() Id = term() Args = term() Result = ok | {'EXIT',Reason} | term() Reason = term()
和add_handler/3一样添加一个event handler,但会在event handler 和被调用的进程之间添加监控连接(supervise ther connection),
如果这个进程terminateswith Reason event manager 会用Module:terminate/2 {stop,Reason} 把这个event handler 删除
如果event handler 被删除,event manager 会发{gen_event_EXIT,Handler,Reason}给进程(the calling process):这时的Reason会有以下:
- 1)normal ----使用delete_handler/3或remove_handler
- 2)shutdown ---event_manager 终结了:is terminating
- 3){swapped,NewHandler,Pid} 如果使用swap_handler/3或swap_sup_handler/3替换原event handler
- 4)一个term如果由于一个错误被移除
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
notify(EventMgrRef, Event) -> ok sync_notify(EventMgrRef, Event) -> ok Types: EventMgrRef = Name | {Name,Node} | {global,GlobalName} | {via,Module,ViaName} | pid() Name = Node = atom() GlobalName = ViaName = term() Event = term()
向已增加在event manager里面所有的event handler都发一个Event(MSG).event manager会调用所有的event handler的Module:handler_event/2.
notify 是异步的:在消息发出后立即返回,sync_notify同步的,会在所有的event_handler处理完消息后返回ok.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
call(EventMgrRef, Handler, Request) -> Result call(EventMgrRef, Handler, Request, Timeout) -> Result Types: EventMgrRef = Name | {Name,Node} | {global,GlobalName} | {via,Module,ViaName} | pid() Name = Node = atom() GlobalName = ViaName = term() Handler = Module | {Module,Id} Module = atom() Id = term() Request = term() Timeout = int()>0 | infinity Result = Reply | {error,Error} Reply = term() Error = bad_module | {'EXIT',Reason} | term() Reason = term()
一个同步call(和gen_server:call差不多)不过会指定对应的Hander来处理Request.Handler内使用handler_call/2来处理Request.
TimeOut 是一个比0大的毫秒级或infinity.默认值为50000ms.如果规定时间内没有返回,就会call fails.
Repeal会返回Module:handle_call/2返回,如果 event handler没有安装,会返回{error,bad_module}.callback会分别返回Reason Term ,这个函数就会返回{error,{'EXIT',Reason},{error,Term}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
delete_handler(EventMgrRef, Handler, Args) -> Result Types: EventMgrRef = Name | {Name,Node} | {global,GlobalName} | {via,Module,ViaName} | pid() Name = Node = atom() GlobalName = ViaName = term() Handler = Module | {Module,Id} Module = atom() Id = term() Args = term() Result = term() | {error,module_not_found} | {'EXIT',Reason} Reason = term()
删除event manager(EvenMgrRef)里面对应的Handler,调用Handler:terminate(Args,State).来终结这个事件.
Result:返回Handler:terminate(Args,State)的返回值,如果没有找到安装的事件返回{error,module_not_found}.
如果失败了就会回调返回Reason.此函数返回:{'EXIT',Reason}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
swap_handler(EventMgrRef, {Handler1,Args1}, {Handler2,Args2}) -> Result Types: EventMgrRef = Name | {Name,Node} | {global,GlobalName} | {via,Module,ViaName} | pid() Name = Node = atom() GlobalName = ViaName = term() Handler1 = Handler2 = Module | {Module,Id} Module = atom() Id = term() Args1 = Args2 = term() Result = ok | {error,Error} Error = {'EXIT',Reason} | term() Reason = term()
在event manager (EventMgrRef)用Handler1代替Handler2
- 1)删除Handler1-----与调用delete_handler一致:
- 2)增加Handler2-----与调用add_handler一致:【init里面调用{Args2,Term}:Term是Handler1:terminate里面返回的】
- 3)这2个操作没有原子性,1,2的成功没有关系的。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
swap_sup_handler(EventMgrRef, {Handler1,Args1}, {Handler2,Args2}) -> Result Types: EventMgrRef = Name | {Name,Node} | {global,GlobalName} | {via,Module,ViaName} | pid() Name = Node = atom() GlobalName = ViaName = term() Handler1 = Handler 2 = Module | {Module,Id} Module = atom() Id = term() Args1 = Args2 = term() Result = ok | {error,Error} Error = {'EXIT',Reason} | term() Reason = term()
与swap_handler/3一致,但是会Handler2和the calling process里面建立连接.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
which_handlers(EventMgrRef) -> [Handler] Types: EventMgrRef = Name | {Name,Node} | {global,GlobalName} | {via,Module,ViaName} | pid() Name = Node = atom() GlobalName = ViaName = term() Handler = Module | {Module,Id} Module = atom() Id = term()
返回event manager的事件Event handler列表
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
stop(EventMgrRef) -> ok Types: EventMgrRef = Name | {Name,Node} | {global,GlobalName} | {via,Module,ViaName} | pid() Name = Node = atom() GlobalName = ViaName = term()
terminates the event manager 在此之前会对安装好的事件调用Module:terminate(stop,...).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
event handler里面的callback函数
Module:init(InitArgs) -> {ok,State} | {ok,State,hibernate} | {error,Reason} Types: InitArgs = Args | {Args,Term} Args = Term = term() State = term() Reason = term()
当一个新的event handler被加入event manager时,这个函数会被调用.
调用gen_event:add_sup_handler/3,swap_handler/3 swap_sup_handler
返回{ok,State,hibernate}时event manager会进入休眠状态:等待下次事件发生
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Module:handle_event(Event, State) -> Result Types: Event = term() State = term() Result = {ok,NewState} | {ok,NewState,hibernate} | {swap_handler,Args1,NewState,Handler2,Args2} | remove_handler NewState = term() Args1 = Args2 = term() Handler2 = Module2 | {Module2,Id} Module2 = atom() Id = term
当event manager收到用notify/2或sync_notify/2发送的消息时会调用:所有安装过的事件的Handler:handler_event/2
返回{swap_handler,Args1,NewState,Handler2,Args2}时会调用Term = Module:terminate(Args1,NewState),Module2:init(Args2,Term) 【基本和swap_handler/3相同】
返回remove_handler 时会调用Module:terminate(remove_handler,State).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Module:handle_call(Request, State) -> Result Types: Request = term() State = term() Result = {ok,Reply,NewState} | {ok,Reply,NewState,hibernate}| {swap_handler,Reply,Args1,NewState,Handler2,Args2}| {remove_handler, Reply} Reply = term() NewState = term() Args1 = Args2 = term() Handler2 = Module2 | {Module2,Id} Module2 = atom() Id = term()
使用gen_event:call/3发出的信息,与handle_event类似,不过是同步的。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Module:handle_info(Info, State) -> Result Types: Info = term() State = term() Result = {ok,NewState} | {ok,NewState,hibernate} | {swap_handler,Args1,NewState,Handler2,Args2} | remove_handler NewState = term() Args1 = Args2 = term() Handler2 = Module2 | {Module2,Id} Module2 = atom() Id = term()
收到除用gen_event:call/3,gen_event:notify/3,gen_event:sync_notify/3之外的任何消息。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Module:terminate(Arg, State) -> term() Types: Arg = Args | {stop,Reason} | stop | remove_handler | {error,{'EXIT',Reason}} | {error,Term} Args = Reason = Term = term()
在要完成删除,清理工作时会调用。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Module:code_change(OldVsn, State, Extra) -> {ok, NewState} Types: OldVsn = Vsn | {down, Vsn} Vsn = term() State = NewState = term() Extra = term()
更新版本用,这个一直不懂,反正现在没人用到
发表评论
-
Erlang 简单的节点互连
2014-03-19 23:41 563自己写的游戏跨服初步构架,以后再一点点完善,先记下时间线哈。 ... -
简单erlang节点互连实验
2014-03-10 15:53 768如果erlang:节点test1,test2互连接: 1.节点 ... -
Erlang OTP gen_event (1)
2014-02-26 15:06 1067演示gen_event的运行过程: mod_event_ma ... -
erlang efficient guide 3
2013-08-19 22:19 1114* 3 Common Caveats * 3常见 ... -
erlang efficient guide 2
2013-08-18 01:02 8662 The Eight Myths of Erlang Per ... -
fun还是如以前一样狂跩吊么?
2013-08-16 22:26 612fun这么好用。为什么老大在最近都说不要用? gen:cal ... -
emacs 的erlang-flymake
2013-08-14 15:15 1463emacs 设置erlang-flymake erlang- ... -
erlang ets
2013-07-22 23:08 1870参见:http://www.cnblogs.com ... -
erlang的编程规范
2013-03-26 17:17 1955Programming Rules and Conventio ... -
Erlang------Mnesia
2013-03-25 12:49 1708读erlang编程指南Mnesia笔记: 1.mnesia 是 ... -
进程环
2013-03-18 16:48 821编写一个程序,它生成N ... -
匿名函数fun
2012-12-15 16:12 814lists:map(fun/1,[1,2,3]). 小试匿名函 ... -
并发编程实战otp--open telecom platform 二
2012-10-10 23:17 1153第二章:Erlang语言精要。 shell 的启动参数h ... -
并发编程实战otp--open telecom platform 一
2012-10-10 23:16 12231.erlang 的进程模型: 并发的基本单位是进程, ... -
learn some erlang
2012-10-09 22:54 720Erlang has this very pragm ... -
erlang语句块的简洁使用
2012-09-25 22:48 677begin end语句块的简洁使用:问题描述:将一堆人 ... -
命令式编程语言的标杆
2012-09-25 09:47 706命令式编程语言的标杆: 1.进程必须是语言的核心; 2.任何进 ... -
emacs与erlang的完美结合
2012-09-23 22:48 12871.在emacs中使用c+x c+z 启动erlang she ...
相关推荐
7. **行为模块**:如gen_server、gen_event、gen_fsm等,是OTP设计模式的具体实现,简化了编写服务器、事件处理器和有限状态机的代码。 关于压缩包内的"otp_src_17.3",这是Erlang OTP 17.3版本的源代码目录。为了...
Erlang OTP设计原理是一份深入探讨Erlang/OTP(Open Telecom Platform)框架中设计模式和组织代码原则的文档。Erlang OTP作为Erlang语言的中间件平台,提供了构建可扩展和容错系统的标准方法。 文档开篇就介绍了...
Erlang OTP设计原则中的Gen_Fsm行为是一个关键的概念,用于构建健壮、可扩展的并发应用程序。Gen_Fsm,即通用有限状态机,是一种行为模式,它提供了一种结构化的方法来处理具有多种状态和事件的系统。本文将深入探讨...
例如Gen_Server、Gen_Fsm、Gen_Event和Supervisor等。每个行为模式都有其通用部分和特定部分。通用部分由Erlang/OTP库提供,开发者只需要专注于实现特定部分,即回调模块,以及根据需要导出特定的回调函数。 3. ...
2. OTP框架:理解其模块化设计、行为(gen_server, gen_event等)、分布式应用和系统监控。 3. RabbitMQ基本概念:掌握消息队列的工作原理、交换器(exchanges)、队列(queues)、绑定(bindings)以及消费者...
OTP是Erlang生态系统的重要组成部分,提供了许多预先设计好的行为模式(如 gen_server、gen_event 和 supervisor),这些模式使得开发者能够快速构建出符合Erlang并发哲学的应用程序。 otp_src_21.3.tar是Erlang ...
1. **模块化设计**:OTP提供了各种预定义的进程行为模式(gen_server、gen_event、gen_fsm等),便于开发者创建符合特定模式的进程,提高了代码复用和可维护性。 2. **分布式计算**:Erlang OTP支持跨节点的进程...
这些库包括Mnesia(分布式数据库)、Event Logger、公共接口定义语言(CIDL)以及行为模式如GenServer、GenEvent和Gen_fsm等。这些行为模式为开发者提供了构建状态管理、事件处理和分布式服务的标准结构,使得代码...
Erlang OTP(Open Telephony Platform)是Erlang编程语言的一个核心部分,它提供了一套强大的工具和库,用于构建可靠、可扩展和容错的分布式系统。OTP设计原则着重于实现高度并发、容错性和高效能。下面将详细讨论...
2. **gen_server行为**:gen_server是Erlang OTP中最常用的行为模式,它提供了一个通用服务器模板,支持请求-响应模型。通过gen_server,你可以创建状态管理服务器,处理同步和异步调用,同时支持定时任务和错误处理...
OTP提供了几个设计良好的应用框架,如gen_server、gen_event、gen_fsm等,它们是基于行为模式的模块,简化了并发编程和状态管理。 5. **分布式功能** OTP支持跨节点的分布式计算,使得在多台机器上构建分布式系统...
5. **行为模式(Behaviours)**:如`gen_server`、`gen_event`和`supervisor`等,这些是Erlang OTP设计模式的实现,它们为特定的系统角色提供了基础架构。例如,`gen_server`适用于处理服务请求,`gen_event`用于...
8. **行为(Behaviours)**: Erlang的行为如gen_server、gen_event和gen_fsm,提供了标准的服务器、事件管理和有限状态机的实现框架。源码中可能会有这些行为的实例。 9. **并发与分布式(Concurrency and ...
通过本案例的学习,我们不仅了解了如何使用Erlang构建高性能的在线IP查询服务,而且还深入学习了OTP的关键行为如gen_server、gen_fsm和gen_event的具体应用。这种实践不仅有助于初学者快速掌握Erlang的核心概念,还...
文档版本为v0.1.5,由Erlang/OTP官方撰写,中文版由DinoWu翻译。文档主要分为两大部分:入门指南和OTP设计原则。 ##### 1. 入门指南 - **简介**:简要介绍了Erlang的基本概念,旨在引导新手快速入门。 - **介绍**...
- **行为(Behaviours)**:如gen_server、gen_event和gen_fsm等,定义了标准的服务器、事件管理和有限状态机的行为模式,为编写可靠服务提供模板。 - **应用(Applications)**:Erlang程序组织成应用,每个应用有...
OTP库提供了许多实用的模块,如gen_server、gen_event和gen_fsm,这些都是Erlang并发编程的基础。 总而言之,Erlang9.rar是一个包含Erlang/OTP 20.0 Windows 64位安装程序的压缩包,主要用于安装Erlang环境,以...
在Erlang OTP中,应用程序通常由几个部分组成,包括行为模块(如gen_server、gen_event等)、状态管理、错误处理和进程通信。Timekeeper应用可能包含以下组件: 1. **gen_server行为模块**:Timekeeper可能实现了一...
OTP(Open Telecom Platform)是Erlang/OTP框架的核心组成部分之一,它提供了一套成熟的、可扩展的、容错的应用程序设计模式。OTP设计原则指导开发者如何构建稳定可靠的分布式系统。本文将详细介绍OTP中的几个关键...