programming erlang ch18 - andstudy/forge GitHub Wiki
18์ฅ OTP๋กค ์์คํ ๊ตฌ์ถํ๊ธฐ
๋ชฉ์ฐจ 1.๋ฒ์ฉ์ด๋ฒคํธ ํธ๋ค๋ฌ 2.์ค๋ฅ๋ก๊ทธ 3.์๋ ๊ด๋ฆฌ 4.์ํผ๋น์ ผํธ๋ฆฌ 5.์ ํ๋ฆฌ์ผ์ด์
1.์ด๋ฒคํธ : ์ผ์ด๋๋ ์ด๋ค ๊ฒ...
RegProcName ! {evnet. E}
RegProcName : ๋ฑ๋ก๋ ํ๋ก์ธ์ค ์ด๋ฆ
E : ์ด๋ฒคํธ
- ์ด๋ฒค๋ํธ๋ค๋ฌ API
event_handler:make(Name) : ์๋ฌด๊ฒ๋ ํ์ง ์๋ ์ด๋ฒคํธ ํธ๋ค๋ฌ ์์ฑ
event_handler:make(Name, X) : Name ์ด๋ผ๋ ์ด๋ฒคํธ ํธ๋ค๋ฌ๋ก ์ด๋ฒคํธ X ์ ์ก
event_handler:make(Name, Fun) : Name ์ด๋ผ๋ ์ด๋ฒคํธ ํธ๋ค๋ฌ์ ํธ๋ค๋ฌ Fun์ ์ถ๊ฐ
ex.1) event_handler.erl
ex.2) motor_controller.erl
event_handler:add_handler(errors, fun controller/1).
==> ์คํํ๊ธฐ ์ํด์๋ errors ๋ผ๋ ์ด๋ฒค๋ ํธ๋ค๋ฌ๋ฅผ ์์ฑํด์ผํ๋ค.
( event_handler:make(errors). )
์ค๋ฅ๋ก๊ทธ / ์๋์ฒ๋ฆฌ์ ํ๋ถ ๊ตฌ์กฐ๋ ์ด๋ฒคํธ ํธ๋ค๋ฌ ํจํด์ ๋ฐ๋ฅธ๋ค.
2.์ค๋ฅ๋ก๊ทธ - ์ค๋ฅ ๋ก๊ทธ๋ฅผ ๋ณด๋ 3๊ฐ์ง ๊ด์ 1.ํ๋ก๊ทธ๋๋จธ ๊ด์ : ๋ก๊ทธ ๋จ๊ธฐ๊ธฐ ์ํด ํ๋จธ๊ฐ ํธ์ถํ๋ ํจ์ 2.๊ตฌ์ฑ์ค์ ๊ด์ : ์ค๋ฅ๋ก๊ทธ๊ฐ ๋ก๊ทธ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๋ ์์น 3.๋ณด๊ณ ์ ๊ด์ : ๊ธฐ๋ก๋ ์ค๋ฅ ์ด๋ป๊ฒ ๋ถ์ํ๋
- ์ค๋ฅ๋ก๊ทธ API
error_logger:error_msg(String) -> ok
==> ์ฝ์๋ก ์ค๋ฅ๋ฉ์ธ์ง ๋ณด๋
error_logger:error_msg(Format, Data) -> ok
==> ์ธ์๋ io:format(Format, Data) ์ ๋์ผ
error_logger:error_report(Report) -> ok
error_msg ๋ง ์ฌ์ฉํ๋ค.. -> ์ถ๊ฐ์ ์ธ ๋ด์ฉ์ ๋ฉ๋ด์ผ ์ฐธ์กฐ...
ex) error_logger:warning_map().
error_logger:error_report(Type, Report) -> ok
- ์ค๋ฅ๋ก๊ทธ ์ค์ ๋ฐฉ๋ฒ
์ฝ์์์ ํ์ธ, ํ์ผ๋ก ์ ์ฅ, ์ํ๋ก๊ทธ๋ก ์ ์ฅ
- ๋ก๊ทธ ํ์ผ ์ค์ ์ธ์๋ฅผ ๊ฐ์ง๊ณ ์ผ๋ญ ์์ํ๊ธฐ
1.erl -boot start_clean ==> ์ธ์์์ด ์คํ๊ณผ ๋์ผ
2.erl -boot start_sasl
==> ์์คํ
์ํคํ
์ณ ์ง์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์ค๋ฅ ๋ก๊น
๊ณผ ๋ถํ ๋ฐฉ์ง๋ฅผ ๋ด๋น
3.erl -boot start_sasl -config elog1
==> elog1.config ํ์ผ์ ๊ธฐ์ ๋ ํ๊ฒฝ์ ๋ฐ๋ผ์ ๋ก๊ทธ ์ถ๋ ฅ ๋ฐ ํ์ผ ์์ฑ
* config file : ์ค๋ฅ ๋ก๊ทธ ์ค์ ( ๋๋ ํ ๋ฆฌ/๋ก๊ทธํ์ผ ๊ฐฏ์/์ํ๋ก๊ทธyn )
sample) elog1..4.config ํ์ผ
%% no tty
[{sasl, [
{sasl_error_logger, false} ==> ์ค์ง ์ค๋ฅ๋ง. ์งํ๋ณด๊ณ ํจ์ค ===> ์ค์ง ์๋ก๋ง ์ถ๋ ฅ๋จ..
...
{sasl_error_logger, {file, "/home/joe/error_logs/THELOG"}} ==> ์๋๊ฒฝ๋ก์ด์ฉ. homepath ์ ์ค์ .
==> ํด๋น ํ์ผ์ ๋ก๊ทธ ๊ธฐ๋ก..
...
{error_logger_mf_dir,"./mslogs4"}, ==> ํด๋์์ฑ ์๋จ..ใ
ก.ใ
ก;
...
{errlog_type, error}, ==> ์ค์ง ์ค๋ฅ๋ง ๋ณด๊ณ .. ( ์ ๋ณด์ฑ ๋ณด๊ณ / ์งํ ๋ณด๊ณ ํจ์ค..)
]}].
- ์ค๋ฅ ๋ถ์
MODULE
rb
MODULE SUMMARY
The Report Browser Tool
DESCRIPTION
The Report Browser (RB) tool makes it possible to browse and format error reports
written by the error logger handler log_mf_h.
rb:grep(RegExp)
Types : RegExp = string()
All reports containing the regular expression RegExp are printed.
RegExp is a string containing the regular expression.
Refer to the module regexp in the STDLIB reference manual
for a definition of valid regular expressions.
They are essentially the same as the UNIX command egrep.
rb:start{max, MaxNoOfReports}.
: Controls how many reports the rb_server should read on start-up.
- ์๋ ๊ด๋ฆฌ
-
์ ๋ค๋ฆญ ์๋ฒ๋ Mod:init(InitArgs) ํธ์ถ๋ก ์์ํ๋ค.
-
handle_event(Event, State) Event : {EventType, EventArg} ํํ์ ํํ
-
4.์ํผ๋น์ ผํธ๋ฆฌ - ํ๋ก์ธ์ค๋ค์ ๊ตฌ์กฐ - ์์ ํ๋ก์ธ์ค๋ ํธ๋ฆฌ์ ์๋ ํ์ ํ๋ก์ธ์ค(์์ปค)๋ฅผ ๊ฐ์ํ๋ฉด์ ํ๋ก์ธ์ค๊ฐ ์คํจํ ๊ฒฝ์ฐ ์ฌ์์ ์ํจ๋ค.
* ํธ๋ฆฌ ์ ํ
- ์ผ๋์ผ ์ํผ๋น์ ผ ํธ๋ฆฌ
์ด๋ค ์์ปค๊ฐ ์คํจํ๋ฉด ๊ทธ ํ๋ก์ธ์ค๋ ์ํผ๋ฐ์ด์ ์ ์ํด ์ฌ์์
- ์ผ๋๋ค ์ํผ๋น์ ผ ํธ๋ฆฌ
์ด๋ค ์์ปค๊ฐ ์ฃฝ์ผ๋ฉด ๋ชจ๋ ์์ปค๋ฅผ ์ฃฝ์ด๊ณ ๋ชจ๋ ์ฌ์์
* ์ํผ๋น์ ผ ํจ์ ํํ
init(...) ->
{ok, {RestartStrategy, MaxRestart, Time},
[Worker1, Worker2, Worker3, ...]
}
- RestartStrategy : ์ ํ
์ผ๋์ผ / ์ผ๋๋ค ๊ฐ์ด๋ฐ ํ๋
- MaxRestart, Time : ์ฌ ์์ ๋น๋ (Time ๋ด์ MaxRestart ์ด์์ ์ํํ๋ฉด ์์ปค๋ฅผ ๋ชจ๋ ์ฃฝ์ด๊ณ ์์ ๋ ์ข
๋ฃ)
- [{Worker1}..n] : ์์ปค ํ๋ก์ธ์ค๋ฅผ ์ด๋ป๊ฒ ์์ํ ์ง ๊ธฐ์
Worker ์์ธ
{Tag, {Mod, Func, ArgList},
Restart,
Shutdown,
Type,
[Mod1] }
- Tag : ์์ปคํ๋ก์ธ์ค๋ฅผ ์ฐธ์กฐํ๋ ๋ฐ ์ฌ์ฉํ ์ ์๋ ์ ํ
ํ๊ทธ
- {Mod, Func, ArgList} : ์ํผ๋ฐ์ด์ ๊ฐ ์์ปค๋ฅผ ์์ํ๋ ์ฌ์ฉํ ํจ์ ์
- Restart : permanent/transient/tempory
- Shutdown : ์ค๋จ ์ต๋ํ์ฉ ์๊ฐ
- Type : worker/supervisor ํ๋ก์ธ์ค ์ ํ
- Mod1 : ์ฝ๋ฐฑ ๋ชจ๋์ ์ด๋ฆ
5.์ ํ๋ฆฌ์ผ์ด์
MODULE
application
MODULE SUMMARY
Generic OTP application functions
DESCRIPTION
In OTP, application denotes a component implementing some specific functionality,
that can be started and stopped as a unit, and which can be re-used in other systems
as well. This module interfaces the application controller, a process started at every
Erlang runtime system, and contains functions for controlling applications (for example
starting and stopping applications), and functions to access information about
applications (for example configuration parameters).
OTP ์์คํ
์์ Application์ ํ๋์ ๋จ์๋ก์ ์์ํ๊ฑฐ๋ ์ค์ง ๋ ์ ์๋ ํนํ๋ ๊ธฐ๋ฅ์ ๊ฐ์ง
์ปดํฌ๋ํธ ์ด๋ค. ์ด ๋ชจ๋์ ์ดํ๋ฆฌ์ผ์ด์
์ปจํธ๋กค ๊ฐ์ ์์
, ๋ชจ๋ ์ผ๋ญ ์์คํ
ํ๋ก์ธ์, ์์/์ ์ง
๋ฑ์ ์์
์ดํ๋ฆฌ์ผ์ด์
, ์ดํ๋ฆฌ์ผ์ด์
์ ๊ดํ ์ ๋ณด๋ฅผ ์ ์ํ๋ ๊ธฐ๋ฅ ๋ฑ์ ๊ด์ฌํ๋ค.
An application is defined by an application specification. ๋ช
์ธ์์ ์ ์๋์ด์๋ค.
The specification is normally located in an application resource file called Application.app,
where Application is the name of the application. Refer to app(4) for more information about
the application specification.
This module can also be viewed as a behaviour for an application implemented according to
the OTP design principles as a supervision tree. The definition of how to start and stop the
tree should be located in an application callback module exporting a pre-defined set of functions.
- loaded_applications() -> [{Application, Description, Vsn}]
Types:
Application = atom()
Description = string()
Vsn = string()
Returns a list with information about the applications which have been loaded using load/1,2,
also included applications. Application is the application name. Description and Vsn are the values
of its description and vsn application specification keys, respectively.
=* File Types *=
The following file types are defined in Erlang/OTP:
=* File Types *=
File Type File Name/Extension Documented in
module .erl Erlang Reference Manual
include file .hrl Erlang Reference Manual
release resource file .rel rel(4)
application resource file .app app(4)
boot script .script script(4)
binary boot script .boot -
configuration file .config config(4)
application upgrade file .appup appup(4)
release upgrade file relup relup(4)