Skip to content

Commit

Permalink
Changing init_per_host_type in mongoose_backend module
Browse files Browse the repository at this point in the history
  • Loading branch information
Janusz Jakubiec authored and Janusz Jakubiec committed Oct 15, 2021
1 parent 926579c commit 4d95223
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
15 changes: 7 additions & 8 deletions src/gen_mod.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
start_module/3,
start_backend_module/2,
start_backend_module/3,
get_backend_module/3,
stop_module/2,
stop_module_keep_config/2,
reload_module/3,
Expand Down Expand Up @@ -225,13 +224,13 @@ start_backend_module(Module, Opts, TrackedFuncs) ->
Backend = gen_mod:get_opt(backend, Opts, mnesia),
backend_module:create(Module, Backend, TrackedFuncs).

-spec get_backend_module(host_type(), module(), atom()) -> module().
get_backend_module(HostType, Module, DefaultBackend) ->
Backend = get_module_opt(HostType, Module, backend, DefaultBackend),
backend_module(Module, Backend).

backend_module(Module, Backend) ->
list_to_atom(atom_to_list(Module) ++ "_" ++ atom_to_list(Backend)).
%-spec get_backend_module(host_type(), module(), atom()) -> module().
%get_backend_module(HostType, Module, DefaultBackend) ->
% Backend = get_module_opt(HostType, Module, backend, DefaultBackend),
% backend_module(Module, Backend).
%
%backend_module(Module, Backend) ->
% list_to_atom(atom_to_list(Module) ++ "_" ++ atom_to_list(Backend)).

-spec is_app_running(_) -> boolean().
is_app_running(AppName) ->
Expand Down
2 changes: 1 addition & 1 deletion src/mod_auth_token.erl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
-spec start(mongooseim:host_type(), gen_mod:module_opts()) -> ok.
start(HostType, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts, no_queue),
mod_auth_token_backend:start(HostType),
mod_auth_token_backend:start(HostType, Opts),
ejabberd_hooks:add(hooks(HostType)),
gen_iq_handler:add_iq_handler_for_domain(
HostType, ?NS_ESL_TOKEN_AUTH, ejabberd_sm,
Expand Down
8 changes: 4 additions & 4 deletions src/mod_auth_token_backend.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
%%% @end
%%%----------------------------------------------------------------------
-module(mod_auth_token_backend).
-export([start/1,
-export([start/2,
revoke/2,
get_valid_sequence_number/2,
clean_tokens/2]).
Expand All @@ -26,9 +26,9 @@
%% ----------------------------------------------------------------------
%% API Functions

-spec start(HostType :: mongooseim:host_type()) -> ok.
start(HostType) ->
mongoose_backend:init_per_host_type(HostType, ?MAIN_MODULE, [], rdbms),
-spec start(HostType :: mongooseim:host_type(), Opts :: gen_mod:module_opts()) -> ok.
start(HostType, Opts) ->
mongoose_backend:init_per_host_type(HostType, ?MAIN_MODULE, [], [{backend, rdbms} | Opts]),
Args = [HostType],
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

Expand Down
2 changes: 1 addition & 1 deletion src/mod_last_backend.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
-spec init(mod_last:host_type(), gen_mod:module_opts()) -> ok.
init(HostType, Opts) ->
TrackedFuns = [get_last, set_last_info],
mongoose_backend:init_per_host_type(HostType, ?MAIN_MODULE, TrackedFuns),
mongoose_backend:init_per_host_type(HostType, ?MAIN_MODULE, TrackedFuns, Opts),
Args = [HostType, Opts],
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

Expand Down
2 changes: 1 addition & 1 deletion src/mod_private_backend.erl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
Opts :: list().
init(HostType, Opts) ->
TrackedFuns = [multi_get_data, multi_set_data],
mongoose_backend:init_per_host_type(HostType, ?MAIN_MODULE, TrackedFuns),
mongoose_backend:init_per_host_type(HostType, ?MAIN_MODULE, TrackedFuns, Opts),
Args = [HostType, Opts],
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

Expand Down
21 changes: 9 additions & 12 deletions src/mongoose_backend.erl
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
-module(mongoose_backend).

%% API
-export([init_per_host_type/3,
init_per_host_type/4,
-export([init_per_host_type/4,
call/4,
call_tracked/4]).

Expand All @@ -17,22 +16,20 @@
-type main_module() :: module().
-type backend_module() :: module().

-spec init_per_host_type(HostType :: mongooseim:host_type(),
MainModule :: main_module(),
TrackedFuns :: [function_name()]) -> ok.
init_per_host_type(HostType, MainModule, TrackedFuns) ->
init_per_host_type(HostType, MainModule, TrackedFuns, mnesia).

-spec init_per_host_type(HostType :: mongooseim:host_type(),
MainModule :: main_module(),
TrackedFuns :: [function_name()],
DefaultBackend :: atom()) -> ok.
init_per_host_type(HostType, MainModule, TrackedFuns, DefaultBackend) ->
Opts :: gen_mod:module_opts()) -> ok.
init_per_host_type(HostType, MainModule, TrackedFuns, Opts) ->
ensure_backend_metrics(MainModule, TrackedFuns),
Backend = gen_mod:get_backend_module(HostType, MainModule, DefaultBackend),
persist_backend_name(HostType, MainModule, Backend),
Backend = gen_mod:get_module_opt(HostType, MainModule, Opts, mnesia),
BackendModule = backend_module(MainModule, Backend),
persist_backend_name(HostType, MainModule, BackendModule),
ok.

backend_module(Module, Backend) ->
list_to_atom(atom_to_list(Module) ++ "_" ++ atom_to_list(Backend)).

call_metric(MainModule, FunName) ->
[backends, MainModule, calls, FunName].

Expand Down

0 comments on commit 4d95223

Please sign in to comment.