Skip to content

Commit

Permalink
Add handle_info callback to riak_core_vnode behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
evax committed Apr 19, 2011
1 parent b9e8d78 commit 434aec4
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/riak_core_vnode.erl
Expand Up @@ -66,6 +66,15 @@ behaviour_info(_Other) ->
%% {noreply, term()} |
%% {stop, term(), term()}

%% handle_info/2 is an optional behaviour callback too.
%% It will be called in the case when a vnode receives any other message
%% than an EXIT message.
%% The function signature is: handle_info(Info, State).
%% It should return a tuple of the form {ok, NextState}
%%
%% Here is what the spec for handle_info/2 would look like:
%% -spec handle_info(term(), term()) -> {ok, term()}

-define(DEFAULT_TIMEOUT, 60000).
-define(LOCK_RETRY_TIMEOUT, 10000).
-define(MODSTATE, State#state{mod=Mod,modstate=ModState}).
Expand Down Expand Up @@ -232,8 +241,19 @@ handle_info({'EXIT', Pid, Reason}, StateName, State=#state{mod=Mod,modstate=ModS
{stop, linked_process_crash, State}
end;

handle_info(_Info, StateName, State) ->
{next_state, StateName, State, State#state.inactivity_timeout}.
handle_info(Info, StateName, State=#state{mod=Mod,modstate=ModState}) ->
case erlang:function_exported(Mod, handle_info, 2) of
true ->
case Mod:handle_info(Info, ModState) of
{ok, NewModState} ->
{next_state, StateName, State#state{modstate=NewModState},
State#state.inactivity_timeout};
Else ->
Else
end;
false ->
{next_state, StateName, State, State#state.inactivity_timeout}
end.

terminate(Reason, _StateName, #state{mod=Mod, modstate=ModState}) ->
Mod:terminate(Reason, ModState),
Expand Down

0 comments on commit 434aec4

Please sign in to comment.