From 31e26ec5dfec5a47e97fe5d03fd330a467dd407d Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 26 Aug 2019 13:56:41 +0800 Subject: [PATCH] Update comment and format code --- rebar.config | 3 +-- src/ecpool.erl | 14 +++++++++----- src/ecpool_app.erl | 2 ++ src/ecpool_pool.erl | 2 ++ src/ecpool_pool_sup.erl | 2 ++ src/ecpool_sup.erl | 2 ++ src/ecpool_worker.erl | 12 +++++++++--- src/ecpool_worker_sup.erl | 2 ++ test/ecpool_SUITE.erl | 2 ++ test/test_client.erl | 2 ++ 10 files changed, 33 insertions(+), 10 deletions(-) diff --git a/rebar.config b/rebar.config index f8f2879fe..fb70bfda2 100644 --- a/rebar.config +++ b/rebar.config @@ -4,8 +4,7 @@ {require_min_otp_vsn, "R20"}. %warnings_as_errors, warn_untyped_record, -{erl_opts, [ - warn_export_all, +{erl_opts, [warn_export_all, warn_unused_import, {i, "include"}, {src_dirs, ["src"]} diff --git a/src/ecpool.erl b/src/ecpool.erl index b929253cf..41e047993 100644 --- a/src/ecpool.erl +++ b/src/ecpool.erl @@ -1,3 +1,4 @@ +%%-------------------------------------------------------------------- %% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved. %% %% 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. %% See the License for the specific language governing permissions and %% limitations under the License. +%%-------------------------------------------------------------------- -module(ecpool). @@ -19,6 +21,13 @@ set_reconnect_callback/2, 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 reconn_callback() :: {fun((pid()) -> term())}. @@ -29,11 +38,6 @@ | {on_reconnect, reconn_callback()} | tuple(). --export_type([pool_name/0, - pool_type/0, - option/0 - ]). - pool_spec(ChildId, Pool, Mod, Opts) -> #{id => ChildId, start => {?MODULE, start_pool, [Pool, Mod, Opts]}, diff --git a/src/ecpool_app.erl b/src/ecpool_app.erl index 63463139a..b120c8738 100644 --- a/src/ecpool_app.erl +++ b/src/ecpool_app.erl @@ -1,3 +1,4 @@ +%%-------------------------------------------------------------------- %% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved. %% %% 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. %% See the License for the specific language governing permissions and %% limitations under the License. +%%-------------------------------------------------------------------- -module(ecpool_app). diff --git a/src/ecpool_pool.erl b/src/ecpool_pool.erl index 3f0dbca93..9a3392602 100644 --- a/src/ecpool_pool.erl +++ b/src/ecpool_pool.erl @@ -1,3 +1,4 @@ +%%-------------------------------------------------------------------- %% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved. %% %% 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. %% See the License for the specific language governing permissions and %% limitations under the License. +%%-------------------------------------------------------------------- -module(ecpool_pool). diff --git a/src/ecpool_pool_sup.erl b/src/ecpool_pool_sup.erl index 1b2371889..4d7d9874a 100644 --- a/src/ecpool_pool_sup.erl +++ b/src/ecpool_pool_sup.erl @@ -1,3 +1,4 @@ +%%-------------------------------------------------------------------- %% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved. %% %% 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. %% See the License for the specific language governing permissions and %% limitations under the License. +%%-------------------------------------------------------------------- -module(ecpool_pool_sup). diff --git a/src/ecpool_sup.erl b/src/ecpool_sup.erl index 10ac005a7..8528defa3 100644 --- a/src/ecpool_sup.erl +++ b/src/ecpool_sup.erl @@ -1,3 +1,4 @@ +%%-------------------------------------------------------------------- %% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved. %% %% 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. %% See the License for the specific language governing permissions and %% limitations under the License. +%%-------------------------------------------------------------------- -module(ecpool_sup). diff --git a/src/ecpool_worker.erl b/src/ecpool_worker.erl index f107bb1d0..e255bb4de 100644 --- a/src/ecpool_worker.erl +++ b/src/ecpool_worker.erl @@ -1,3 +1,4 @@ +%%-------------------------------------------------------------------- %% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved. %% %% 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. %% See the License for the specific language governing permissions and %% limitations under the License. +%%-------------------------------------------------------------------- -module(ecpool_worker). @@ -19,7 +21,7 @@ -export([start_link/4]). %% 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 -export([init/1, @@ -121,8 +123,8 @@ handle_info({'EXIT', Pid, Reason}, State = #state{client = Pid, opts = Opts}) -> reconnect_after(Secs, State) end; -handle_info(reconnect, State = #state{opts = Opts, on_reconnect = OnReconnect}) -> - case catch connect(State) of +handle_info(reconnect, State = #state{pool = Pool, opts = Opts, on_reconnect = OnReconnect}) -> + try connect(State) of {ok, Client} -> handle_reconnect(Client, OnReconnect), {noreply, State#state{client = Client}}; @@ -176,3 +178,7 @@ handle_reconnect(_, undefined) -> ok; handle_reconnect(Client, OnReconnect) -> OnReconnect(Client). + +maybe_apply(undefined, _) -> ok; +maybe_apply(Fun, Arg) -> erlang:apply(Fun, [Arg]). + diff --git a/src/ecpool_worker_sup.erl b/src/ecpool_worker_sup.erl index 7a8db2669..c4e2092a9 100644 --- a/src/ecpool_worker_sup.erl +++ b/src/ecpool_worker_sup.erl @@ -1,3 +1,4 @@ +%%-------------------------------------------------------------------- %% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved. %% %% 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. %% See the License for the specific language governing permissions and %% limitations under the License. +%%-------------------------------------------------------------------- -module(ecpool_worker_sup). diff --git a/test/ecpool_SUITE.erl b/test/ecpool_SUITE.erl index af7c92a56..287d1b5aa 100644 --- a/test/ecpool_SUITE.erl +++ b/test/ecpool_SUITE.erl @@ -1,3 +1,4 @@ +%%-------------------------------------------------------------------- %% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved. %% %% 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. %% See the License for the specific language governing permissions and %% limitations under the License. +%%-------------------------------------------------------------------- -module(ecpool_SUITE). diff --git a/test/test_client.erl b/test/test_client.erl index 28c7157f1..272c82ddf 100644 --- a/test/test_client.erl +++ b/test/test_client.erl @@ -1,3 +1,4 @@ +%%-------------------------------------------------------------------- %% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved. %% %% 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. %% See the License for the specific language governing permissions and %% limitations under the License. +%%-------------------------------------------------------------------- -module(test_client).