summaryrefslogtreecommitdiff
path: root/src/rabbit_limiter.erl
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@lshift.net>2010-02-05 20:28:16 +0000
committerMatthias Radestock <matthias@lshift.net>2010-02-05 20:28:16 +0000
commita7b3464eb73e66f61a218134f03055b6b037ec5e (patch)
tree9549e3b8fb3459dd946c665afddd8605b12419e2 /src/rabbit_limiter.erl
parent82571f5e68c898a79fac70bdf7c65c1de0f2dcd6 (diff)
parenta8e6ccc9735461e74e501ee3f176ea3c0970c1d5 (diff)
downloadrabbitmq-server-a7b3464eb73e66f61a218134f03055b6b037ec5e.tar.gz
merge default into bug22310bug22310
in order to resolve merge conflict going the other way
Diffstat (limited to 'src/rabbit_limiter.erl')
-rw-r--r--src/rabbit_limiter.erl18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/rabbit_limiter.erl b/src/rabbit_limiter.erl
index cf91270e..83df15ce 100644
--- a/src/rabbit_limiter.erl
+++ b/src/rabbit_limiter.erl
@@ -31,12 +31,13 @@
-module(rabbit_limiter).
--behaviour(gen_server).
+-behaviour(gen_server2).
-export([init/1, terminate/2, code_change/3, handle_call/3, handle_cast/2,
handle_info/2]).
-export([start_link/2, shutdown/1]).
-export([limit/2, can_send/3, ack/2, register/2, unregister/2]).
+-export([get_limit/1]).
%%----------------------------------------------------------------------------
@@ -51,6 +52,7 @@
-spec(ack/2 :: (maybe_pid(), non_neg_integer()) -> 'ok').
-spec(register/2 :: (maybe_pid(), pid()) -> 'ok').
-spec(unregister/2 :: (maybe_pid(), pid()) -> 'ok').
+-spec(get_limit/1 :: (maybe_pid()) -> non_neg_integer()).
-endif.
@@ -69,7 +71,7 @@
%%----------------------------------------------------------------------------
start_link(ChPid, UnackedMsgCount) ->
- {ok, Pid} = gen_server:start_link(?MODULE, [ChPid, UnackedMsgCount], []),
+ {ok, Pid} = gen_server2:start_link(?MODULE, [ChPid, UnackedMsgCount], []),
Pid.
shutdown(undefined) ->
@@ -104,6 +106,13 @@ register(LimiterPid, QPid) -> gen_server2:cast(LimiterPid, {register, QPid}).
unregister(undefined, _QPid) -> ok;
unregister(LimiterPid, QPid) -> gen_server2:cast(LimiterPid, {unregister, QPid}).
+get_limit(undefined) ->
+ 0;
+get_limit(Pid) ->
+ rabbit_misc:with_exit_handler(
+ fun () -> 0 end,
+ fun () -> gen_server2:pcall(Pid, 9, get_limit, infinity) end).
+
%%----------------------------------------------------------------------------
%% gen_server callbacks
%%----------------------------------------------------------------------------
@@ -118,7 +127,10 @@ handle_call({can_send, QPid, AckRequired}, _From,
false -> {reply, true, State#lim{volume = if AckRequired -> Volume + 1;
true -> Volume
end}}
- end.
+ end;
+
+handle_call(get_limit, _From, State = #lim{prefetch_count = PrefetchCount}) ->
+ {reply, PrefetchCount, State}.
handle_cast(shutdown, State) ->
{stop, normal, State};