diff options
author | Matthew Sackman <matthew@rabbitmq.com> | 2011-01-18 13:04:31 +0000 |
---|---|---|
committer | Matthew Sackman <matthew@rabbitmq.com> | 2011-01-18 13:04:31 +0000 |
commit | 4692f4151980bc4eed401ad5f0b0cf012469c958 (patch) | |
tree | 3ef15134b8365dcab97d33c05e8e347c6df99d4f | |
parent | a4b110d4484f08fabb739cecaa49695cdf297baf (diff) | |
download | rabbitmq-server-4692f4151980bc4eed401ad5f0b0cf012469c958.tar.gz |
Some might say this is a touch over abstracted. It's quite pretty though
-rw-r--r-- | src/rabbit_channel.erl | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 507fab75..b54a92cc 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -71,6 +71,8 @@ -define(INFO_KEYS, ?CREATION_EVENT_KEYS ++ ?STATISTICS_KEYS -- [pid]). +-define(NEXT_STATE_DEFAULT_FLAGS, [ensure_stats_timer, send_confirms]). + %%---------------------------------------------------------------------------- -ifdef(use_specs). @@ -280,13 +282,13 @@ handle_cast({deliver, ConsumerTag, AckRequired, handle_cast(emit_stats, State = #ch{stats_timer = StatsTimer}) -> internal_emit_stats(State), - {noreply, - State#ch{stats_timer = rabbit_event:reset_stats_timer(StatsTimer)}, - hibernate}; + noreply(?NEXT_STATE_DEFAULT_FLAGS -- [ensure_stats_timer], + State#ch{stats_timer = rabbit_event:reset_stats_timer(StatsTimer)}); handle_cast({confirm, MsgSeqNos, From}, State) -> State1 = #ch{confirmed = C} = confirm(MsgSeqNos, From, State), - {noreply, State1, case C of [] -> hibernate; _ -> 0 end}. + noreply(?NEXT_STATE_DEFAULT_FLAGS -- [send_confirms], State1, + case C of [] -> hibernate; _ -> 0 end). handle_info(timeout, State) -> noreply(State); @@ -332,10 +334,29 @@ code_change(_OldVsn, State, _Extra) -> %%--------------------------------------------------------------------------- reply(Reply, NewState) -> - {reply, Reply, ensure_stats_timer(send_confirms(NewState)), hibernate}. + reply(Reply, ?NEXT_STATE_DEFAULT_FLAGS, NewState). + +reply(Reply, Flags, NewState) -> + reply(Reply, Flags, NewState, hibernate). + +reply(Reply, Flags, NewState, Timeout) -> + {reply, Reply, next_state(Flags, NewState), Timeout}. noreply(NewState) -> - {noreply, ensure_stats_timer(send_confirms(NewState)), hibernate}. + noreply(?NEXT_STATE_DEFAULT_FLAGS, NewState). + +noreply(Flags, NewState) -> + noreply(Flags, NewState, hibernate). + +noreply(Flags, NewState, Timeout) -> + {noreply, next_state(Flags, NewState), Timeout}. + +next_state([], State) -> + State; +next_state([ensure_stats_timer | Flags], State) -> + next_state(Flags, ensure_stats_timer(State)); +next_state([send_confirms | Flags], State) -> + next_state(Flags, send_confirms(State)). ensure_stats_timer(State = #ch{stats_timer = StatsTimer}) -> ChPid = self(), |