summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandru Scvortov <alexandru@rabbitmq.com>2011-08-02 17:48:28 +0100
committerAlexandru Scvortov <alexandru@rabbitmq.com>2011-08-02 17:48:28 +0100
commit227bdc662000b68b4a63a4086f918f73b5ddfe9f (patch)
tree055134574aa347b3cbac8d35ca593647d45cec6f
parent3e5037b71c4bd5d4947ea0ed3807a51f87255388 (diff)
downloadrabbitmq-server-227bdc662000b68b4a63a4086f918f73b5ddfe9f.tar.gz
refactoring
Rename internal_emit_stats to emit_stats. Add the missing export to channel. Prefer one big case statement over a function with two heads.
-rw-r--r--src/rabbit_amqqueue_process.erl17
-rw-r--r--src/rabbit_channel.erl22
-rw-r--r--src/rabbit_reader.erl6
3 files changed, 21 insertions, 24 deletions
diff --git a/src/rabbit_amqqueue_process.erl b/src/rabbit_amqqueue_process.erl
index fcca3087..0b4b62f5 100644
--- a/src/rabbit_amqqueue_process.erl
+++ b/src/rabbit_amqqueue_process.erl
@@ -184,7 +184,7 @@ declare(Recover, From,
infos(?CREATION_EVENT_KEYS, State1)),
rabbit_event:if_enabled(
StatsTimer,
- fun() -> internal_emit_stats(State1) end),
+ fun() -> emit_stats(State1) end),
noreply(State1);
Q1 -> {stop, normal, {existing, Q1}, State}
end.
@@ -755,10 +755,10 @@ consumers(#q{active_consumers = ActiveConsumers,
[{ChPid, ConsumerTag, AckRequired} | Acc]
end, [], queue:join(ActiveConsumers, BlockedConsumers)).
-internal_emit_stats(State) ->
- internal_emit_stats(State, []).
+emit_stats(State) ->
+ emit_stats(State, []).
-internal_emit_stats(State, Extra) ->
+emit_stats(State, Extra) ->
rabbit_event:notify(queue_stats, Extra ++ infos(?STATISTICS_KEYS, State)).
emit_consumer_created(ChPid, ConsumerTag, Exclusive, AckRequired) ->
@@ -798,10 +798,9 @@ prioritise_cast(Msg, _State) ->
_ -> 0
end.
-prioritise_info({'DOWN', _MonitorRef, process, DownPid, _Reason},
- #q{q = #amqqueue{exclusive_owner = DownPid}}) -> 8;
-prioritise_info(Msg, _State) ->
+prioritise_info(Msg, #q{q = #amqqueue{exclusive_owner = DownPid}}) ->
case Msg of
+ {'DOWN', _, process, DownPid, _} -> 8;
update_ram_duration -> 8;
maybe_expire -> 8;
drop_expired -> 8;
@@ -1101,7 +1100,7 @@ handle_info(drop_expired, State) ->
handle_info(emit_stats, State = #q{stats_timer = StatsTimer}) ->
%% Do not invoke noreply as it would see no timer and create a new one.
- internal_emit_stats(State),
+ emit_stats(State),
State1 = State#q{stats_timer = rabbit_event:reset_stats_timer(StatsTimer)},
assert_invariant(State1),
{noreply, State1, hibernate};
@@ -1155,7 +1154,7 @@ handle_pre_hibernate(State = #q{backing_queue = BQ,
BQS3 = BQ:handle_pre_hibernate(BQS2),
rabbit_event:if_enabled(
StatsTimer,
- fun () -> internal_emit_stats(State, [{idle_since, now()}]) end),
+ fun () -> emit_stats(State, [{idle_since, now()}]) end),
State1 = State#q{stats_timer = rabbit_event:stop_stats_timer(StatsTimer),
backing_queue_state = BQS3},
{hibernate, stop_rate_timer(State1)}.
diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl
index 4dd38fd6..72d6d33a 100644
--- a/src/rabbit_channel.erl
+++ b/src/rabbit_channel.erl
@@ -27,7 +27,7 @@
-export([init/1, terminate/2, code_change/3, handle_call/3, handle_cast/2,
handle_info/2, handle_pre_hibernate/1, prioritise_call/3,
- prioritise_cast/2, format_message_queue/2]).
+ prioritise_cast/2, prioritise_info/2, format_message_queue/2]).
-record(ch, {state, protocol, channel, reader_pid, writer_pid, conn_pid,
limiter_pid, start_limiter_fun, tx_status, next_tag,
@@ -192,7 +192,7 @@ init([Channel, ReaderPid, WriterPid, ConnPid, Protocol, User, VHost,
trace_state = rabbit_trace:init(VHost)},
rabbit_event:notify(channel_created, infos(?CREATION_EVENT_KEYS, State)),
rabbit_event:if_enabled(StatsTimer,
- fun() -> internal_emit_stats(State) end),
+ fun() -> emit_stats(State) end),
{ok, State, hibernate,
{backoff, ?HIBERNATE_AFTER_MIN, ?HIBERNATE_AFTER_MIN, ?DESIRED_HIBERNATE}}.
@@ -211,7 +211,8 @@ prioritise_cast(Msg, _State) ->
prioritise_info(Msg, _State) ->
case Msg of
- emit_stats -> 7
+ emit_stats -> 7;
+ _ -> 0
end.
handle_call(flush, _From, State) ->
@@ -303,7 +304,7 @@ handle_info(timeout, State) ->
noreply(State);
handle_info(emit_stats, State = #ch{stats_timer = StatsTimer}) ->
- internal_emit_stats(State),
+ emit_stats(State),
noreply([ensure_stats_timer],
State#ch{
stats_timer = rabbit_event:reset_stats_timer(StatsTimer)});
@@ -323,11 +324,8 @@ handle_info({'EXIT', _Pid, Reason}, State) ->
handle_pre_hibernate(State = #ch{stats_timer = StatsTimer}) ->
ok = clear_permission_cache(),
- rabbit_event:if_enabled(StatsTimer,
- fun () ->
- internal_emit_stats(
- State, [{idle_since, now()}])
- end),
+ rabbit_event:if_enabled(
+ StatsTimer, fun () -> emit_stats(State, [{idle_since, now()}]) end),
StatsTimer1 = rabbit_event:stop_stats_timer(StatsTimer),
{hibernate, State#ch{stats_timer = StatsTimer1}}.
@@ -1495,10 +1493,10 @@ update_measures(Type, QX, Inc, Measure) ->
put({Type, QX},
orddict:store(Measure, Cur + Inc, Measures)).
-internal_emit_stats(State) ->
- internal_emit_stats(State, []).
+emit_stats(State) ->
+ emit_stats(State, []).
-internal_emit_stats(State = #ch{stats_timer = StatsTimer}, Extra) ->
+emit_stats(State = #ch{stats_timer = StatsTimer}, Extra) ->
CoarseStats = infos(?STATISTICS_KEYS, State),
case rabbit_event:stats_level(StatsTimer) of
coarse ->
diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl
index 3bc0e389..2dccc748 100644
--- a/src/rabbit_reader.erl
+++ b/src/rabbit_reader.erl
@@ -318,7 +318,7 @@ handle_other({'$gen_call', From, {info, Items}}, Deb, State) ->
end),
mainloop(Deb, State);
handle_other(emit_stats, Deb, State) ->
- mainloop(Deb, internal_emit_stats(State));
+ mainloop(Deb, emit_stats(State));
handle_other({system, From, Request}, Deb, State = #v1{parent = Parent}) ->
sys:handle_system_msg(Request, From, Parent, ?MODULE, Deb, State);
handle_other(Other, _Deb, _State) ->
@@ -686,7 +686,7 @@ handle_method0(#'connection.open'{virtual_host = VHostPath},
[{type, network} |
infos(?CREATION_EVENT_KEYS, State1)]),
rabbit_event:if_enabled(StatsTimer,
- fun() -> internal_emit_stats(State1) end),
+ fun() -> emit_stats(State1) end),
State1;
handle_method0(#'connection.close'{}, State) when ?IS_RUNNING(State) ->
lists:foreach(fun rabbit_channel:shutdown/1, all_channels()),
@@ -915,6 +915,6 @@ send_exception(State = #v1{connection = #connection{protocol = Protocol}},
State1#v1.sock, 0, CloseMethod, Protocol),
State1.
-internal_emit_stats(State = #v1{stats_timer = StatsTimer}) ->
+emit_stats(State = #v1{stats_timer = StatsTimer}) ->
rabbit_event:notify(connection_stats, infos(?STATISTICS_KEYS, State)),
State#v1{stats_timer = rabbit_event:reset_stats_timer(StatsTimer)}.