Permalink
Browse files

Add ability to watch for node update events

If a process watches node events it will see node up/down events..
  • Loading branch information...
1 parent 1256fa5 commit 8db293290b3a19ea2b48fedb0f8c6d8254a660d2 @rzezeski rzezeski committed Oct 22, 2012
Showing with 10 additions and 0 deletions.
  1. +2 −0 src/riak_core_node_watcher.erl
  2. +8 −0 src/riak_core_node_watcher_events.erl
@@ -285,6 +285,7 @@ node_up(Node, Services, State) ->
%% that situation, we'll go ahead broadcast out.
S2 = case is_node_up(Node) of
false ->
+ riak_core_node_watcher_events:node_update(Node, up),
broadcast([Node], State);
true ->
State
@@ -305,6 +306,7 @@ node_up(Node, Services, State) ->
node_down(Node, State) ->
case is_peer(Node, State) of
true ->
+ riak_core_node_watcher_events:node_update(Node, down),
case node_delete(Node) of
[] ->
ok;
@@ -31,6 +31,7 @@
add_callback/1,
add_sup_callback/1,
add_guarded_callback/1,
+ node_update/2,
service_update/1]).
%% gen_event callbacks
@@ -64,6 +65,9 @@ add_sup_callback(Fn) when is_function(Fn) ->
add_guarded_callback(Fn) when is_function(Fn) ->
riak_core:add_guarded_event_handler(?MODULE, {?MODULE, make_ref()}, [Fn]).
+node_update(Node, Status) ->
+ gen_event:notify(?MODULE, {node_update, Node, Status}).
+
service_update(Services) ->
gen_event:notify(?MODULE, {service_update, Services}).
@@ -77,6 +81,10 @@ init([Fn]) ->
Fn(riak_core_node_watcher:services()),
{ok, #state { callback = Fn }}.
+handle_event({node_update, Node, Status}, State) ->
+ (State#state.callback)({node_update, Node, Status}),
+ {ok, State};
+
handle_event({service_update, Services}, State) ->
(State#state.callback)(Services),
{ok, State}.

0 comments on commit 8db2932

Please sign in to comment.