summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam Kocoloski <adam@cloudant.com>2010-06-30 17:02:41 -0400
committerAdam Kocoloski <adam@cloudant.com>2010-08-12 01:23:05 -0400
commit4b74111cb63e5f5b250d0e617512e1221a8c509d (patch)
tree341d893678b1d1faa0a4bbefb3d9759e817c959a /src
parentebfbbb43cddaf592687b53caa0ed42cd58b2d36d (diff)
simpler event handler for sync server
Diffstat (limited to 'src')
-rw-r--r--src/mem3_sync_event.erl63
1 files changed, 9 insertions, 54 deletions
diff --git a/src/mem3_sync_event.erl b/src/mem3_sync_event.erl
index 1a360bde..55f3840c 100644
--- a/src/mem3_sync_event.erl
+++ b/src/mem3_sync_event.erl
@@ -1,37 +1,25 @@
-module(mem3_sync_event).
-
-behaviour(gen_event).
-export([init/1, handle_event/2, handle_call/2, handle_info/2, terminate/2,
code_change/3]).
--include("mem3.hrl").
-
-init([]) ->
- {ok, []}.
-
-handle_event({node_join, Node}, State) ->
- start_repl({node_join, Node}, State);
+init(_) ->
+ {ok, nil}.
-handle_event({nodeup, Node}, State) ->
- start_repl({nodeup, Node}, State);
+handle_event({Up, Node}, State) when Up == nodeup; Up == node_join ->
+ mem3_sync:add_node(Node);
-handle_event({node_leave, Node}, State) ->
- stop_repl({node_leave, Node}, State);
+handle_event({Down, Node}, State) when Down == nodedown; Down == node_leave ->
+ mem3_sync:remove_node(Node);
-handle_event({nodedown, Node}, State) ->
- stop_repl({nodedown, Node}, State);
-
-handle_event(Event, State) ->
- ?LOG_ERROR("unexpected event in dbs handler ~p", [Event]),
+handle_event(_Event, State) ->
{ok, State}.
-handle_call(Request, State) ->
- ?LOG_ERROR("unexpected call in dbs handler ~p", [Request]),
+handle_call(_Request, State) ->
{ok, ok, State}.
-handle_info(Info, State) ->
- ?LOG_ERROR("unexpected msg in dbs handler ~p", [Info]),
+handle_info(_Info, State) ->
{ok, State}.
terminate(_Reason, _State) ->
@@ -39,36 +27,3 @@ terminate(_Reason, _State) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
-
-%%
-%% internal
-%%
-
-start_repl({Reason, Node}, State) ->
- ChildSpec = dbs:childspec(Node),
- case supervisor:start_child(dbs, ChildSpec) of
- {ok, _} ->
- ok;
- {error, {already_started, _Child}} ->
- ok;
- {error, running} ->
- ok;
- {error, already_present} ->
- case supervisor:restart_child(dbs, ChildSpec) of
- {ok, _} ->
- ok;
- {error, running} ->
- ok;
- {error, Reason} ->
- ?LOG_ERROR("dbs repl restart failed ~p", [Reason])
- end;
- {error, Reason} ->
- ?LOG_ERROR("dbs repl start failed ~p", [Reason])
- end,
- {ok, State}.
-
-stop_repl({Reason, Node}, State) ->
- ?LOG_INFO("dbs repl ~p --> ~p terminating (~p)", [node(), Node, Reason]),
- supervisor:terminate_child(dbs, Node),
- supervisor:delete_child(dbs, Node),
- {ok, State}.