You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2015/06/02 21:31:10 UTC
[20/41] chttpd commit: updated refs/heads/2080-port-cors to e2c2bd7
Update config_listener behaviuor
COUCHDB-2561
Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/4b102bf7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/4b102bf7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/4b102bf7
Branch: refs/heads/2080-port-cors
Commit: 4b102bf7de3b835cf82c81276deb3e4afbd942d9
Parents: 1e41311
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Jan 29 13:33:57 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Wed Feb 4 05:58:58 2015 -0800
----------------------------------------------------------------------
src/chttpd_config_listener.erl | 43 +++++++++----------------------------
src/chttpd_sup.erl | 2 +-
2 files changed, 11 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/4b102bf7/src/chttpd_config_listener.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_config_listener.erl b/src/chttpd_config_listener.erl
index cf90ab5..76fc396 100644
--- a/src/chttpd_config_listener.erl
+++ b/src/chttpd_config_listener.erl
@@ -11,24 +11,16 @@
% the License.
-module(chttpd_config_listener).
--behaviour(gen_server).
--vsn(1).
+-vsn(2).
-behaviour(config_listener).
% public interface
--export([start_link/0]).
-
-% gen_server callbacks
--export([init/1, handle_call/3, handle_cast/2, handle_info/2,
- code_change/3, terminate/2]).
+-export([subscribe/0]).
% config_listener callback
--export([handle_config_change/5]).
-
-start_link() ->
- gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
+-export([handle_config_change/5, handle_config_terminate/3]).
-init([]) ->
+subscribe() ->
Settings = [
{bind_address, config:get("chttpd", "bind_address")},
{port, config:get("chttpd", "port")},
@@ -36,7 +28,7 @@ init([]) ->
{server_options, config:get("chttpd", "server_options")}
],
ok = config:listen_for_changes(?MODULE, Settings),
- {ok, Settings}.
+ ok.
handle_config_change("chttpd", "bind_address", Value, _, Settings) ->
maybe_replace(bind_address, Value, Settings);
@@ -49,26 +41,11 @@ handle_config_change("chttpd", "server_options", Value, _, Settings) ->
handle_config_change(_, _, _, _, Settings) ->
{ok, Settings}.
-handle_call(_, _, State) ->
- {reply, ignored, State}.
-
-handle_cast(_, State) ->
- {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, State),
- {noreply, State};
-handle_info(_Msg, State) ->
- {noreply, State}.
-
-terminate(_, _State) ->
- ok.
-
-code_change(_, State, _) ->
- {ok, State}.
+handle_config_terminate(_Server, _Reason, State) ->
+ spawn(fun() ->
+ timer:sleep(5000),
+ config:listen_for_changes(?MODULE, State)
+ end).
% private
maybe_replace(Key, Value, Settings) ->
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/4b102bf7/src/chttpd_sup.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_sup.erl b/src/chttpd_sup.erl
index 498491a..6763ffe 100644
--- a/src/chttpd_sup.erl
+++ b/src/chttpd_sup.erl
@@ -23,9 +23,9 @@ start_link(Args) ->
supervisor:start_link({local,?MODULE}, ?MODULE, Args).
init([]) ->
+ chttp_config_listener:subscribe(),
{ok, {{one_for_one, 3, 10}, [
?CHILD(chttpd, worker),
- ?CHILD(chttpd_config_listener, worker),
?CHILD(chttpd_auth_cache, worker),
{chttpd_auth_cache_lru,
{ets_lru, start_link, [chttpd_auth_cache_lru, lru_opts()]},