Pull settings from new config app
BugzID: 15608
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"}}}
]}.
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,[]}}
]}.
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 @@
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