mirror of
https://github.com/processone/ejabberd.git
synced 2024-06-12 21:52:07 +02:00
Attach mod_muc_room processes to a supervisor
This commit is contained in:
parent
1fe1322bc1
commit
87b8344ede
|
@ -128,10 +128,8 @@ start(Host, Opts) ->
|
||||||
|
|
||||||
stop(Host) ->
|
stop(Host) ->
|
||||||
Proc = mod_muc_sup:procname(Host),
|
Proc = mod_muc_sup:procname(Host),
|
||||||
Rooms = shutdown_rooms(Host),
|
|
||||||
supervisor:terminate_child(ejabberd_gen_mod_sup, Proc),
|
supervisor:terminate_child(ejabberd_gen_mod_sup, Proc),
|
||||||
supervisor:delete_child(ejabberd_gen_mod_sup, Proc),
|
supervisor:delete_child(ejabberd_gen_mod_sup, Proc).
|
||||||
{wait, Rooms}.
|
|
||||||
|
|
||||||
-spec reload(binary(), gen_mod:opts(), gen_mod:opts()) -> ok.
|
-spec reload(binary(), gen_mod:opts(), gen_mod:opts()) -> ok.
|
||||||
reload(ServerHost, NewOpts, OldOpts) ->
|
reload(ServerHost, NewOpts, OldOpts) ->
|
||||||
|
@ -517,7 +515,7 @@ route_to_room(Packet, ServerHost) ->
|
||||||
ejabberd_router:route_error(Packet, Err);
|
ejabberd_router:route_error(Packet, Err);
|
||||||
StartType ->
|
StartType ->
|
||||||
case load_room(RMod, Host, ServerHost, Room) of
|
case load_room(RMod, Host, ServerHost, Room) of
|
||||||
error when StartType == start ->
|
{error, notfound} when StartType == start ->
|
||||||
case check_create_room(ServerHost, Host, Room, From) of
|
case check_create_room(ServerHost, Host, Room, From) of
|
||||||
true ->
|
true ->
|
||||||
case start_new_room(RMod, Host, ServerHost, Room, From, Nick) of
|
case start_new_room(RMod, Host, ServerHost, Room, From, Nick) of
|
||||||
|
@ -533,11 +531,14 @@ route_to_room(Packet, ServerHost) ->
|
||||||
Err = xmpp:err_forbidden(ErrText, Lang),
|
Err = xmpp:err_forbidden(ErrText, Lang),
|
||||||
ejabberd_router:route_error(Packet, Err)
|
ejabberd_router:route_error(Packet, Err)
|
||||||
end;
|
end;
|
||||||
error ->
|
{error, notfound} ->
|
||||||
Lang = xmpp:get_lang(Packet),
|
Lang = xmpp:get_lang(Packet),
|
||||||
ErrText = ?T("Conference room does not exist"),
|
ErrText = ?T("Conference room does not exist"),
|
||||||
Err = xmpp:err_item_not_found(ErrText, Lang),
|
Err = xmpp:err_item_not_found(ErrText, Lang),
|
||||||
ejabberd_router:route_error(Packet, Err);
|
ejabberd_router:route_error(Packet, Err);
|
||||||
|
{error, _} ->
|
||||||
|
Err = xmpp:err_internal_server_error(),
|
||||||
|
ejabberd_router:route_error(Packet, Err);
|
||||||
{ok, Pid2} ->
|
{ok, Pid2} ->
|
||||||
mod_muc_room:route(Pid2, Packet)
|
mod_muc_room:route(Pid2, Packet)
|
||||||
end
|
end
|
||||||
|
@ -774,17 +775,19 @@ load_permanent_rooms(Hosts, ServerHost, Opts) ->
|
||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec load_room(module(), binary(), binary(), binary()) -> {ok, pid()} |
|
||||||
|
{error, notfound | term()}.
|
||||||
load_room(RMod, Host, ServerHost, Room) ->
|
load_room(RMod, Host, ServerHost, Room) ->
|
||||||
case restore_room(ServerHost, Host, Room) of
|
case restore_room(ServerHost, Host, Room) of
|
||||||
error ->
|
error ->
|
||||||
error;
|
{error, notfound};
|
||||||
Opts0 ->
|
Opts0 ->
|
||||||
case proplists:get_bool(persistent, Opts0) of
|
case proplists:get_bool(persistent, Opts0) of
|
||||||
true ->
|
true ->
|
||||||
?DEBUG("Restore room: ~s", [Room]),
|
?DEBUG("Restore room: ~s", [Room]),
|
||||||
start_room(RMod, Host, ServerHost, Room, Opts0);
|
start_room(RMod, Host, ServerHost, Room, Opts0);
|
||||||
_ ->
|
_ ->
|
||||||
error
|
{error, notfound}
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
start_link/8,
|
start_link/8,
|
||||||
start/10,
|
start/10,
|
||||||
start/8,
|
start/8,
|
||||||
|
supervisor/1,
|
||||||
get_role/2,
|
get_role/2,
|
||||||
get_affiliation/2,
|
get_affiliation/2,
|
||||||
is_occupant_or_admin/2,
|
is_occupant_or_admin/2,
|
||||||
|
@ -113,17 +114,19 @@
|
||||||
{ok, pid()} | {error, any()}.
|
{ok, pid()} | {error, any()}.
|
||||||
start(Host, ServerHost, Access, Room, HistorySize, RoomShaper,
|
start(Host, ServerHost, Access, Room, HistorySize, RoomShaper,
|
||||||
Creator, Nick, DefRoomOpts, QueueType) ->
|
Creator, Nick, DefRoomOpts, QueueType) ->
|
||||||
p1_fsm:start(?MODULE, [Host, ServerHost, Access, Room, HistorySize,
|
supervisor:start_child(
|
||||||
RoomShaper, Creator, Nick, DefRoomOpts, QueueType],
|
supervisor(ServerHost),
|
||||||
?FSMOPTS).
|
[Host, ServerHost, Access, Room, HistorySize,
|
||||||
|
RoomShaper, Creator, Nick, DefRoomOpts, QueueType]).
|
||||||
|
|
||||||
-spec start(binary(), binary(), mod_muc:access(), binary(), non_neg_integer(),
|
-spec start(binary(), binary(), mod_muc:access(), binary(), non_neg_integer(),
|
||||||
atom(), [{atom(), term()}], ram | file) ->
|
atom(), [{atom(), term()}], ram | file) ->
|
||||||
{ok, pid()} | {error, any()}.
|
{ok, pid()} | {error, any()}.
|
||||||
start(Host, ServerHost, Access, Room, HistorySize, RoomShaper, Opts, QueueType) ->
|
start(Host, ServerHost, Access, Room, HistorySize, RoomShaper, Opts, QueueType) ->
|
||||||
p1_fsm:start(?MODULE, [Host, ServerHost, Access, Room, HistorySize,
|
supervisor:start_child(
|
||||||
RoomShaper, Opts, QueueType],
|
supervisor(ServerHost),
|
||||||
?FSMOPTS).
|
[Host, ServerHost, Access, Room, HistorySize,
|
||||||
|
RoomShaper, Opts, QueueType]).
|
||||||
|
|
||||||
-spec start_link(binary(), binary(), mod_muc:access(), binary(), non_neg_integer(),
|
-spec start_link(binary(), binary(), mod_muc:access(), binary(), non_neg_integer(),
|
||||||
atom(), jid(), binary(), [{atom(), term()}], ram | file) ->
|
atom(), jid(), binary(), [{atom(), term()}], ram | file) ->
|
||||||
|
@ -142,6 +145,10 @@ start_link(Host, ServerHost, Access, Room, HistorySize, RoomShaper, Opts, QueueT
|
||||||
RoomShaper, Opts, QueueType],
|
RoomShaper, Opts, QueueType],
|
||||||
?FSMOPTS).
|
?FSMOPTS).
|
||||||
|
|
||||||
|
-spec supervisor(binary()) -> atom().
|
||||||
|
supervisor(Host) ->
|
||||||
|
gen_mod:get_module_proc(Host, mod_muc_room_sup).
|
||||||
|
|
||||||
-spec destroy(pid()) -> ok.
|
-spec destroy(pid()) -> ok.
|
||||||
destroy(Pid) ->
|
destroy(Pid) ->
|
||||||
p1_fsm:send_all_state_event(Pid, destroy).
|
p1_fsm:send_all_state_event(Pid, destroy).
|
||||||
|
|
|
@ -52,15 +52,26 @@ procname(Host) ->
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
init([Host, Opts]) ->
|
init([Host, Opts]) ->
|
||||||
Cores = erlang:system_info(logical_processors),
|
Cores = erlang:system_info(logical_processors),
|
||||||
Specs = [#{id => mod_muc:procname(Host, I),
|
Specs = lists:foldl(
|
||||||
start => {mod_muc, start_link, [Host, Opts, I]},
|
fun(I, Acc) ->
|
||||||
restart => permanent,
|
[#{id => mod_muc:procname(Host, I),
|
||||||
shutdown => timer:minutes(1),
|
start => {mod_muc, start_link, [Host, Opts, I]},
|
||||||
type => worker,
|
restart => permanent,
|
||||||
modules => [mod_muc]}
|
shutdown => timer:minutes(1),
|
||||||
|| I <- lists:seq(1, Cores)],
|
type => worker,
|
||||||
|
modules => [mod_muc]}|Acc]
|
||||||
|
end, [room_sup_spec(Host)], lists:seq(1, Cores)),
|
||||||
{ok, {{one_for_one, 10*Cores, 1}, Specs}}.
|
{ok, {{one_for_one, 10*Cores, 1}, Specs}}.
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
-spec room_sup_spec(binary()) -> supervisor:child_spec().
|
||||||
|
room_sup_spec(Host) ->
|
||||||
|
Name = mod_muc_room:supervisor(Host),
|
||||||
|
#{id => Name,
|
||||||
|
start => {ejabberd_tmp_sup, start_link, [Name, mod_muc_room]},
|
||||||
|
restart => permanent,
|
||||||
|
shutdown => infinity,
|
||||||
|
type => supervisor,
|
||||||
|
modules => [ejabberd_tmp_sup]}.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user