summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2011-07-27 14:02:57 +0100
committerMatthias Radestock <matthias@rabbitmq.com>2011-07-27 14:02:57 +0100
commit318d37920c395a11c1a72ac55014d7d84dfadd76 (patch)
tree2ba4a299ada14274b935d44ca3456d3ef64ca8a9
parent9433b14ae3f0e864895b0b02837b7598cadfe32c (diff)
parent8b59064f8d092871fa3ca504a1bdaf58830e1e01 (diff)
downloadrabbitmq-server-318d37920c395a11c1a72ac55014d7d84dfadd76.tar.gz
merge bug24288 into default
-rw-r--r--src/gen_server2.erl28
-rw-r--r--src/rabbit_amqqueue_process.erl15
2 files changed, 34 insertions, 9 deletions
diff --git a/src/gen_server2.erl b/src/gen_server2.erl
index 43e0a8f5..60471181 100644
--- a/src/gen_server2.erl
+++ b/src/gen_server2.erl
@@ -67,6 +67,11 @@
%% module. Note there is no form also encompassing a reply, thus if
%% you wish to reply in handle_call/3 and change the callback module,
%% you need to use gen_server2:reply/2 to issue the reply manually.
+%%
+%% 8) The callback module can optionally implement
+%% format_message_queue/2 which is the equivalent of format_status/2
+%% but where the second argument is specifically the priority_queue
+%% which contains the prioritised message_queue.
%% All modifications are (C) 2009-2011 VMware, Inc.
@@ -1161,17 +1166,22 @@ format_status(Opt, StatusData) ->
end,
Header = lists:concat(["Status for generic server ", NameTag]),
Log = sys:get_debug(log, Debug, []),
- Specfic =
- case erlang:function_exported(Mod, format_status, 2) of
- true -> case catch Mod:format_status(Opt, [PDict, State]) of
- {'EXIT', _} -> [{data, [{"State", State}]}];
- Else -> Else
- end;
- _ -> [{data, [{"State", State}]}]
- end,
+ Specfic = callback(Mod, format_status, [Opt, [PDict, State]],
+ fun () -> [{data, [{"State", State}]}] end),
+ Messages = callback(Mod, format_message_queue, [Opt, Queue],
+ fun () -> priority_queue:to_list(Queue) end),
[{header, Header},
{data, [{"Status", SysState},
{"Parent", Parent},
{"Logged events", Log},
- {"Queued messages", priority_queue:to_list(Queue)}]} |
+ {"Queued messages", Messages}]} |
Specfic].
+
+callback(Mod, FunName, Args, DefaultThunk) ->
+ case erlang:function_exported(Mod, FunName, length(Args)) of
+ true -> case catch apply(Mod, FunName, Args) of
+ {'EXIT', _} -> DefaultThunk();
+ Success -> Success
+ end;
+ false -> DefaultThunk()
+ end.
diff --git a/src/rabbit_amqqueue_process.erl b/src/rabbit_amqqueue_process.erl
index fcd6cc24..4492bbd8 100644
--- a/src/rabbit_amqqueue_process.erl
+++ b/src/rabbit_amqqueue_process.erl
@@ -35,6 +35,8 @@
-export([init_with_backing_queue_state/7]).
+-export([format_message_queue/2]).
+
%% Queue's state
-record(q, {q,
exclusive_consumer,
@@ -1162,3 +1164,16 @@ handle_pre_hibernate(State = #q{backing_queue = BQ,
State1 = State#q{stats_timer = rabbit_event:stop_stats_timer(StatsTimer),
backing_queue_state = BQS3},
{hibernate, stop_rate_timer(State1)}.
+
+format_message_queue(_Opt, Mailbox) ->
+ Len = priority_queue:len(Mailbox),
+ {Len,
+ case Len > 100 of
+ false -> priority_queue:to_list(Mailbox);
+ true -> {summary,
+ orddict:to_list(
+ lists:foldl(
+ fun ({P, _V}, Counts) ->
+ orddict:update_counter(P, 1, Counts)
+ end, orddict:new(), priority_queue:to_list(Mailbox)))}
+ end}.