feature: add registry sup
diff --git a/src/dubbo_common_fun.erl b/src/dubbo_common_fun.erl
index ad15be1..e0db828 100644
--- a/src/dubbo_common_fun.erl
+++ b/src/dubbo_common_fun.erl
@@ -72,11 +72,11 @@
Parameters;
parse_url_parameter([Item | Rest], Parameters) ->
case string:tokens(Item, "=") of
- KeyPair when length(KeyPair) == 2 ->
- [Key, Value] = KeyPair,
+ [Key,Value] ->
parse_url_parameter(Rest, maps:put(list_to_binary(Key), list_to_binary(Value), Parameters));
- KeyPair2 ->
- logger:error("parse parameter error, keypair ~p", [KeyPair2]),
+ [Key] ->
+ parse_url_parameter(Rest, maps:put(list_to_binary(Key), <<"">>, Parameters));
+ [] ->
parse_url_parameter(Rest, Parameters)
end.
diff --git a/src/dubbo_node_config_util.erl b/src/dubbo_node_config_util.erl
index 9e3108a..59fef4b 100644
--- a/src/dubbo_node_config_util.erl
+++ b/src/dubbo_node_config_util.erl
@@ -31,18 +31,6 @@
logger:debug("parse provider,result: ~p", [ProviderConfig]),
{ok, ProviderConfig}.
-parse_parameter([], Config) ->
- Config;
-parse_parameter([Item | Rest], Config) ->
- case string:tokens(Item, "=") of
- KeyPair when length(KeyPair) == 2 ->
- [Key, Value] = KeyPair,
- ConfigNew = parse_parameter(Key, Value, Config),
- parse_parameter(Rest, ConfigNew);
- KeyPair2 ->
- logger:error("parse parameter error, keypair ~p", [KeyPair2]),
- parse_parameter(Rest, Config)
- end.
parse_parameter(<<"anyhost">>, Value, Config) ->
Config#provider_config{anyhost = binary_to_existing_atom(Value, latin1)};
parse_parameter(<<"application">>, Value, Config) ->
diff --git a/src/dubbo_registry_sup.erl b/src/dubbo_registry_sup.erl
new file mode 100644
index 0000000..ee72842
--- /dev/null
+++ b/src/dubbo_registry_sup.erl
@@ -0,0 +1,87 @@
+%%------------------------------------------------------------------------------
+%% Licensed to the Apache Software Foundation (ASF) under one or more
+%% contributor license agreements. See the NOTICE file distributed with
+%% this work for additional information regarding copyright ownership.
+%% The ASF licenses this file to You under the Apache License, Version 2.0
+%% (the "License"); you may not use this file except in compliance with
+%% the License. You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% 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(dubbo_registry_sup).
+
+-behaviour(supervisor).
+
+%% API
+-export([start_link/0, start_child/3]).
+
+%% Supervisor callbacks
+-export([init/1]).
+
+-define(SERVER, ?MODULE).
+
+%%%===================================================================
+%%% API functions
+%%%===================================================================
+
+%%--------------------------------------------------------------------
+%% @doc
+%% Starts the supervisor
+%%
+%% @end
+%%--------------------------------------------------------------------
+-spec(start_link() ->
+ {ok, Pid :: pid()} | ignore | {error, Reason :: term()}).
+start_link() ->
+ supervisor:start_link({local, ?SERVER}, ?MODULE, []).
+
+%%%===================================================================
+%%% Supervisor callbacks
+%%%===================================================================
+
+%%--------------------------------------------------------------------
+%% @private
+%% @doc
+%% Whenever a supervisor is started using supervisor:start_link/[2,3],
+%% this function is called by the new process to find out about
+%% restart strategy, maximum restart frequency and child
+%% specifications.
+%%
+%% @end
+%%--------------------------------------------------------------------
+-spec(init(Args :: term()) ->
+ {ok, {SupFlags :: {RestartStrategy :: supervisor:strategy(),
+ MaxR :: non_neg_integer(), MaxT :: non_neg_integer()},
+ [ChildSpec :: supervisor:child_spec()]
+ }} |
+ ignore |
+ {error, Reason :: term()}).
+init([]) ->
+ RestartStrategy = one_for_one,
+ MaxRestarts = 1000,
+ MaxSecondsBetweenRestarts = 3600,
+
+ SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts},
+
+%% AChild = {'AName', {'AModule', start_link, []}, Restart, Shutdown, Type, ['AModule']},
+
+ {ok, {SupFlags, []}}.
+
+start_child(Id, StartSepc, Module) ->
+ Restart = permanent,
+ Shutdown = 2000,
+ Type = worker,
+
+ Child = {Id, StartSepc,
+ Restart, Shutdown, Type, [Module]},
+ supervisor:start_child(?MODULE, Child),
+ ok.
+%%%===================================================================
+%%% Internal functions
+%%%===================================================================
diff --git a/src/dubbo_registry_zookeeper.erl b/src/dubbo_registry_zookeeper.erl
index e7e1862..632abb0 100644
--- a/src/dubbo_registry_zookeeper.erl
+++ b/src/dubbo_registry_zookeeper.erl
@@ -89,14 +89,13 @@
{stop, Reason :: term(), Reply :: term(), NewState :: #state{}} |
{stop, Reason :: term(), NewState :: #state{}}).
handle_call({do_register, Url}, _From, State) ->
- io:format(user,"debug do_register ~p~n",[Url]),
do_register(State#state.zk_pid, Url),
{reply, ok, State};
handle_call({do_unregister, Url}, _From, State) ->
do_unregister(State#state.zk_pid, Url),
{reply, ok, State};
handle_call({subscribe_provider, InterfaceName, NotifyFun}, _From, #state{zk_pid = ZkPid} = State) ->
- logger:debug("subscribe provider ~p notify fun ~p",[InterfaceName,NotifyFun]),
+ logger:debug("subscribe provider ~p notify fun ~p", [InterfaceName, NotifyFun]),
NewState = State#state{provider_notify_fun = NotifyFun},
List = get_provider_list(InterfaceName, ZkPid),
notify_provider_change(NotifyFun, InterfaceName, List),
@@ -174,17 +173,9 @@
%%----------------------------------------------
%% dubbo_registry
%%----------------------------------------------
-start(Url) ->
+start(_Url) ->
+ dubbo_registry_sup:start_child(?MODULE, {?MODULE, start_link, []}, ?MODULE),
ok.
-%%register(Url) ->
-%% {ok, UrlInfo} = dubbo_common_fun:parse_url(Url),
-%% InterfaceName = maps:get(<<"interface">>, UrlInfo#dubbo_url.parameters),
-%% register(UrlInfo#dubbo_url.scheme, InterfaceName, Url),
-%% ok.
-
-%%register(<<"consumer">>, InterfaceName, Url) ->
-%% gen_server:call(?SERVER, {add_consumer, InterfaceName, Url}),
-%% ok.
register(Url) ->
gen_server:call(?SERVER, {do_register, Url}, 10000),
diff --git a/src/dubboerl_sup.erl b/src/dubboerl_sup.erl
index a7b2bac..62e9982 100644
--- a/src/dubboerl_sup.erl
+++ b/src/dubboerl_sup.erl
@@ -42,7 +42,8 @@
init([]) ->
dubboerl_app:env_init(),
%% @todo registry need move registry sup
- ZK = {dubbo_registry_zookeeper, {dubbo_registry_zookeeper, start_link, []}, transient, 5000, worker, [dubbo_registry_zookeeper]},
+%% ZK = {dubbo_registry_zookeeper, {dubbo_registry_zookeeper, start_link, []}, transient, 5000, worker, [dubbo_registry_zookeeper]},
+ RegistrySup = {dubbo_registry_sup, {dubbo_registry_sup, start_link, []}, transient, 5000, supervisor, [dubbo_registry_sup]},
ExtensionSer = {dubbo_extension, {dubbo_extension, start_link, []}, transient, 5000, worker, [dubbo_extension]},
Id_count = {dubbo_id_generator, {dubbo_id_generator, start_link, []}, transient, 5000, worker, [dubbo_id_generator]},
@@ -50,14 +51,8 @@
ConsumerPoolSup = {dubbo_transport_pool_sup, {dubbo_transport_pool_sup, start_link, []}, transient, 5000, supervisor, [dubbo_transport_pool_sup]},
ConsumerPool = {dubbo_provider_consumer_reg_table, {dubbo_provider_consumer_reg_table, start_link, []}, transient, 5000, worker, [dubbo_provider_consumer_reg_table]},
ShutdownSer = {dubbo_shutdown, {dubbo_shutdown, start_link, []}, transient, 10000, worker, [dubbo_shutdown]},
-%% ListNew1 =
-%% case application:get_env(dubboerl, registry, false) of
-%% true ->
-%% [ZK];
-%% false ->
-%% []
-%% end,
- ListNew = [Id_count, ExtensionSer, ZK, ConsumerPool, ConsumerPoolSup, ProviderPoolSup, ShutdownSer],
+
+ ListNew = [Id_count, ExtensionSer, RegistrySup, ConsumerPool, ConsumerPoolSup, ProviderPoolSup, ShutdownSer],
{ok, {{one_for_one, 60, 10}, ListNew}}.
%%====================================================================