-{"3",
- [{"2", [{load_module, irc_sup}]}],
- [{"2", [{load_module, irc_sup}]}]
+{"4",
+ [{"3", [{add_module, irc_object_sup},
+ {add_module, irc_amqp_listener},
+ {update, irc_sup, supervisor},
+ {update, irc_net_sup, supervisor},
+ {update, irc_conn, {advanced, none}}
+ ]}],
+
+ [{"3", [{update, irc_conn, {advanced, none}},
+ {delete_module, irc_object_sup},
+ {delete_module, irc_amqp_listener},
+ {update, irc_sup, supervisor},
+ {update, irc_net_sup, supervisor}
+ ]}]
}.
terminate(_Reason, _State) ->
ok.
-code_change(_OldVsn, State, _Extra) ->
- {ok, State}.
+code_change(1, {irc_state, Instance, Config, Joined, Socket, Buffer} = State, _Extra) ->
+ error_logger:info_msg("Converting from version 1 to version 2.~nOld state is~p~n",
+ [State]),
+
+ [Supervisor|_] = get('$ancestors'),
+ [TableId|_] = [Tab || Tab <- ets:all(), Supervisor == ets:info(Tab, owner)],
+ {ok, ObjectSupPid} = irc_net_sup:create_object_sup(Instance, Supervisor, TableId),
+
+ NewState = {irc_state, Instance,
+ Config,
+ Joined,
+ Socket,
+ Buffer,
+ Supervisor,
+ TableId,
+ ObjectSupPid},
+
+ error_logger:info_msg("State transition is done.~nNew state is ~p~n",
+ [NewState]),
+
+ {_, _, _, _, Channels} = Config,
+ lists:foreach(fun (Channel) -> add_amqp_listener(Channel, NewState) end, Channels),
+
+ error_logger:info_msg("All done starting new version"),
+
+ {ok, NewState};
+
+code_change({down, 1}, State, _Extra) ->
+ error_logger:info_msg("Converting version 2 to version 1.~nOld state is ~p~n",
+ [State]),
+
+ #irc_state{instance = Instance,
+ config = Config,
+ joined = Joined,
+ socket = Socket,
+ buffer = Buffer,
+ supervisor = Supervisor} = State,
+
+ irc_net_sup:remove_object_sup(Supervisor),
+
+ NewState = {irc_state, Instance, Config, Joined, Socket, Buffer},
+ error_logger:info_msg("New state is ~p~n", [NewState]),
+
+ {ok, NewState}.
send_command(Command) ->
gen_server:cast(self(), {send_command, Command}).
join_channel(Channel, State) ->
Command = #irc_command{command = "JOIN", middles = [Channel]},
send_command(Command),
+ add_amqp_listener(Channel, State).
+
+add_amqp_listener(Channel, State) ->
#irc_state{object_sup = ObjectSup,
instance = Instance
} = State,