Skip to content
Permalink
Browse files
feature: add registry sup
  • Loading branch information
DLive committed Jul 25, 2019
1 parent f0bf043 commit 7fd1c8bc7c3612cb8e3f06aa47060f920d840bdb
Showing 5 changed files with 98 additions and 37 deletions.
@@ -72,11 +72,11 @@ parse_url_parameter([], Parameters) ->
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.

@@ -31,18 +31,6 @@ parse_provider_info(#dubbo_url{scheme = Scheme, host = Host, port = Port, parame
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) ->
@@ -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
%%%===================================================================
@@ -89,14 +89,13 @@ init([]) ->
{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 @@ code_change(_OldVsn, State, _Extra) ->
%%----------------------------------------------
%% 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),
@@ -42,22 +42,17 @@ start_link() ->
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]},
ProviderPoolSup = {dubbo_provider_worker_sup, {dubbo_provider_worker_sup, start_link, []}, transient, 5000, supervisor, [dubbo_provider_worker_sup]},
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}}.

%%====================================================================

0 comments on commit 7fd1c8b

Please sign in to comment.