You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/01/17 23:01:00 UTC
[41/50] git commit: Pull settings from new config app
Pull settings from new config app
BugzID: 15608
Project: http://git-wip-us.apache.org/repos/asf/couchdb-rexi/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-rexi/commit/7a81f979
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-rexi/tree/7a81f979
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-rexi/diff/7a81f979
Branch: refs/heads/import
Commit: 7a81f9795cfe841b47dc852ae3abe8105ab60070
Parents: 6703c36
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Mon Feb 11 15:32:31 2013 -0500
Committer: Adam Kocoloski <ad...@cloudant.com>
Committed: Mon Feb 11 15:44:46 2013 -0500
----------------------------------------------------------------------
rebar.config | 2 ++
src/rexi.app.src | 2 +-
src/rexi_gov_manager.erl | 34 +++++++++++++++++++++++++++-------
3 files changed, 30 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-rexi/blob/7a81f979/rebar.config
----------------------------------------------------------------------
diff --git a/rebar.config b/rebar.config
index 4af6b85..11cd96d 100644
--- a/rebar.config
+++ b/rebar.config
@@ -13,5 +13,7 @@
% the License.
{deps, [
+ {config, ".*", {git, "https://github.com/cloudant/config.git",
+ {tag, "0.1.0"}}},
{twig, ".*", {git, "https://github.com/cloudant/twig.git", {tag, "0.2.1"}}}
]}.
http://git-wip-us.apache.org/repos/asf/couchdb-rexi/blob/7a81f979/src/rexi.app.src
----------------------------------------------------------------------
diff --git a/src/rexi.app.src b/src/rexi.app.src
index 75baa77..01fa503 100644
--- a/src/rexi.app.src
+++ b/src/rexi.app.src
@@ -2,6 +2,6 @@
{description, "Lightweight RPC server"},
{vsn, git},
{registered, [rexi_sup, rexi_server]},
- {applications, [kernel, stdlib]},
+ {applications, [kernel, stdlib, config]},
{mod, {rexi_app,[]}}
]}.
http://git-wip-us.apache.org/repos/asf/couchdb-rexi/blob/7a81f979/src/rexi_gov_manager.erl
----------------------------------------------------------------------
diff --git a/src/rexi_gov_manager.erl b/src/rexi_gov_manager.erl
index 14f73ed..0886351 100644
--- a/src/rexi_gov_manager.erl
+++ b/src/rexi_gov_manager.erl
@@ -14,6 +14,7 @@
-module(rexi_gov_manager).
-behaviour(gen_server).
+-behaviour(config_listener).
% API
-export([start_link/0, send/2]).
@@ -21,6 +22,7 @@
% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
+-export([handle_config_change/5]).
-record(state, {node_timers = ets:new(timers, [set]),
nodeout_timeout = 2000,
@@ -54,14 +56,32 @@ get_governor(Node) ->
init([]) ->
ets:new(govs, [named_table, set, {read_concurrency, true}]),
net_kernel:monitor_nodes(true),
- %% if we install the new config app, the use of couch_config will go away
- %%
- %% NodeOutTimeout = list_to_integer(config:get("rexi","nodeout_timeout","500")),
- %% PidSpawnMax = list_to_integer(config:get("rexi","pid_spawn_max", "10000")),
- %% {ok, #state{nodeout_timeout = NodeOutTimeout,
- %% pid_spawn_max = PidSpawnMax}}
- {ok, #state{}}.
+ NodeOutTimeout = config:get("rexi","nodeout_timeout","500"),
+ PidSpawnMax = config:get("rexi","pid_spawn_max", "10000"),
+ State = #state{
+ nodeout_timeout = list_to_integer(NodeOutTimeout),
+ pid_spawn_max = list_to_integer(PidSpawnMax)
+ },
+ config:listen_for_changes(?MODULE, State),
+ {ok, State}.
+
+handle_config_change("rexi", "nodeout_timeout", Value, _, State) ->
+ IntValue = list_to_integer(Value),
+ %% Setting the timeout is cheap, no need to check if it actually changed
+ gen_server:call(?MODULE, {set_timeout, IntValue}),
+ {ok, State#state{nodeout_timeout = IntValue}};
+handle_config_change("rexi", "pid_spawn_max", Value, _, State) ->
+ IntValue = list_to_integer(Value),
+ %% Setting the timeout is cheap, no need to check if it actually changed
+ gen_server:call(?MODULE, {set_spawn_max, IntValue}),
+ {ok, State#state{pid_spawn_max = IntValue}};
+handle_config_change(_, _, _, _, State) ->
+ {ok, State}.
+handle_call({set_timeout, TO}, _, #state{nodeout_timeout = Old} = State) ->
+ {reply, Old, State#state{nodeout_timeout = TO}};
+handle_call({set_spawn_max, Max}, _, #state{pid_spawn_max = Old} = State) ->
+ {reply, Old, State#state{pid_spawn_max = Max}};
handle_call({get_governor, Node}, _From,
#state{pid_spawn_max = PidSpawnMax} = State) ->
case ets:lookup(govs, Node) of