]> granicus.if.org Git - ejabberd/commitdiff
Remove handle_event/1 callback
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 16 Jan 2017 08:34:49 +0000 (11:34 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 16 Jan 2017 08:34:49 +0000 (11:34 +0300)
src/ejabberd_router.erl
src/ejabberd_router_mnesia.erl
src/mod_muc.erl
src/mod_muc_mnesia.erl
src/mod_muc_riak.erl
src/mod_muc_sql.erl

index eeb9b45b0417ae58234ce2b8f450140729464145..879a88c0ef1333d7b3d8d04788c688aaa0186f9c 100644 (file)
@@ -65,7 +65,6 @@
 -callback is_my_route(binary()) -> boolean().
 -callback is_my_host(binary()) -> boolean().
 -callback get_all_routes() -> [binary()].
--callback handle_event(term()) -> any().
 
 -record(state, {}).
 
@@ -251,9 +250,8 @@ handle_info({route, From, To, Packet}, State) ->
       _ -> ok
     end,
     {noreply, State};
-handle_info(Event, State) ->
-    Mod = get_backend(),
-    Mod:handle_event(Event),
+handle_info(Info, State) ->
+    ?ERROR_MSG("unexpected info: ~p", [Info]),
     {noreply, State}.
 
 terminate(_Reason, _State) ->
index f53541f24201b394a84d1f0c48efb0b8b609f492..d9946cef54a8147fa6ae29954121e9e9eb38f3a2 100644 (file)
@@ -8,32 +8,32 @@
 %%%-------------------------------------------------------------------
 -module(ejabberd_router_mnesia).
 -behaviour(ejabberd_router).
+-behaviour(gen_server).
 
 %% API
 -export([init/0, register_route/4, unregister_route/2, find_routes/1,
-        host_of_route/1, is_my_route/1, is_my_host/1, get_all_routes/0,
-        handle_event/1]).
+        host_of_route/1, is_my_route/1, is_my_host/1, get_all_routes/0]).
+%% gen_server callbacks
+-export([init/1, handle_cast/2, handle_call/3, handle_info/2,
+        terminate/2, code_change/3]).
 
 -include("ejabberd.hrl").
 -include("ejabberd_router.hrl").
 -include("logger.hrl").
 -include_lib("stdlib/include/ms_transform.hrl").
 
+-record(state, {}).
+
 %%%===================================================================
 %%% API
 %%%===================================================================
 init() ->
-    update_tables(),
-    ejabberd_mnesia:create(?MODULE, route,
-                          [{ram_copies, [node()]},
-                           {type, bag},
-                           {attributes, record_info(fields, route)}]),
-    mnesia:add_table_copy(route, node(), ram_copies),
-    mnesia:subscribe({table, route, simple}),
-    lists:foreach(
-      fun (Pid) -> erlang:monitor(process, Pid) end,
-      mnesia:dirty_select(route,
-                         [{{route, '_', '$1', '_'}, [], ['$1']}])).
+    case gen_server:start_link({local, ?MODULE}, ?MODULE, [], []) of
+       {ok, _Pid} ->
+           ok;
+       Err ->
+           Err
+    end.
 
 register_route(Domain, ServerHost, LocalHint, undefined) ->
     F = fun () ->
@@ -135,10 +135,35 @@ get_all_routes() ->
              when Domain /= ServerHost -> Domain
        end)).
 
