your mail
Ulf Wiger
etxuwig@REDACTED
Mon Oct 25 18:17:35 CEST 1999
On Mon, 25 Oct 1999, Sean Hinde wrote:
Sean.H>> 2) Create a 'supervisor' with one child which receives a message from
Sean.H>> alarm_handler if your module crashes. If this happens, this child
Sean.H>> process calls exit/1, and the supervisor restarts the child, which
Sean.H>> reinstalls the handler module in alarm_handler.
Sean.H>>
Sean.H>> Here's some code to do the trick:
Sean.H>>
Sean.H>>
Sean.H>> /martin
Sean.H>[...]
Sean.H>Out of interest, why did you choose to implement this as a 'made up'
Sean.H>behaviour rather than using gen_server. Is the reason performance /
Sean.H>simplicity, or something subtle to do with the functionality of the startup
Sean.H>mechanism which can't be achieved using standard behaviours.
Sean.H>
Sean.H>Sean
Same problem, different solution, using gen_server (taken from the AXD301
project):
-module(sysHandlerSup).
-behaviour(gen_server).
-date('98-11-16').
-author('etxuwig@REDACTED').
-export([start_link/3,
start_link/4,
stop/1]).
-export([code_change/3]).
-export([init/1, handle_info/2, handle_call/3, terminate/2]).
code_change(OldVsn, State, Extra) ->
{ok, State}.
start_link(Name, Module, Args) ->
start_link(error_logger, Name, Module, Args).
start_link(EventMgr, Name, Module, Args) ->
gen_server:start_link({local, Name}, sysHandlerSup,
{EventMgr, Module, Args}, []).
stop(Name) ->
gen_server:call(Name, stop).
init({EventMgr, Module, Args}) ->
install(EventMgr, Module, Args),
{ok, {EventMgr, Module}}.
handle_call(stop, _From, S) ->
{stop, normal, ok, S}.
handle_info({gen_event_EXIT, Mod, Reason}, State) ->
{stop, {gen_event_EXIT, Mod, Reason}, State}.
terminate(Reason, {EventMgr, Module}) ->
uninstall(EventMgr, Module),
ok.
install(EventMgr, Module, Args) ->
ok = gen_event:add_sup_handler(EventMgr, Module, Args).
uninstall(EventMgr, Module) ->
gen_event:delete_handler(EventMgr, Module, stop).
Ulf Wiger, Chief Designer AXD 301
Ericsson Telecom AB tfn: +46 8 719 81 95
Varuvägen 9, Älvsjö mob: +46 70 519 81 95
S-126 25 Stockholm, Sweden fax: +46 8 719 43 44
More information about the erlang-questions
mailing list