From d241c9ea655d1aa356ad4cb3e7f07c2cd59c6fdb Mon Sep 17 00:00:00 2001 From: Matt Mullins Date: Fri, 3 May 2013 23:56:59 -0700 Subject: [PATCH] Bump irc_amqp_listener state version to 3. Convert version 2 state to version 3 by hoping that the listener is only monitoring one process. Thankfully, amqp_bot_listener:listen_for_events creates a monitor so that AMQP will kill IRC. --- irc/irc_amqp_listener.erl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/irc/irc_amqp_listener.erl b/irc/irc_amqp_listener.erl index da33e92..f615dc3 100644 --- a/irc/irc_amqp_listener.erl +++ b/irc/irc_amqp_listener.erl @@ -2,7 +2,7 @@ %% as PRIVMSG to a particular destination -module(irc_amqp_listener). -behavior(gen_server). --vsn(2). +-vsn(3). -define(EXCHANGE, <<"irc">>). @@ -15,7 +15,8 @@ -export([ init/1, - handle_info/2 + handle_info/2, + code_change/3 ]). -include("irc_util.hrl"). @@ -47,6 +48,17 @@ handle_info( irc_conn:send_command(ConnectionPid, Command), {noreply, State}. +code_change(2, {ConnectionPid}, _) -> + case process_info(self(), monitors) of + {monitors, [{process, ListeningChannel}]} -> + {ok, {ConnectionPid, ListeningChannel}}; + _ -> + {error, cant_find_listening_channel} + end; + +code_change({down, 2}, {ConnectionPid, _ListeningChannel}, _) -> + {ok, {ConnectionPid}}. + %% @doc Sends a message with the given routing key and body to the proper %% exchange send_message(RoutingKey, ReplyTo, Body) -> -- 2.11.0