Skip to content

Commit

Permalink
revert to tracking handler funs with refs
Browse files Browse the repository at this point in the history
  • Loading branch information
argv0 committed Apr 1, 2011
1 parent dc64975 commit 4c863b6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
9 changes: 7 additions & 2 deletions src/riak_core_node_watcher.erl
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ handle_info(broadcast, State) ->


terminate(_Reason, State) ->
%% This works because we are trapping exits - if we stop doing that, the
%% handler won't get deleted.
riak_core:delete_guarded_event_handler(riak_core_ring_events,
{riak_core_ring_events, self()}, []),
%% Let our peers know that we are shutting down
broadcast(State#state.peers, State#state { status = down }).

Expand All @@ -222,10 +226,11 @@ update_avsn(State) ->
State#state { avsn = State#state.avsn + 1 }.

watch_for_ring_events() ->
Self = self(),
Fn = fun(R) ->
gen_server:cast(riak_core_node_watcher, {ring_update, R})
gen_server:cast(Self, {ring_update, R})
end,
riak_core_ring_events:add_guarded_callback(Fn).
riak_core_ring_events:add_guarded_handler({riak_core_ring_events, Self}, [Fn]).

delete_service_mref(Id) ->
%% Cleanup the monitor if one exists
Expand Down
3 changes: 1 addition & 2 deletions src/riak_core_node_watcher_events.erl
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ add_sup_callback(Fn) when is_function(Fn) ->
gen_event:add_sup_handler(?MODULE, {?MODULE, make_ref()}, [Fn]).

add_guarded_callback(Fn) when is_function(Fn) ->
riak_core:add_guarded_event_handler(
?MODULE, {?MODULE, riak_core_util:fun_uniq_id(Fn)}, [Fn]).
riak_core:add_guarded_event_handler(?MODULE, {?MODULE, make_ref()}, [Fn]).

service_update(Services) ->
gen_event:notify(?MODULE, {service_update, Services}).
Expand Down
3 changes: 1 addition & 2 deletions src/riak_core_ring_events.erl
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ add_sup_callback(Fn) when is_function(Fn) ->
gen_event:add_sup_handler(?MODULE, {?MODULE, make_ref()}, [Fn]).

add_guarded_callback(Fn) when is_function(Fn) ->
riak_core:add_guarded_event_handler(
?MODULE, {?MODULE,riak_core_util:fun_uniq_id(Fn)}, [Fn]).
riak_core:add_guarded_event_handler(?MODULE, {?MODULE, make_ref()}, [Fn]).

force_update() ->
{ok, Ring} = riak_core_ring_manager:get_my_ring(),
Expand Down
9 changes: 1 addition & 8 deletions src/riak_core_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
chash_bucketonly_keyfun/1,
mkclientid/1,
start_app_deps/1,
rpc_every_member/4,
fun_uniq_id/1]).
rpc_every_member/4]).

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
Expand Down Expand Up @@ -225,12 +224,6 @@ rpc_every_member(Module, Function, Args, Timeout) ->
Nodes = riak_core_ring:all_members(MyRing),
rpc:multicall(Nodes, Module, Function, Args, Timeout).

%% @spec fun_uniq_id(function()) -> integer()
%% @doc Return a unique integer for a fun, based on erlang:fun_info().
fun_uniq_id(Fn) when is_function(Fn) ->
{uniq, Uniq} = erlang:fun_info(Fn, uniq),
Uniq.


%% ===================================================================
%% EUnit tests
Expand Down

0 comments on commit 4c863b6

Please sign in to comment.