Skip to content
Permalink
Browse files
format code
  • Loading branch information
DLive committed Jul 28, 2019
1 parent 7fd1c8b commit aeac23b39d6a244cb778c9c6616d05ac3027c42d
Showing 17 changed files with 102 additions and 46 deletions.
@@ -24,7 +24,7 @@

-record(dubbo_url, {
scheme :: binary() ,
user_info :: binary(),
user_info :: binary() | undefined,
host:: binary(),
port::integer(),
path:: binary(),
@@ -20,6 +20,8 @@
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;

public class AppListMain {

@@ -28,6 +30,9 @@ public static void main( String[] args ) throws IOException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[] { "applicationProvider.xml" });
context.start();
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
System.out.println(runtimeMXBean.getName());
System.out.println("current process pid "+ Integer.valueOf(runtimeMXBean.getName().split("@")[0]));

System.out.println("按任意键退出");
System.in.read();
@@ -21,7 +21,7 @@
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="hello-world"/><!-- 注册地址 -->
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<dubbo:registry address="zookeeper://127.0.0.1:2181" check="false" />
<dubbo:protocol name="dubbo" port="20880"/>

<dubbo:reference id="userInterface" interface="org.apache.dubbo.erlang.sample.service.facade.UserOperator" retries="0" />
@@ -19,7 +19,7 @@

-include("dubbo.hrl").
%% API
-export([invoke/2, do_response/2]).
-export([invoke/2, on_response/2]).


invoke(#dubbo_rpc_invocation{className = Interface, loadbalance = LoadBalance} = Invocation, Acc) ->
@@ -53,5 +53,5 @@ loadbalance_select(LoadBalance, ConnectionList) ->
Connection = LoadBalance:select(ConnectionList),
Connection.

do_response(Invocation, Result) ->
on_response(Invocation, Result) ->
{ok, Invocation, Result}.
@@ -46,8 +46,8 @@ encode_header(Request, DataLen, RequestState) ->
false -> Header2
end,
Header22 = case Request#dubbo_request.is_event of
true -> Header21 bor 32;
false -> Header21
false -> Header21;
true -> Header21 bor 32
end,
RequestId = Request#dubbo_request.mid,
Header = <<?DUBBO_MEGIC:16, Header22:8, RequestState:8, RequestId:64, DataLen:32>>,
@@ -82,8 +82,8 @@ encode_response_header(Response, DataLen, ResponseState) ->
false -> Header2
end,
Header22 = case Response#dubbo_response.is_event of
true -> Header21 bor 32;
false -> Header21
false -> Header21;
true -> Header21 bor 32
end,
RequestId = Response#dubbo_response.mid,
Header = <<?DUBBO_MEGIC:16, Header22:8, ResponseState:8, RequestId:64, DataLen:32>>,
@@ -94,13 +94,9 @@ url_to_binary(UrlInfo) ->
list_to_binary(Value).
format_path(<< ?URL_PATH_SEPARATOR:8,Rest/binary>>) ->
Rest;
format_path([?URL_PATH_SEPARATOR|Rest]) ->
Rest;
format_path(Value) ->
Value.

format_parameter(undefined) ->
"";
format_parameter(Parameter) when is_map(Parameter) ->
KeyValues = maps:to_list(Parameter),
format_parameter(KeyValues);
@@ -86,14 +86,14 @@ notify(Interface, UrlList) ->

refresh_invoker(UrlList) ->
case pick_interface(UrlList) of
{error, Reason} ->
{error, _Reason} ->
fail;
{<<"empty">>, Interface,_} ->
OldProviderHosts = dubbo_provider_consumer_reg_table:get_interface_provider_node(Interface),
dubbo_provider_consumer_reg_table:clean_invalid_provider(OldProviderHosts),
todo_destroy;
{Schame, Interface, LoadBalance} ->
ProtocolModule = binary_to_existing_atom(<<<<"dubbo_protocol_">>/binary, Schame/binary>>, latin1),
{Scheme, Interface, LoadBalance} ->
ProtocolModule = binary_to_existing_atom(<<<<"dubbo_protocol_">>/binary, Scheme/binary>>, latin1),

logger:info("[DUBBO] refresh invoker for interface ~p loadbalance ~p protocol ~p", [Interface, LoadBalance, ProtocolModule]),
OldProviderHosts = dubbo_provider_consumer_reg_table:get_interface_provider_node(Interface),
@@ -107,12 +107,8 @@ refresh_invoker(UrlList) ->
NewHostConnections = dubbo_provider_consumer_reg_table:query_node_connections(NewHosts),
dubbo_provider_consumer_reg_table:update_consumer_connections(Interface, NewHostConnections)
end, NewProviderHosts),


%% dubbo_provider_consumer_reg_table:update_connection_info(#interface_info{interface = Interface,loadbalance = LoadBalance})
dubbo_provider_consumer_reg_table:update_interface_info(#interface_info{interface = Interface, loadbalance = LoadBalance, protocol = ProtocolModule})
end.
%% OldProviderHosts =

refresh_invoker([], Acc) ->
Acc;
@@ -154,7 +150,7 @@ pick_interface([Url | _]) ->
{stop, Reason :: term(), Reply :: term(), NewState :: #state{}} |
{stop, Reason :: term(), NewState :: #state{}}).
handle_call({subscribe, RegistryName, SubcribeUrl}, _From, State) ->
NotifyFun = fun dubbo_directory:notify/1,
NotifyFun = fun dubbo_directory:notify/2,
apply(RegistryName, subscribe, [SubcribeUrl, NotifyFun]),
{reply, ok, State};
handle_call(_Request, _From, State) ->
@@ -3,7 +3,7 @@
%% 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 not use this file e34rg 56yujxcept in compliance with
%% the License. You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
@@ -121,15 +121,6 @@ do_invoke([M | Rest], HookName, Fun, Args0, Acc) ->
do_invoke(Rest, HookName, Fun, [Args2], NewAcc2)
end.


%% @doc retrieve the lists of registered functions for an hook.
-spec find(HookName :: atom()) -> {ok, [{atom(), atom()}]} | error.
find(HookName) ->
case find_hooks(HookName) of
no_hook -> error;
Hooks -> {ok, Hooks}
end.

%% @hidden
start_link() ->
_ = init_tabs(),
@@ -84,7 +84,7 @@ invoke_request(Interface, Request, RequestOption, CallBackPid) ->
end.

invoke_response(Invocation, Result) ->
Result2 = dubbo_extension:invoke_foldr(filter, do_response, [Invocation], Result),
Result2 = dubbo_extension:invoke_foldr(filter, on_response, [Invocation], Result),
gen_server:cast(Invocation#dubbo_rpc_invocation.source_pid, {response_process, Invocation#dubbo_rpc_invocation.call_ref, Invocation#dubbo_rpc_invocation.attachments, Result2}),
ok.

@@ -46,8 +46,6 @@ parse_parameter(<<"methods">>, Value, Config) ->
Config#provider_config{methods = MethodList};
parse_parameter(<<"side">>, Value, Config) ->
Config#provider_config{side = Value};
parse_parameter(<<"interface">>, Value, Config) ->
Config#provider_config{interface = Value};
parse_parameter(_, _, Config) ->
Config.

@@ -37,7 +37,6 @@ refer(Url, Acc) ->
do_refer(UrlInfo) ->
case dubbo_node_config_util:parse_provider_info(UrlInfo) of
{ok, ProviderConfig} ->
%% OldHostList = dubbo_provider_consumer_reg_table:get_interface_provider_node(ProviderConfig#provider_config.interface),
case getClients(ProviderConfig) of
{ok, ConnectionInfoList} ->
dubbo_provider_consumer_reg_table:update_node_conections(ProviderConfig#provider_config.interface, ConnectionInfoList),
@@ -63,15 +63,6 @@ gen_registry_parameter(ProviderInfo) ->
Para.

get_export_info(ProviderInfo) ->
%%dubbo://127.0.0.1:20880/org.apache.dubbo.erlang.sample.service.facade.UserOperator?
%% anyhost=true&
%% application=hello-world&
%% bean.name=org.apache.dubbo.erlang.sample.service.facade.UserOperator&
%% bind.ip=127.0.0.1&bind.port=20880&default.deprecated=false&
%% default.dynamic=false&default.register=true&deprecated=false&dubbo=2.0.2&
%% dynamic=false&generic=false&
%% interface=org.apache.dubbo.erlang.sample.service.facade.UserOperator&
%% methods=queryUserInfo,queryUserList,genUserId,getUserInfo&pid=90956&register=true&release=2.7.1&side=provider&timestamp=1562725983984
Para = [
{"anyhost", "true"},
{"application", ProviderInfo#provider_config.application},
@@ -34,7 +34,7 @@ get_cur_time() ->
io_lib:format("~4..0w-~2..0w-~2..0w ~2..0w:~2..0w:~2..0w", [Year, Month, Day, Hour, Min, Second]).

get_cur_date() ->
{{Year, Month, Day}, {Hour, Min, Second}} = calendar:now_to_local_time(os:timestamp()),
{{Year, Month, Day}, {_Hour, _Min, _Second}} = calendar:now_to_local_time(os:timestamp()),
io_lib:format("~4..0w-~2..0w-~2..0w", [Year, Month, Day]).

get_cur_time({{Year, Month, Day}, {Hour, Min, Second}}) ->
@@ -47,14 +47,25 @@ init_default_hooks() ->
dubbo_extension:register(protocol, dubbo_protocol_dubbo, 10),
dubbo_extension:register(protocol_wapper, dubbo_protocol_registry, 10),
dubbo_extension:register(filter, application:get_env(dubboerl, cluster, dubbo_cluster_failfast), 1),
init_filter_hooks(),
ok.

init_filter_hooks() ->
FilterList = application:get_env(dubboerl, filter, []),
lists:mapfoldl(
fun(Filter,Acc) ->
dubbo_extension:register(filter, Filter, Acc),
Acc +1
end,100,FilterList
),
ok.

env_init() ->
ets:new(?PROVIDER_IMPL_TABLE, [public, named_table]),
ets:new(?SERVICE_EXPORT_TABLE, [public, named_table]),
dubbo_traffic_control:init(),
dubbo_type_register:init(),
register_type_list().
%% type_decoding:init().


register_type_list() ->
@@ -35,4 +35,9 @@ string_join_test() ->

list_dup_test() ->
R = dubbo_lists_util:del_duplicate([a, b, a]),
?assertEqual(length(R), 2).
?assertEqual(length(R), 2).


ip_v4_test()->
Result = dubbo_network_tools:local_ipv4(),
?assertEqual(true,is_list(Result)).
@@ -0,0 +1,35 @@
%%------------------------------------------------------------------------------
%% 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_extension_tests).


-include_lib("eunit/include/eunit.hrl").
-include("dubbo.hrl").

invoker_test()->
{ok,_Pid} = dubbo_extension:start_link(),

ok = dubbo_extension:register(filter, dubbo_filter_test1, 100),
Invocation = #dubbo_rpc_invocation{},
Ref = make_ref(),
{ok,Ref} = dubbo_extension:invoke(filter, invoke, [Invocation], {ok, Ref}, []),
ok.

%%on_response_test() ->



@@ -0,0 +1,29 @@
%%------------------------------------------------------------------------------
%% 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_filter_test1).
-behaviour(dubbo_filter).

%% API
-export([invoke/2, on_response/2]).

invoke(Invocation, Acc) ->
io:format(user,"test filter invoke sucess~n",[]),
{ok, Invocation, Acc}.

on_response(Invocation, Result) ->
io:format(user,"test filter on_response sucess~n",[]),
{ok, Invocation, Result}.

0 comments on commit aeac23b

Please sign in to comment.