-handle_event({mnesia_table_event,
-             {write, #route{pid = Pid}, _ActivityId}}) ->
-    erlang:monitor(process, Pid);
-handle_event({'DOWN', _Ref, _Type, Pid, _Info}) ->
+%%%===================================================================
+%%% gen_server callbacks
+%%%===================================================================
+init([]) ->
+    update_tables(),
+    ejabberd_mnesia:create(?MODULE, route,
+                          [{ram_copies, [node()]},
+                           {type, bag},
+                           {attributes, record_info(fields, route)}]),
+    mnesia:add_table_copy(route, node(), ram_copies),
+    mnesia:subscribe({table, route, simple}),
+    lists:foreach(
+      fun (Pid) -> erlang:monitor(process, Pid) end,
+      mnesia:dirty_select(route,
+                         [{{route, '_', '$1', '_'}, [], ['$1']}])),
+    {ok, #state{}}.
+
+handle_call(_Request, _From, State) ->
+    Reply = ok,
+    {reply, Reply, State}.
+
+handle_cast(_Msg, State) ->
+    {noreply, State}.
+
+handle_info({mnesia_table_event,
+            {write, #route{pid = Pid}, _ActivityId}}, State) ->
+    erlang:monitor(process, Pid),
+    {noreply, State};
+handle_info({'DOWN', _Ref, _Type, Pid, _Info}, State) ->
     F = fun () ->
                Es = mnesia:select(route,
                                   [{#route{pid = Pid, _ = '_'}, [], ['$_']}]),
@@ -158,10 +183,18 @@ handle_event({'DOWN', _Ref, _Type, Pid, _Info}) ->
                          end
                  end, Es)
        end,
-    transaction(F);
-handle_event(_Event) ->
+    transaction(F),
+    {noreply, State};
+handle_info(Info, State) ->
+    ?ERROR_MSG("unexpected info: ~p", [Info]),
+    {noreply, State}.
+
+terminate(_Reason, _State) ->
     ok.
 
+code_change(_OldVsn, State, _Extra) ->
+    {ok, State}.
+
 %%%===================================================================
 %%% Internal functions
 %%%===================================================================
index 149c25f4622a44b8de643f654f3b2befe53551f3..e75fb3893d23d3e70032c314c8e923862aa1392d 100644 (file)
 -callback unregister_online_user(ljid(), binary(), binary()) -> any().
 -callback count_online_rooms_by_user(binary(), binary()) -> non_neg_integer().
 -callback get_online_rooms_by_user(binary(), binary()) -> [{binary(), binary()}].
--callback handle_event(term()) -> any().
 
 %%====================================================================
 %% API
@@ -377,9 +376,8 @@ handle_info({room_destroyed, {Room, Host}, Pid}, State) ->
     RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
     RMod:unregister_online_room(Room, Host, Pid),
     {noreply, State};
-handle_info(Event, #state{server_host = LServer} = State) ->
-    RMod = gen_mod:ram_db_mod(LServer, ?MODULE),
-    RMod:handle_event(Event),
+handle_info(Info, State) ->
+    ?ERROR_MSG("unexpected info: ~p", [Info]),
     {noreply, State}.
 
 terminate(_Reason, #state{host = MyHost}) ->
index 0552184b4b49da36b56ccf9795c803ee0e869ec0..14c048863104f606d61aa8d27e6ca756cb94e681 100644 (file)
 -export([register_online_room/3, unregister_online_room/3, find_online_room/2,
         get_online_rooms/2, count_online_rooms/1, rsm_supported/0,
         register_online_user/3, unregister_online_user/3,
-        count_online_rooms_by_user/2, get_online_rooms_by_user/2,
-        handle_event/1]).
+        count_online_rooms_by_user/2, get_online_rooms_by_user/2]).
 -export([set_affiliation/6, set_affiliations/4, get_affiliation/5,
         get_affiliations/3, search_affiliation/4]).
+%% gen_server callbacks
+-export([init/1, handle_cast/2, handle_call/3, handle_info/2,
+        terminate/2, code_change/3]).
 
 -include("mod_muc.hrl").
 -include("logger.hrl").
 -include("xmpp.hrl").
 -include_lib("stdlib/include/ms_transform.hrl").
 
+-record(state, {}).
+
 %%%===================================================================
 %%% API
 %%%===================================================================
 init(Host, Opts) ->
-    MyHost = proplists:get_value(host, Opts),
-    case gen_mod:db_mod(Host, Opts, mod_muc) of
-       ?MODULE ->
-           ejabberd_mnesia:create(?MODULE, muc_room,
-                                  [{disc_copies, [node()]},
-                                   {attributes,
-                                    record_info(fields, muc_room)}]),
-           ejabberd_mnesia:create(?MODULE, muc_registered,
-                                  [{disc_copies, [node()]},
-                                   {attributes,
-                                    record_info(fields, muc_registered)}]),
-           update_tables(MyHost),
-           mnesia:add_table_index(muc_registered, nick);
-       _ ->
-           ok
-    end,
-    case gen_mod:ram_db_mod(Host, Opts, mod_muc) of
-       ?MODULE ->
-           update_muc_online_table(),
-           ejabberd_mnesia:create(?MODULE, muc_online_room,
-                                  [{ram_copies, [node()]},
-                                   {type, ordered_set},
-                                   {attributes,
-                                    record_info(fields, muc_online_room)}]),
-           mnesia:add_table_copy(muc_online_room, node(), ram_copies),
-           catch ets:new(muc_online_users,
-                         [bag, named_table, public, {keypos, 2}]),
-           clean_table_from_bad_node(node(), MyHost),
-           mnesia:subscribe(system);
-       _ ->
-           ok
+    case gen_server:start_link({local, ?MODULE}, ?MODULE, [Host, Opts], []) of
+       {ok, _Pid} ->
+           ok;
+       Err ->
+           Err
     end.
 
 store_room(_LServer, Host, Name, Opts) ->
@@ -247,11 +225,6 @@ get_online_rooms(Action, Key, Host, Count, Max, Items) ->
            Items
     end.
 
-handle_event({mnesia_system_event, {mnesia_down, Node}}) ->
-    clean_table_from_bad_node(Node);
-handle_event(_) ->
-    ok.
-
 rsm_supported() ->
     true.
 
@@ -294,6 +267,64 @@ import(_LServer, <<"muc_registered">>,
       #muc_registered{us_host = {{U, S}, RoomHost},
                       nick = Nick}).
 
+%%%===================================================================
+%%% gen_server callbacks
+%%%===================================================================
+init([Host, Opts]) ->
+    MyHost = proplists:get_value(host, Opts),
+    case gen_mod:db_mod(Host, Opts, mod_muc) of
+       ?MODULE ->
+           ejabberd_mnesia:create(?MODULE, muc_room,
+                                  [{disc_copies, [node()]},
+                                   {attributes,
+                                    record_info(fields, muc_room)}]),
+           ejabberd_mnesia:create(?MODULE, muc_registered,
+                                  [{disc_copies, [node()]},
+                                   {attributes,
+                                    record_info(fields, muc_registered)}]),
+           update_tables(MyHost),
+           mnesia:add_table_index(muc_registered, nick);
+       _ ->
+           ok
+    end,
+    case gen_mod:ram_db_mod(Host, Opts, mod_muc) of
+       ?MODULE ->
+           update_muc_online_table(),
+           ejabberd_mnesia:create(?MODULE, muc_online_room,
+                                  [{ram_copies, [node()]},
+                                   {type, ordered_set},
+                                   {attributes,
+                                    record_info(fields, muc_online_room)}]),
+           mnesia:add_table_copy(muc_online_room, node(), ram_copies),
+           catch ets:new(muc_online_users,
+                         [bag, named_table, public, {keypos, 2}]),
+           clean_table_from_bad_node(node(), MyHost),
+           mnesia:subscribe(system);
+       _ ->
+           ok
+    end,
+    {ok, #state{}}.
+
+handle_call(_Request, _From, State) ->
+    Reply = ok,
+    {reply, Reply, State}.
+
+handle_cast(_Msg, State) ->
+    {noreply, State}.
+
+handle_info({mnesia_system_event, {mnesia_down, Node}}, State) ->
+    clean_table_from_bad_node(Node),
+    {noreply, State};
+handle_info(Info, State) ->
+    ?ERROR_MSG("unexpected info: ~p", [Info]),
+    {noreply, State}.
+
+terminate(_Reason, _State) ->
+    ok.
+
+code_change(_OldVsn, State, _Extra) ->
+    {ok, State}.
+
 %%%===================================================================
 %%% Internal functions
 %%%===================================================================
index f53d945fe80a71f120e1ea2d7a8271d5bb7e0c21..47e50f86cbc475836d4decd94f5c23ecf2355d0b 100644 (file)
@@ -17,8 +17,7 @@
 -export([register_online_room/3, unregister_online_room/3, find_online_room/2,
         get_online_rooms/2, count_online_rooms/1, rsm_supported/0,
         register_online_user/3, unregister_online_user/3,
-        count_online_rooms_by_user/2, get_online_rooms_by_user/2,
-        handle_event/1]).
+        count_online_rooms_by_user/2, get_online_rooms_by_user/2]).
 -export([set_affiliation/6, set_affiliations/4, get_affiliation/5,
         get_affiliations/3, search_affiliation/4]).
 
@@ -140,9 +139,6 @@ count_online_rooms(_) ->
 get_online_rooms(_, _) ->
     erlang:error(not_implemented).
 
-handle_event(_) ->
-    ok.
-
 rsm_supported() ->
     false.
 
index 08b8bf9e0b4b5a603daaef9ea901bb5e5b6d4826..6a37451c045ac75b45fd5c144afc2c79ffec00de 100644 (file)
@@ -20,8 +20,7 @@
 -export([register_online_room/3, unregister_online_room/3, find_online_room/2,
         get_online_rooms/2, count_online_rooms/1, rsm_supported/0,
         register_online_user/3, unregister_online_user/3,
-        count_online_rooms_by_user/2, get_online_rooms_by_user/2,
-        handle_event/1]).
+        count_online_rooms_by_user/2, get_online_rooms_by_user/2]).
 -export([set_affiliation/6, set_affiliations/4, get_affiliation/5,
         get_affiliations/3, search_affiliation/4]).
 
@@ -165,9 +164,6 @@ count_online_rooms(_) ->
 get_online_rooms(_, _) ->
     erlang:error(not_implemented).
 
-handle_event(_) ->
-    ok.
-
 rsm_supported() ->
     false.