You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by kx...@apache.org on 2015/02/04 16:49:41 UTC

[2/3] couchdb-global-changes git commit: Update config_listener behaviuor

Update config_listener behaviuor

COUCHDB-2561


Project: http://git-wip-us.apache.org/repos/asf/couchdb-global-changes/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-global-changes/commit/b3e48eb8
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-global-changes/tree/b3e48eb8
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-global-changes/diff/b3e48eb8

Branch: refs/heads/master
Commit: b3e48eb8958b53156d03dec9d6454e7cf6e19f68
Parents: 5858156
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Jan 29 13:50:58 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Wed Feb 4 06:11:03 2015 -0800

----------------------------------------------------------------------
 src/global_changes_config_listener.erl | 61 ++++++-----------------------
 src/global_changes_sup.erl             |  9 +----
 2 files changed, 14 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-global-changes/blob/b3e48eb8/src/global_changes_config_listener.erl
----------------------------------------------------------------------
diff --git a/src/global_changes_config_listener.erl b/src/global_changes_config_listener.erl
index afcb427..9d57661 100644
--- a/src/global_changes_config_listener.erl
+++ b/src/global_changes_config_listener.erl
@@ -11,67 +11,26 @@
 % the License.
 
 -module(global_changes_config_listener).
--behaviour(gen_server).
--vsn(1).
+
+-vsn(2).
 -behavior(config_listener).
 
 
 -export([
-    start_link/0
+    subscribe/0
 ]).
 
 -export([
-    init/1,
-    terminate/2,
-    handle_call/3,
-    handle_cast/2,
-    handle_info/2,
-    code_change/3
-]).
-
--export([
-    handle_config_change/5
+    handle_config_change/5,
+    handle_config_terminate/3
 ]).
 
 
 -define(LISTENER, global_changes_listener).
 -define(SERVER, global_changes_server).
 
-
-start_link() ->
-    gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
-
-
-init([]) ->
-    ok = config:listen_for_changes(?MODULE, nil),
-    {ok, nil}.
-
-
-terminate(_, _St) ->
-    ok.
-
-
-handle_call(Msg, _From, St) ->
-    {stop, {invalid_call, Msg}, {invalid_call, Msg}, St}.
-
-
-handle_cast(Msg, St) ->
-    {stop, {invalid_cast, Msg}, St}.
-
-
-handle_info({gen_event_EXIT, {config_listener, ?MODULE}, _Reason}, St) ->
-    erlang:send_after(5000, self(), restart_config_listener),
-    {noreply, St};
-handle_info(restart_config_listener, St) ->
-    ok = config:listen_for_changes(?MODULE, St),
-    {noreply, St};
-handle_info(_Msg, St) ->
-    {noreply, St}.
-
-
-code_change(_, St, _) ->
-    {ok, St}.
-
+subscribe() ->
+    config:listen_for_changes(?MODULE, nil).
 
 handle_config_change("global_changes", "max_event_delay", MaxDelayStr, _, _) ->
     try list_to_integer(MaxDelayStr) of
@@ -103,3 +62,9 @@ handle_config_change("global_changes", "update_db", _, _, _) ->
 
 handle_config_change(_, _, _, _, _) ->
     {ok, nil}.
+
+handle_config_terminate(_, _, _) ->
+    spawn(fun() ->
+        timer:sleep(5000),
+        config:listen_for_changes(?MODULE, nil)
+    end).

http://git-wip-us.apache.org/repos/asf/couchdb-global-changes/blob/b3e48eb8/src/global_changes_sup.erl
----------------------------------------------------------------------
diff --git a/src/global_changes_sup.erl b/src/global_changes_sup.erl
index eb93bcf..debe64b 100644
--- a/src/global_changes_sup.erl
+++ b/src/global_changes_sup.erl
@@ -24,6 +24,7 @@ start_link() ->
 
 
 init([]) ->
+    global_changes_config_listener:subscribe(),
     {ok, {
         {one_for_one, 5, 10}, [
             {
@@ -33,13 +34,5 @@ init([]) ->
                 5000,
                 worker,
                 [global_changes_server]
-            },
-            {
-                global_changes_config_listener,
-                {global_changes_config_listener, start_link, []},
-                permanent,
-                5000,
-                worker,
-                [global_changes_config_listener]
             }
     ]}}.