Przeglądaj źródła

ft: 添加 gen_apu 模块

master
SisMaker 3 lat temu
rodzic
commit
c65a8a4f6a
4 zmienionych plików z 1354 dodań i 24 usunięć
  1. +8
    -3
      README.md
  2. +9
    -9
      src/eGbh.app.src
  3. +1325
    -0
      src/gen_apu.erl
  4. +12
    -12
      src/gen_srv.erl

+ 8
- 3
README.md Wyświetl plik

@ -1,16 +1,20 @@
# genBehavior
封装与收集各种有用的erlang行为
最初目的是想造个非常统一又通用的行为模式-基于这个想法-封装了gen_ipc行为模块
基于gen_ipc gen_srv 基于Otp23.0.2编写 运行otp版本21+
# 简写备注
gen_ipc gen_information_processing_cell
gen_srv gen_server
gen_epm gen_event_processing module
gen_emm gen_event_management module
gen_tcm gen_tcp_callback_module
gen_apu gen_Automatic_processing_unit
# gen_ipc
erlang中存在application, supervisor, gen_server, gen_event, gen_fsm, gen_statem各种行为, 学习otp也都会学习这些行为, 实际项目中也经常会用这些行为,
其中gen_server, gen_event, gen_fsm, gen_statem这些worker类型的行为gen_server用的最多。 从大的方面看很多这些worker类型的行为都属于c/s模型,但是就单从服务进程来看
响应请求和返回请求只是服务进程对外提供的服务接口,而处理请求才是核心,而服务进程处理各种请求和其他事物可以看做是图灵机, 而gen_statem就是一个完备的图灵机模型,
@ -21,8 +25,9 @@
把这些行为封装成一个, 不仅仅可以减少学习成本,最开始学习erlang otp时要学习各种行为,各种用法,稍微有点费神, 还可以在工作中保持基础行为的统一, 不然项目中又是gen_server, 又是gen_event,又
是gen_statem不是很简洁和易用, 而且有些还不经常用,容易搞错。现在统一了, 天天用一个,天天就看一个就没简单明了多了,而且简单的需求和复杂的场景都满足, 是不是感觉好多了。
# gen_srv
# gen_srv
出于考虑大部分的行为模式为gen_server, 如果使用gen_ipc大量handle函数会添加一个额外无用的 _ 作为 状态 参数的占位, 可能对于一些追求完美与代码简洁的人来说不可接受,
所以出于该考虑, 基于gen_server结合gen_ipc一些便捷式的定时器封装了gen_srv.

+ 9
- 9
src/eGbh.app.src Wyświetl plik

@ -1,10 +1,10 @@
{application, eGbh,
[{description, "An OTP library"},
{vsn, "0.1.0"},
{registered, []},
{applications, [kernel, stdlib]},
{env, []},
{modules, []},
{licenses, ["Apache 2.0"]},
{links, []}
]}.
[{description, "An OTP library"},
{vsn, "0.1.0"},
{registered, []},
{applications, [kernel, stdlib]},
{env, []},
{modules, []},
{licenses, ["MIT"]},
{links, []}
]}.

+ 1325
- 0
src/gen_apu.erl
Plik diff jest za duży
Wyświetl plik


+ 12
- 12
src/gen_srv.erl Wyświetl plik

@ -239,9 +239,9 @@ init_it(Starter, Parent, ServerRef, Module, Args, Options) ->
%%-----------------------------------------------------------------
%% enter_loop(Module, Options, State, <ServerName>, <TimeOut>) ->_
%%
%% Description: Makes an existing process into a gen_server.
%% The calling process will enter the gen_server receive
%% loop and become a gen_server process.
%% Description: Makes an existing process into a gen_srv.
%% The calling process will enter the gen_srv receive
%% loop and become a gen_srv process.
%% The process *must* have been started using one of the
%% start functions in proc_lib, see proc_lib(3).
%% The user is responsible for any initialization of the
@ -976,7 +976,7 @@ error_info(_Reason, application_controller, _From, _Msg, _Mod, _State, _Debug) -
ok;
error_info(Reason, Name, From, Msg, Module, Debug, State) ->
Log = sys:get_log(Debug),
?LOG_ERROR(#{label => {gen_server, terminate},
?LOG_ERROR(#{label => {gen_srv, terminate},
name => Name,
last_message => Msg,
state => format_status(terminate, Module, get(), State),
@ -985,8 +985,8 @@ error_info(Reason, Name, From, Msg, Module, Debug, State) ->
client_info => client_stacktrace(From)},
#{
domain => [otp],
report_cb => fun gen_server:format_log/2,
error_logger => #{tag => error, report_cb => fun gen_server:format_log/1}
report_cb => fun gen_srv:format_log/2,
error_logger => #{tag => error, report_cb => fun gen_srv:format_log/1}
}),
ok.
@ -1022,7 +1022,7 @@ format_log(Report) ->
limit_report(Report, unlimited) ->
Report;
limit_report(#{label := {gen_server, terminate},
limit_report(#{label := {gen_srv, terminate},
last_message := Msg,
state := State,
log := Log,
@ -1036,7 +1036,7 @@ limit_report(#{label := {gen_server, terminate},
reason => io_lib:limit_term(Reason, Depth),
client_info => limit_client_report(Client, Depth)
};
limit_report(#{label := {gen_server, no_handle_info},
limit_report(#{label := {gen_srv, no_handle_info},
message := Msg} = Report, Depth) ->
Report#{message => io_lib:limit_term(Msg, Depth)}.
@ -1063,7 +1063,7 @@ format_log(Report, FormatOpts0) ->
{Format, Args} = format_log_single(Report, FormatOpts),
io_lib:format(Format, Args, IoOpts).
format_log_single(#{label := {gen_server, terminate},
format_log_single(#{label := {gen_srv, terminate},
name := Name,
last_message := Msg,
state := State,
@ -1086,7 +1086,7 @@ format_log_single(#{label := {gen_server, terminate},
end,
{Format1 ++ ServerLogFormat ++ ClientLogFormat,
Args1 ++ ServerLogArgs ++ ClientLogArgs};
format_log_single(#{label := {gen_server, no_handle_info},
format_log_single(#{label := {gen_srv, no_handle_info},
module := Module,
message := Msg},
#{single_line := true, depth := Depth} = FormatOpts) ->
@ -1104,7 +1104,7 @@ format_log_single(#{label := {gen_server, no_handle_info},
format_log_single(Report, FormatOpts) ->
format_log_multi(Report, FormatOpts).
format_log_multi(#{label := {gen_server, terminate},
format_log_multi(#{label := {gen_srv, terminate},
name := Name,
last_message := Msg,
state := State,
@ -1143,7 +1143,7 @@ format_log_multi(#{label := {gen_server, terminate},
end ++ ClientArgs
end,
{Format, Args};
format_log_multi(#{label := {gen_server, no_handle_info},
format_log_multi(#{label := {gen_srv, no_handle_info},
module := Module,
message := Msg},
#{depth := Depth} = FormatOpts) ->

Ładowanie…
Anuluj
Zapisz