Erlang警报管理
发布日期:2021-06-29 17:24:08 浏览次数:2 分类:技术文章

本文共 822 字,大约阅读时间需要 2 分钟。

我们编写的应用程序只需要一个警报,这个警报会在CPU因为计算超大质数而开始溶化时抛出(别忘了我们正在建设一家销售质数的公司).这次将使用真正的OTP警报处理器(而不是在本章开头看到的简单版)

-module(my_alarm_handler).
-behaviour(gen_event).
-export([init/1,code_change/3,handle_event/2,handle_call/2,handle_info/2,terminate/2]).
init(Args)->
io:format("*** my_alarm_handler init:pn",[Args]),
{ok,0}.
handle_event({set_alarm,tooHot},N)->
error_logger:error_msg("*** Tell the Engineer to turn on the fan~n"),
{ok,N+1};
handle_event({clear_alarm,tooHot},N)->
error_logger:error_msg("*** Danger over.Turn off the fan~n"),
{ok,N};
handle_event(Event,N)->
io:format("*** unmatched event:pn",[Event]),
{ok,N}.
handle_call(_Request,N)->Reply=N,{ok,Reply,N}.
handle_info(_Info,N)->{ok,N}.
terminate(_reason,_N)->ok.
code_change(_OldVsn,State,_Extra)->{ok,State}.
在这里插入图片描述

Erlang程序设计-----【瑞典】Joe Armstron著 牛化成译-----【M】北京:中国工信出版社和人民邮电出版社

转载地址:https://blog.csdn.net/m0_38127487/article/details/113757440 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:为什么“自学”总是那么难?
下一篇:红楼梦第一回ruby优化

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月14日 22时29分27秒