Update comment and format code
This commit is contained in:
parent
93c263741c
commit
31e26ec5df
|
@ -4,8 +4,7 @@
|
||||||
{require_min_otp_vsn, "R20"}.
|
{require_min_otp_vsn, "R20"}.
|
||||||
|
|
||||||
%warnings_as_errors, warn_untyped_record,
|
%warnings_as_errors, warn_untyped_record,
|
||||||
{erl_opts, [
|
{erl_opts, [warn_export_all,
|
||||||
warn_export_all,
|
|
||||||
warn_unused_import,
|
warn_unused_import,
|
||||||
{i, "include"},
|
{i, "include"},
|
||||||
{src_dirs, ["src"]}
|
{src_dirs, ["src"]}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
%%
|
%%
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -11,6 +12,7 @@
|
||||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
%% See the License for the specific language governing permissions and
|
%% See the License for the specific language governing permissions and
|
||||||
%% limitations under the License.
|
%% limitations under the License.
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
-module(ecpool).
|
-module(ecpool).
|
||||||
|
|
||||||
|
@ -19,6 +21,13 @@
|
||||||
set_reconnect_callback/2,
|
set_reconnect_callback/2,
|
||||||
name/1, workers/1]).
|
name/1, workers/1]).
|
||||||
|
|
||||||
|
-export_type([pool_name/0,
|
||||||
|
pool_type/0,
|
||||||
|
option/0
|
||||||
|
]).
|
||||||
|
|
||||||
|
-type pool_name() :: term().
|
||||||
|
|
||||||
-type pool_type() :: random | hash | round_robin.
|
-type pool_type() :: random | hash | round_robin.
|
||||||
|
|
||||||
-type reconn_callback() :: {fun((pid()) -> term())}.
|
-type reconn_callback() :: {fun((pid()) -> term())}.
|
||||||
|
@ -29,11 +38,6 @@
|
||||||
| {on_reconnect, reconn_callback()}
|
| {on_reconnect, reconn_callback()}
|
||||||
| tuple().
|
| tuple().
|
||||||
|
|
||||||
-export_type([pool_name/0,
|
|
||||||
pool_type/0,
|
|
||||||
option/0
|
|
||||||
]).
|
|
||||||
|
|
||||||
pool_spec(ChildId, Pool, Mod, Opts) ->
|
pool_spec(ChildId, Pool, Mod, Opts) ->
|
||||||
#{id => ChildId,
|
#{id => ChildId,
|
||||||
start => {?MODULE, start_pool, [Pool, Mod, Opts]},
|
start => {?MODULE, start_pool, [Pool, Mod, Opts]},
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
%%
|
%%
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -11,6 +12,7 @@
|
||||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
%% See the License for the specific language governing permissions and
|
%% See the License for the specific language governing permissions and
|
||||||
%% limitations under the License.
|
%% limitations under the License.
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
-module(ecpool_app).
|
-module(ecpool_app).
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
%%
|
%%
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -11,6 +12,7 @@
|
||||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
%% See the License for the specific language governing permissions and
|
%% See the License for the specific language governing permissions and
|
||||||
%% limitations under the License.
|
%% limitations under the License.
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
-module(ecpool_pool).
|
-module(ecpool_pool).
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
%%
|
%%
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -11,6 +12,7 @@
|
||||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
%% See the License for the specific language governing permissions and
|
%% See the License for the specific language governing permissions and
|
||||||
%% limitations under the License.
|
%% limitations under the License.
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
-module(ecpool_pool_sup).
|
-module(ecpool_pool_sup).
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
%%
|
%%
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -11,6 +12,7 @@
|
||||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
%% See the License for the specific language governing permissions and
|
%% See the License for the specific language governing permissions and
|
||||||
%% limitations under the License.
|
%% limitations under the License.
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
-module(ecpool_sup).
|
-module(ecpool_sup).
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
%%
|
%%
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -11,6 +12,7 @@
|
||||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
%% See the License for the specific language governing permissions and
|
%% See the License for the specific language governing permissions and
|
||||||
%% limitations under the License.
|
%% limitations under the License.
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
-module(ecpool_worker).
|
-module(ecpool_worker).
|
||||||
|
|
||||||
|
@ -19,7 +21,7 @@
|
||||||
-export([start_link/4]).
|
-export([start_link/4]).
|
||||||
|
|
||||||
%% API Function Exports
|
%% API Function Exports
|
||||||
-export([start_link/4, client/1, is_connected/1, set_reconnect_callback/2]).
|
-export([client/1, is_connected/1, set_reconnect_callback/2]).
|
||||||
|
|
||||||
%% gen_server Function Exports
|
%% gen_server Function Exports
|
||||||
-export([init/1,
|
-export([init/1,
|
||||||
|
@ -121,8 +123,8 @@ handle_info({'EXIT', Pid, Reason}, State = #state{client = Pid, opts = Opts}) ->
|
||||||
reconnect_after(Secs, State)
|
reconnect_after(Secs, State)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
handle_info(reconnect, State = #state{opts = Opts, on_reconnect = OnReconnect}) ->
|
handle_info(reconnect, State = #state{pool = Pool, opts = Opts, on_reconnect = OnReconnect}) ->
|
||||||
case catch connect(State) of
|
try connect(State) of
|
||||||
{ok, Client} ->
|
{ok, Client} ->
|
||||||
handle_reconnect(Client, OnReconnect),
|
handle_reconnect(Client, OnReconnect),
|
||||||
{noreply, State#state{client = Client}};
|
{noreply, State#state{client = Client}};
|
||||||
|
@ -176,3 +178,7 @@ handle_reconnect(_, undefined) ->
|
||||||
ok;
|
ok;
|
||||||
handle_reconnect(Client, OnReconnect) ->
|
handle_reconnect(Client, OnReconnect) ->
|
||||||
OnReconnect(Client).
|
OnReconnect(Client).
|
||||||
|
|
||||||
|
maybe_apply(undefined, _) -> ok;
|
||||||
|
maybe_apply(Fun, Arg) -> erlang:apply(Fun, [Arg]).
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
%%
|
%%
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -11,6 +12,7 @@
|
||||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
%% See the License for the specific language governing permissions and
|
%% See the License for the specific language governing permissions and
|
||||||
%% limitations under the License.
|
%% limitations under the License.
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
-module(ecpool_worker_sup).
|
-module(ecpool_worker_sup).
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
%%
|
%%
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -11,6 +12,7 @@
|
||||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
%% See the License for the specific language governing permissions and
|
%% See the License for the specific language governing permissions and
|
||||||
%% limitations under the License.
|
%% limitations under the License.
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
-module(ecpool_SUITE).
|
-module(ecpool_SUITE).
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
%%
|
%%
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -11,6 +12,7 @@
|
||||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
%% See the License for the specific language governing permissions and
|
%% See the License for the specific language governing permissions and
|
||||||
%% limitations under the License.
|
%% limitations under the License.
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
-module(test_client).
|
-module(test_client).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue