|
|
@@ -19,7 +19,6 @@
|
|
|
-behaviour(gen_server).
|
|
|
|
|
|
-include("emqx_retainer.hrl").
|
|
|
--include_lib("emqx/include/emqx.hrl").
|
|
|
-include_lib("emqx/include/logger.hrl").
|
|
|
-include_lib("emqx/include/emqx_hooks.hrl").
|
|
|
|
|
|
@@ -27,8 +26,7 @@
|
|
|
|
|
|
-export([
|
|
|
on_session_subscribed/4,
|
|
|
- on_message_publish/2,
|
|
|
- on_client_banned/1
|
|
|
+ on_message_publish/2
|
|
|
]).
|
|
|
|
|
|
-export([
|
|
|
@@ -41,7 +39,6 @@
|
|
|
get_expiry_time/1,
|
|
|
update_config/1,
|
|
|
clean/0,
|
|
|
- clean_by_clientid/1,
|
|
|
delete/1,
|
|
|
page_read/3,
|
|
|
post_config_update/5,
|
|
|
@@ -83,7 +80,6 @@
|
|
|
-callback match_messages(context(), topic(), cursor()) -> {ok, list(), cursor()}.
|
|
|
-callback clear_expired(context()) -> ok.
|
|
|
-callback clean(context()) -> ok.
|
|
|
--callback clean_by_clientid(context(), emqx_types:clientid()) -> ok.
|
|
|
-callback size(context()) -> non_neg_integer().
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
@@ -122,11 +118,6 @@ on_message_publish(Msg = #message{flags = #{retain := true}}, Context) ->
|
|
|
on_message_publish(Msg, _) ->
|
|
|
{ok, Msg}.
|
|
|
|
|
|
-on_client_banned(#banned{who = {clientid, ClientId}}) ->
|
|
|
- clean_by_clientid(ClientId);
|
|
|
-on_client_banned(_) ->
|
|
|
- ok.
|
|
|
-
|
|
|
%%--------------------------------------------------------------------
|
|
|
%% APIs
|
|
|
%%--------------------------------------------------------------------
|
|
|
@@ -160,9 +151,6 @@ update_config(Conf) ->
|
|
|
clean() ->
|
|
|
call(?FUNCTION_NAME).
|
|
|
|
|
|
-clean_by_clientid(ClientId) ->
|
|
|
- call({?FUNCTION_NAME, ClientId}).
|
|
|
-
|
|
|
delete(Topic) ->
|
|
|
call({?FUNCTION_NAME, Topic}).
|
|
|
|
|
|
@@ -219,9 +207,6 @@ handle_call({update_config, NewConf, OldConf}, _, State) ->
|
|
|
handle_call(clean, _, #{context := Context} = State) ->
|
|
|
clean(Context),
|
|
|
{reply, ok, State};
|
|
|
-handle_call({clean_by_clientid, ClientId}, _, #{context := Context} = State) ->
|
|
|
- clean_by_clientid(Context, ClientId),
|
|
|
- {reply, ok, State};
|
|
|
handle_call({delete, Topic}, _, #{context := Context} = State) ->
|
|
|
delete_message(Context, Topic),
|
|
|
{reply, ok, State};
|
|
|
@@ -313,11 +298,6 @@ clean(Context) ->
|
|
|
Mod = get_backend_module(),
|
|
|
Mod:clean(Context).
|
|
|
|
|
|
--spec clean_by_clientid(context(), emqx_types:clientid()) -> ok.
|
|
|
-clean_by_clientid(Context, ClientId) ->
|
|
|
- Mod = get_backend_module(),
|
|
|
- Mod:clean_by_clientid(Context, ClientId).
|
|
|
-
|
|
|
-spec update_config(state(), hocons:config(), hocons:config()) -> state().
|
|
|
update_config(State, Conf, OldConf) ->
|
|
|
update_config(
|
|
|
@@ -453,13 +433,11 @@ load(Context) ->
|
|
|
'session.subscribed', {?MODULE, on_session_subscribed, [Context]}, ?HP_RETAINER
|
|
|
),
|
|
|
ok = emqx_hooks:put('message.publish', {?MODULE, on_message_publish, [Context]}, ?HP_RETAINER),
|
|
|
- ok = emqx_hooks:put('client.banned', {?MODULE, on_client_banned, []}, ?HP_LOWEST),
|
|
|
emqx_stats:update_interval(emqx_retainer_stats, fun ?MODULE:stats_fun/0),
|
|
|
ok.
|
|
|
|
|
|
unload() ->
|
|
|
ok = emqx_hooks:del('message.publish', {?MODULE, on_message_publish}),
|
|
|
ok = emqx_hooks:del('session.subscribed', {?MODULE, on_session_subscribed}),
|
|
|
- ok = emqx_hooks:del('client.banned', {?MODULE, on_client_banned}),
|
|
|
emqx_stats:cancel_update(emqx_retainer_stats),
|
|
|
ok.
|