-module(thesis_simple_sup).
-behaviour(supervisor).
-export([start/0, init/1]).
start() ->
supervisor:start_link({local, thesis_simple_sup}, ?MODULE, nil).
init(_) ->
{ok,
{%%one_for_one:或型监督树,如果1000秒内被监督者重启超过5次,则监督者本身也错误
{one_for_one, 5, 1000},
[
{packet, %%被监督节点名称,要树内唯一
{thesis_packet_assembler, start,[]}, %%被监督者模块、启动命令和参数
%%permanent表示如果出错则自动重启,500指关停协议中Timer=500ms,worker指工作进程,最后是模块名称
permanent, 500, worker, [thesis_packet_assembler]},
{server,
{thesis_kv, start, []},
permanent, 500, worker,[thesis_kv]},
{logger,
{thesis_simple_logger, start, []},
permanent, 500, worker, [thesis_simple_logger]
}
]
}}.
-module(thesis_simple_sup).
-behaviour(supervisor).
-export([start/0, init/1]).
start() ->
supervisor:start_link({local, thesis_simple_sup}, ?MODULE, nil).
init(_) ->
{ok,
{{one_for_one, 5, 1000},
[
{packet,
{thesis_assember, start,[]},
permanent, 500, worker, [thesis_assember]},
{server,
{thesis_kv, start, []},
permanent, 500, worker,[thesis_kv]},
{logger,
{thesis_logger, start, []},
permanent, 500, worker, [thesis_logger]}
]
}}.
[ {description, "A simple application"},
{vsn, "1.0"},
{modules, [thesis_simple,thesis_kv,thesis_logger,
thesis_assember,thesis_simple_sup]},
{maxT, infinity},
{registered, [thesis_kv,my_simple_event_logger,my_simple_packet_assembler]},
{applications, []},
{included_applications, []},
{evn, []},
{mod, {thesis_simple, go}}]}.
-module(thesis_simple).
-behaviour(application).
-export([start/2]).
start(_,_) -> thesis_simple_sup:start().
1> application:start(thesis_simple, temporary).
Packet assembler starting
Key-Value server starting
Logger starting
ok
2> thesis_kv:store("yes","test").
ack
3> thesis_logger:log("hello").
ok
4> thesis_assember:send_header(2).
ok
5> thesis_assember:send_data("h")
5> .
ok
6> thesis_assember:send_data("h").
Got data:hh
ok
7> application:stop(thesis_simple).
=INFO REPORT==== 29-Jan-2009::20:59:07 ===
application: thesis_simple
exited: stopped
type: temporary
ok