[erlang-questions] Generic server and state recovery

Edmond Begumisa <>
Wed Dec 8 14:30:36 CET 2010


Oops, forgot a few clauses in that terminate function...

terminate(normal, State) ->
    ignore;
terminate(shutdown, State) ->
    ignore;
terminate({shutdown,_}, State) ->
    ignore;
terminate(_Crash, State) ->
    ok = save_crashing_state(State),
    ignore.

- Edmond -

On Thu, 09 Dec 2010 00:24:28 +1100, Edmond Begumisa  
<> wrote:

> You could implement this functionality in to your gen_server (that is  
> trapping exits) using the terminate callback, persisting the state for  
> recovery later or sending it to another process just before the  
> gen_server process itself exits...
>
> init() ->
>     process_flag(trap_exit, true),
>     ...
>
> terminate(normal, State) ->
>     ignore;
> terminate(_Crash, State) ->
>     ok = save_crashing_state(State),
>     ignore.
>
> save_crashing_state(State) ->
>     % do something with State
>     ...
>
> - Edmond -
>
>
> On Wed, 08 Dec 2010 22:29:40 +1100, Alessandro Sivieri  
> <> wrote:
>
>> 2010/12/8 Edmond Begumisa <>
>>
>>> By "recover", do you mean after an abnormal exit?
>>>
>>>
>> Yes, for example after a crash, when the supervisor restarts the  
>> process...
>>
>
>


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


More information about the erlang-questions mailing list