summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Shorin <kxepal@apache.org>2014-09-22 17:32:44 +0400
committerAlexander Shorin <kxepal@apache.org>2014-10-13 21:21:02 +0400
commit40d157f39c0fa0d80db9ccf61b770b72103ddbed (patch)
treec9d94082677adc2c1f0e2cb2a937d1d77a79fb2b
parentc7f9ad1c0f77b601aa456e62c963793d517c1026 (diff)
downloadcouchdb-40d157f39c0fa0d80db9ccf61b770b72103ddbed.tar.gz
Update state on config changes
-rw-r--r--src/ioq.erl18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/ioq.erl b/src/ioq.erl
index b761a0b41..9bfb1f8e3 100644
--- a/src/ioq.erl
+++ b/src/ioq.erl
@@ -12,10 +12,14 @@
-module(ioq).
-behaviour(gen_server).
+-behaviour(config_listener).
-export([start_link/0, call/3]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, code_change/3, terminate/2]).
+% config_listener api
+-export([handle_config_change/5]).
+
-record(state, {
concurrency=10,
ratio,
@@ -45,12 +49,19 @@ call(Fd, Msg, Priority) ->
end.
init(_) ->
+ ok = config:listen_for_changes(?MODULE, nil),
+ State = #state{},
+ {ok, read_config(State)}.
+
+read_config(State) ->
Ratio = list_to_float(config:get("ioq", "ratio", "0.01")),
- {ok, #state{ratio=Ratio}}.
+ State#state{ratio=Ratio}.
handle_call(#request{}=Request, From, State) ->
{noreply, enqueue_request(Request#request{from=From}, State), 0}.
+handle_cast(change, State) ->
+ {noreply, read_config(State)};
handle_cast(_Msg, State) ->
{noreply, State}.
@@ -76,6 +87,11 @@ handle_info({'DOWN', Ref, _, _, Reason}, State) ->
handle_info(timeout, State) ->
{noreply, maybe_submit_request(State)}.
+handle_config_change("ioq", _, _, _, _) ->
+ {ok, gen_server:cast(?MODULE, change)};
+handle_config_change(_, _, _, _, _) ->
+ {ok, nil}.
+
code_change(_Vsn, State, _Extra) ->
{ok, State}.