stop/1, emqttd:seed_now/0

This commit is contained in:
Feng 2016-01-24 13:43:42 +08:00
parent 0b686da281
commit 8934d8ecad
1 changed files with 11 additions and 1 deletions

View File

@ -23,6 +23,7 @@
%%% %%%
%%% @author Feng Lee <feng@emqtt.io> %%% @author Feng Lee <feng@emqtt.io>
%%%----------------------------------------------------------------------------- %%%-----------------------------------------------------------------------------
-module(emqttd_router). -module(emqttd_router).
-behaviour(gen_server2). -behaviour(gen_server2).
@ -44,6 +45,9 @@
%% Batch API %% Batch API
-export([add_routes/2, delete_routes/2]). -export([add_routes/2, delete_routes/2]).
%% For Test
-export([stop/1]).
%% gen_server Callbacks %% gen_server Callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]). terminate/2, code_change/3]).
@ -141,6 +145,9 @@ slice(Topics) ->
pick(Topic) -> pick(Topic) ->
gproc_pool:pick_worker(router, Topic). gproc_pool:pick_worker(router, Topic).
stop(Id) when is_integer(Id) ->
gen_server2:call(emqttd:reg_name(?MODULE, Id), stop).
call(Router, Request) -> call(Router, Request) ->
gen_server2:call(Router, Request, infinity). gen_server2:call(Router, Request, infinity).
@ -154,7 +161,7 @@ init([Pool, Id, StatsFun, Opts]) ->
?GPROC_POOL(join, Pool, Id), ?GPROC_POOL(join, Pool, Id),
random:seed(erlang:now()), emqttd:seed_now(),
AgingSecs = proplists:get_value(route_aging, Opts, 5), AgingSecs = proplists:get_value(route_aging, Opts, 5),
@ -168,6 +175,9 @@ init([Pool, Id, StatsFun, Opts]) ->
start_tick(Secs) -> start_tick(Secs) ->
timer:send_interval(timer:seconds(Secs), {clean, aged}). timer:send_interval(timer:seconds(Secs), {clean, aged}).
handle_call(stop, _From, State) ->
{stop, normal, ok, State};
handle_call({add_route, Topic, Pid}, _From, State) -> handle_call({add_route, Topic, Pid}, _From, State) ->
ets:insert(route, {Topic, Pid}), ets:insert(route, {Topic, Pid}),
{reply, ok, setstats(State)}; {reply, ok, setstats(State)};