Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8370F18873 for ; Tue, 1 Mar 2016 20:00:50 +0000 (UTC) Received: (qmail 97974 invoked by uid 500); 1 Mar 2016 20:00:35 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 97645 invoked by uid 500); 1 Mar 2016 20:00:35 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 96647 invoked by uid 99); 1 Mar 2016 20:00:35 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Mar 2016 20:00:35 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DFF7AE69FA; Tue, 1 Mar 2016 20:00:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: iilyak@apache.org To: commits@couchdb.apache.org Date: Tue, 01 Mar 2016 20:01:13 -0000 Message-Id: In-Reply-To: <9d99c62cf9534dc1a0ead1c806934ff6@git.apache.org> References: <9d99c62cf9534dc1a0ead1c806934ff6@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [40/50] couch-httpd commit: updated refs/heads/split_out_httpd_stack to e44a372 Refactor couch_httpd_config_listener Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/commit/66ce6af0 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/tree/66ce6af0 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/diff/66ce6af0 Branch: refs/heads/split_out_httpd_stack Commit: 66ce6af097d6416159081c22af34a41680b7e087 Parents: 1065a71 Author: ILYA Khlopotov Authored: Mon Feb 29 09:09:33 2016 -0800 Committer: ILYA Khlopotov Committed: Tue Mar 1 08:35:09 2016 -0800 ---------------------------------------------------------------------- src/couch_httpd_config_listener.erl | 45 ++++++++++++-------------------- 1 file changed, 17 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/66ce6af0/src/couch_httpd_config_listener.erl ---------------------------------------------------------------------- diff --git a/src/couch_httpd_config_listener.erl b/src/couch_httpd_config_listener.erl index 2d3c6a2..41b2312 100644 --- a/src/couch_httpd_config_listener.erl +++ b/src/couch_httpd_config_listener.erl @@ -11,35 +11,29 @@ % the License. -module(couch_httpd_config_listener). --vsn(2). +-vsn(3). -behaviour(config_listener). % public interface --export([subscribe/0]). +-export([subscribe/2]). % config_listener callback -export([handle_config_change/5, handle_config_terminate/3]). -subscribe() -> - Settings = [ - {bind_address, config:get("chttpd", "bind_address")}, - {port, config:get("chttpd", "port")}, - {backlog, config:get("chttpd", "backlog")}, - {server_options, config:get("chttpd", "server_options")} - ], - ok = config:listen_for_changes(?MODULE, Settings), +subscribe(Stack, Settings) -> + io:format(user, "Listen for changes: ~p", [{Stack, get_config(Settings)}]), + ok = config:listen_for_changes(?MODULE, {Stack, get_config(Settings)}), ok. -handle_config_change("chttpd", "bind_address", Value, _, Settings) -> - maybe_replace(bind_address, Value, Settings); -handle_config_change("chttpd", "port", Value, _, Settings) -> - maybe_replace(port, Value, Settings); -handle_config_change("chttpd", "backlog", Value, _, Settings) -> - maybe_replace(backlog, Value, Settings); -handle_config_change("chttpd", "server_options", Value, _, Settings) -> - maybe_replace(server_options, Value, Settings); -handle_config_change(_, _, _, _, Settings) -> - {ok, Settings}. +handle_config_change(Section, Key, Value, _, {Stack, Settings}) -> + Id = {Section, Key}, + case couch_util:get_value(Id, Settings, not_found) of + not_found -> {ok, {Stack, Settings}}; + Value -> {ok, {Stack, Settings}}; + _ -> + Stack:stop(), + {ok, {Stack, lists:keyreplace(Id, 1, Settings, {Id, Value})}} + end. handle_config_terminate(_, stop, _) -> ok; handle_config_terminate(_Server, _Reason, State) -> @@ -49,11 +43,6 @@ handle_config_terminate(_Server, _Reason, State) -> end). % private -maybe_replace(Key, Value, Settings) -> - case couch_util:get_value(Key, Settings) of - Value -> - {ok, Settings}; - _ -> - couch_httpd:stop(), - {ok, lists:keyreplace(Key, 1, Settings, {Key, Value})} - end. + +get_config(Settings) -> + [{Id, config:get(Section, Key)} || {Section, Key} = Id <- Settings].