couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [38/50] git commit: Use config:listen_for_changes in replicator manager
Date Fri, 17 Jan 2014 22:07:12 GMT
Use config:listen_for_changes in replicator manager

BugzID: 13179


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/commit/7915756a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/tree/7915756a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/diff/7915756a

Branch: refs/heads/import
Commit: 7915756a3a19034f9a90d79773fccf126af42a3b
Parents: 9e2d76f
Author: Adam Kocoloski <adam@cloudant.com>
Authored: Wed Feb 27 09:40:34 2013 -0500
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Wed Mar 20 06:02:41 2013 -0500

----------------------------------------------------------------------
 src/couch_replicator_manager.erl | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/7915756a/src/couch_replicator_manager.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_manager.erl b/src/couch_replicator_manager.erl
index d8d1c4a..1db7929 100644
--- a/src/couch_replicator_manager.erl
+++ b/src/couch_replicator_manager.erl
@@ -12,6 +12,7 @@
 
 -module(couch_replicator_manager).
 -behaviour(gen_server).
+-behaviour(config_listener).
 
 % public API
 -export([replication_started/1, replication_completed/2, replication_error/2]).
@@ -21,6 +22,9 @@
 -export([start_link/0, init/1, handle_call/3, handle_info/2, handle_cast/2]).
 -export([code_change/3, terminate/2]).
 
+% config_listener callback
+-export([handle_config_change/5]).
+
 -include_lib("couch/include/couch_db.hrl").
 -include("couch_replicator.hrl").
 -include("couch_replicator_js_functions.hrl").
@@ -104,6 +108,13 @@ replication_error(#rep{id = {BaseId, _} = RepId}, Error) ->
     end.
 
 
+handle_config_change("replicator", "max_replication_retry_count", V, _, S) ->
+    ok = gen_server:cast(S, {set_max_retries, retries_value(V)}),
+    {ok, S};
+handle_config_change(_, _, _, _, S) ->
+    {ok, S}.
+
+
 init(_) ->
     process_flag(trap_exit, true),
     net_kernel:monitor_nodes(true),
@@ -111,11 +122,7 @@ init(_) ->
     ?REP_TO_STATE = ets:new(?REP_TO_STATE, [named_table, set, public]),
     ?DB_TO_SEQ = ets:new(?DB_TO_SEQ, [named_table, set, public]),
     Server = self(),
-    ok = couch_config:register(
-        fun("replicator", "max_replication_retry_count", V) ->
-            ok = gen_server:cast(Server, {set_max_retries, retries_value(V)})
-        end
-    ),
+    ok = config:listen_for_changes(?MODULE, Server),
     ScanPid = spawn_link(fun() -> scan_all_dbs(Server) end),
     {ok, #state{
         db_notifier = db_update_notifier(),
@@ -211,6 +218,14 @@ handle_info({'DOWN', _Ref, _, _, _}, State) ->
     % From a db monitor created by a replication process. Ignore.
     {noreply, State};
 
+handle_info({gen_event_EXIT, {config_listener, ?MODULE}, _Reason}, State) ->
+    erlang:send_after(5000, self(), restart_config_listener),
+    {noreply, State};
+
+handle_info(restart_config_listener, State) ->
+    ok = config:listen_for_changes(?MODULE, self()),
+    {noreply, State};
+
 handle_info(Msg, State) ->
     twig:log(error,"Replication manager received unexpected message ~p", [Msg]),
     {stop, {unexpected_msg, Msg}, State}.


Mime
View raw message