What's wrong with this ???

Asko Husso etxhua@REDACTED
Mon Jun 2 16:52:43 CEST 2003


The kv process must be started like this:
    supervisor:start_child(simple_supervisor, {kv, {kv, start, []},
                           permanent, 1000, worker, [kv]}).
                           
To stop the kv process use supervisor:terminate_child (plus
supervisor:delete_child if You want to get rid of it for good).

See "erl -man supervisor" for details...

/Asko

> X-Authentication-Warning: enfield.sics.se: joe owned process doing -bs
> Date: Mon, 2 Jun 2003 16:25:19 +0200 (CEST)
> From: Joe Armstrong <joe@REDACTED>
> To: erlang-questions@REDACTED
> Subject: What's wrong with this ???
> MIME-Version: 1.0
> X-OriginalArrivalTime: 02 Jun 2003 14:27:39.0789 (UTC) 
FILETIME=[1F02A3D0:01C32913]
> 
> 
> I'm trying to make a supervision tree example.
> 
> I have a Key-Value server with a deliberate error. Looking up the key
> 'crash' with kv:lookup(crash) should case the server to crash  
> with a divide by zero error and the supervisor should restart the server -
> instead the supervisor crashes. 
> 
> If I do this:
> 
>    > simple_sup1:start().
>    ...
>    > kv:lookup(crash)
> 
> The KV server dies as expected, restarts and then the supervisor
> itself dies.
> 
> Any ideas as to what I've done wrong
> 
> /Joe
> 
> 
> ---- here's simple_sup1.erl ----
> 
> -module(simple_sup1).
> -behaviour(supervisor).
> 
> -export([start/0, init/1]).
> 
> start() ->
>     supervisor:start_link({local, simple_supervisor},
> 			  ?MODULE, nil).
> 
> init(_) ->
>     {ok,{{one_for_one, 5, 1000},
>          [
>           {server, 
> 	   {kv, start, []}, 
> 	   permanent, 5000, worker, [kv]}]}}.
> 
> ---- here's kv.erl ----
> 
> 
> -module(kv).
> -behaviour(gen_server).
> 
> -export([start/0, stop/0, lookup/1, store/2]).
> 
> -export([init/1, handle_call/3, handle_cast/2, 
> 	 terminate/2]).
> 
> start() -> gen_server:start_link({local,kv},kv,arg1,[]).
> 
> stop()  -> gen_server:cast(kv, stop).
>     
> init(arg1) ->
>     io:format("Key-Value server starting~n"),
>     {ok, dict:new()}.
> 
> store(Key, Val) -> 
>     gen_server:call(kv, {store, Key, Val}).
>     
> lookup(Key) -> gen_server:call(kv, {lookup, Key}).
> 
> handle_call({store, Key, Val}, From, Dict) ->
>     Dict1 = dict:store(Key, Val, Dict),
>     {reply, ack, Dict1};
> handle_call({lookup, crash}, From, Dict) ->
>     1/0;
> handle_call({lookup, Key}, From, Dict) ->
>     {reply, dict:find(Key, Dict), Dict}.
> 
> handle_cast(stop, Dict) -> {stop, normal, Dict}.
> 
> terminate(Reason, Dict) ->
>     io:format("K-V server terminating~n").
> 
> 
> 
> 
> 
> 
> 
> 

Asko Husso                       	E-mail:etxhua@REDACTED
Ericsson AB		  	        Phone: +46 8 7192324
Varuvägen 9B                               
S-126 25 Stockholm-Älvsjö, Sweden





More information about the erlang-questions mailing list