diff options
| author | Matthias Radestock <matthias@rabbitmq.com> | 2011-07-27 14:02:57 +0100 |
|---|---|---|
| committer | Matthias Radestock <matthias@rabbitmq.com> | 2011-07-27 14:02:57 +0100 |
| commit | dd5755647a68aafd26a1e73cdc47a94875e909fa (patch) | |
| tree | 2ba4a299ada14274b935d44ca3456d3ef64ca8a9 /src | |
| parent | 5d4e44fb9b6c0d382cf0c2b96426f03b3558768e (diff) | |
| parent | d89965a28f6a66128d4f7e42c812d08604140fc9 (diff) | |
| download | rabbitmq-server-git-dd5755647a68aafd26a1e73cdc47a94875e909fa.tar.gz | |
merge bug24288 into default
Diffstat (limited to 'src')
| -rw-r--r-- | src/gen_server2.erl | 28 | ||||
| -rw-r--r-- | src/rabbit_amqqueue_process.erl | 15 |
2 files changed, 34 insertions, 9 deletions
diff --git a/src/gen_server2.erl b/src/gen_server2.erl index 43e0a8f5df..6047118126 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 fcd6cc24e2..4492bbd852 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}. |
