Skip to content
Permalink
Browse files
Merge pull request #1 from dubboerl/0.3.0
replace lager to logger lib
  • Loading branch information
Dlive committed Apr 22, 2019
2 parents 23c52a0 + bad46d7 commit 50126a27defe320e167589ce5d90fdba00f6c50a
Showing 21 changed files with 102 additions and 127 deletions.
@@ -1,25 +1,4 @@
[
%% SASL config {file, "log/sasl-error.log"}
{sasl, [
{sasl_error_logger, false},
{errlog_type, error},
{error_logger_mf_dir, "log/sasl-error.log"}, % Log directory
{error_logger_mf_maxbytes, 104857600}, % 100 MB max file size
{error_logger_mf_maxfiles, 5} % 5 files max
]},
{emysql,[
{lock_timeout,900000},
{default_timeout, 900000}

]},
{lager, [
{log_root, "./logs"},
{handlers, [
{lager_console_backend, debug},
{lager_file_backend, [{file, "error.log"}, {level, error}]},
{lager_file_backend, [{file, "console.log"}, {level, info}]}
]}
]},
{dubboerl,[
{zookeeper_list,[{"127.0.0.1",2181}]},
{application,<<"testdubboerl">>},
@@ -1,9 +1,8 @@
## Name of the node
##需要定义 -name android_connecion_1@logic1.mpush.paf
-name dubboerl@127.0.0.1

## Cookie for distributed erlang
-setcookie fb65338cf25a2d68a2da5207f718cdfa
-setcookie test_cookie

## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive
## (Disabled by default..use with caution!)
@@ -1,6 +1,4 @@
{erl_opts, [debug_info,
{parse_transform, lager_transform}
]}.
{erl_opts, [debug_info]}.

{lib_dirs, []}.
{base_dir, "_build"}.
@@ -12,7 +10,6 @@

{deps, [
{erlzk, ".*", {git, "https://github.com/huaban/erlzk.git", {tag, "v0.6.2"}}},
{lager, ".*", {git, "https://github.com/basho/lager.git", {tag, "3.2.4"}}},
{ranch, ".*", {git, "https://github.com/ninenines/ranch.git", {tag, "1.4.0"}}},
{poolboy, ".*", {git, "https://github.com/devinus/poolboy.git", {tag, "1.5.1"}}},
{jiffy, "0.15.1"}
@@ -26,7 +26,7 @@

-spec encode_request(#dubbo_request{})->{ok,binary()} | {error,term()}.
encode_request(Request)->
%% lager:debug("encode request ~p",[Request]),
%% logger:debug("encode request ~p",[Request]),
{ok,RequestData} = encode_request_data(Request#dubbo_request.serialize_type,Request),
Size = byte_size(RequestData),
Header = encode_header(Request,Size,0),
@@ -218,9 +218,9 @@ decode_response(Res,Data)->
%% 2 ->
%% {ok,Res#dubbo_response{data = null,decode_state = State}};
%% _->
%% lager:warning("decode unkonw type ~p ~p",[Type,Rest]),
%% logger:warning("decode unkonw type ~p ~p",[Type,Rest]),
%% {Rest2,Object2,DecodeState2} = hessianDecode2:decode(Rest,State),
%% lager:warning("decode unkonw type2 ~p ~p",[Object2,Rest2]),
%% logger:warning("decode unkonw type2 ~p ~p",[Object2,Rest2]),
%% {ok,Res#dubbo_response{data = Object2,decode_state = DecodeState2}}
%% end;
%%decode_response(?SERIALIZATION_HESSIAN,dubbo_event,Res,Data)->
@@ -269,7 +269,7 @@ decode_request(Req,Data)->
%% AttachmentsList = dict:to_list(Attachments#map.dict),
%% decode_request_body(List,Rest,State1,[AttachmentsList] ++ ResultList);
%%decode_request_body([_Type1|List],Data,State,ResultList)->
%% lager:warning("decode_request_body unknow type"),
%% logger:warning("decode_request_body unknow type"),
%% decode_request_body(List,Data,State, ResultList);
%%decode_request_body([],Data,State,ResultList)->
%% {ResultList,State,Data}.
@@ -37,7 +37,7 @@ java_to_native(#object{values = ForeignData}=Data,State)->
list_to_tuple( [NativeTupeName] ++ NativeData)
end;
Info ->
lager:warning("java_to_native error:~p",[Info]),
logger:warning("java_to_native error:~p",[Info]),
error
end;
java_to_native(#list{values = ForeignData}=Data,State)->
@@ -49,18 +49,18 @@ java_to_native(#list{values = ForeignData}=Data,State)->
%% false->
%% error;
%% #type_def{fieldnames = NativeFields,native_type = NativeTupeName}->
%% lager:debug("test ForeignType ~p NativeTupeName ~p",[ForeignType,NativeTupeName]),
%% logger:debug("test ForeignType ~p NativeTupeName ~p",[ForeignType,NativeTupeName]),
%%%% AsDict = dict:from_list(lists:zip(ObjectFields,ForeignDataNew)),
%%%% NativeData = [dict:fetch(atom_to_binary(Key,utf8),AsDict) || Key <- NativeFields],
%%%% list_to_tuple( [NativeTupeName] ++ NativeData)
%% ForeignDataNew
%% end;
%% Info ->
%% lager:warning("java_to_native list error:~p",[Info]),
%% logger:warning("java_to_native list error:~p",[Info]),
%% error
%% end;
java_to_native(Data,_)->
lager:debug("java_to_native unkonw type ~p",[Data]),
logger:debug("java_to_native unkonw type ~p",[Data]),
Data.

%%get_deftype([Item |DefTypeList],ForeignType)->
@@ -76,28 +76,28 @@ get_deftype(ForeignType)->

case type_register:lookup_foreign_type(ForeignType) of
undefined->
lager:debug("get deftype undefined ~p",[ForeignType]),
logger:debug("get deftype undefined ~p",[ForeignType]),
false;
#type_def{}=TypeDef->
lager:debug("get deftype success ~p",[ForeignType]),
logger:debug("get deftype success ~p",[ForeignType]),
TypeDef;
_->
lager:debug("get deftype undefined ~p",[ForeignType]),
logger:debug("get deftype undefined ~p",[ForeignType]),
false
end.

pre_process_typedef(NativeType,ForeignType,FieldsNames)->
Type = #type_def{native_type = NativeType,foreign_type = ForeignType,fieldnames = FieldsNames},
%% Type2=type_decoding:hash_store(Type),
type_register:regiest_foreign_native(Type),
lager:debug("pre_process_typedef ~p,~p",[NativeType,ForeignType]).
logger:debug("pre_process_typedef ~p,~p",[NativeType,ForeignType]).
%% case type_decoding:resolve_native_type(ForeignType) of
%% undefined ->
%%%% Type = #type_def{native_type = NativeType, foreign_type = ForeignType, fieldnames = record_info(fields,NativeType)},
%% Type = #type_def{native_type = NativeType,foreign_type = ForeignType,fieldnames = FieldsNames},
%% Type2=type_decoding:hash_store(Type),
%%
%% lager:debug("pre_process_typedef ~p,~p",[NativeType,ForeignType]);
%% logger:debug("pre_process_typedef ~p,~p",[NativeType,ForeignType]);
%% type_decoding:store_typepool(Type2);
%% _->
%% ok
@@ -76,15 +76,15 @@ init_ets_table()->
ok
catch
_Type:Reason ->
lager:error("new ets table error ~p",[Reason]),
logger:error("new ets table error ~p",[Reason]),
error
end,
try ets:new(?PROVIDER_NODE_LIST_TABLE, [bag,public,named_table,{keypos,2}]) of
?PROVIDER_NODE_LIST_TABLE ->
ok
catch
_Type1:Reason1 ->
lager:error("new ets table error ~p",[Reason1]),
logger:error("new ets table error ~p",[Reason1]),
error
end,
ok.
@@ -202,7 +202,7 @@ add_consumer([ProviderNodeInfo|ProviderList],RegisterList)->
end,
add_consumer(ProviderList,[HostFlag]++RegisterList);
{error,R1} ->
lager:error("parse provider info error reason ~p",[R1]),
logger:error("parse provider info error reason ~p",[R1]),
add_consumer(ProviderList,RegisterList)
end.

@@ -213,7 +213,7 @@ start_provider_process(HostFlag,Weight,ProviderConfig) ->
ConnectionFlagTerm= binary_to_atom(ConnectionFlag,utf8),
AChild = {ConnectionFlagTerm,{dubbo_netty_client, start_link, [ConnectionFlagTerm,HostFlag,ProviderConfig,Item]}, permanent, 2000, worker, [dubbo_netty_client]},
{ok,Pid} = dubbo_consumer_pool_sup:add_children(AChild),
lager:info("start provider ~p pid info ~p~n",[HostFlag,Pid]),
logger:info("start provider ~p pid info ~p~n",[HostFlag,Pid]),
#connection_info{connection_id = ConnectionFlagTerm,pid = Pid,weight = Weight,host_flag = HostFlag}
end,ExecutesList),
ConnectionList.
@@ -224,11 +224,11 @@ get_host_flag(ProviderConfig)->
update_connection_info(Interface,HostFlag,ConnectionList,IsUpdateProvideNode)->
lists:map(fun(Item) ->
I1 = ets:insert(?INTERFCE_LIST_TABLE,#interface_list{interface = Interface,connection_info = Item}),
lager:debug("save INTERFCE_LIST_TABLE ~p info:~p",[Interface,I1]),
logger:debug("save INTERFCE_LIST_TABLE ~p info:~p",[Interface,I1]),
case IsUpdateProvideNode of
true->
I2 = ets:insert(?PROVIDER_NODE_LIST_TABLE,#provider_node_list{host_flag = HostFlag,connection_info = Item }),
lager:debug("save PROVIDER_NODE_LIST_TABLE ~p info:~p",[HostFlag,I2]);
logger:debug("save PROVIDER_NODE_LIST_TABLE ~p info:~p",[HostFlag,I2]);
false->
ok
end,
@@ -43,10 +43,10 @@ invoke_request(Interface,Request,RpcContext,RequestState,CallBackPid)->
{error,request_full}
end;
{error,none}->
lager:error("[INVOKE] ~p error Reason no_provider",[Interface]),
logger:error("[INVOKE] ~p error Reason no_provider",[Interface]),
{error,no_provider};
{error,R1}->
lager:error("[INVOKE] ~p error Reason ~p",[Interface,R1]),
logger:error("[INVOKE] ~p error Reason ~p",[Interface,R1]),
{error,R1}
end.

@@ -70,7 +70,7 @@ init([HostFlag,ProviderConfig,Index]) ->
erlang:process_flag(min_bin_vheap_size, 1024*1024),
%% erlang:process_flag(min_heap_size, 1024*1024),
%% BindScheduler = (Index rem erlang:system_info(schedulers_online))+1,
%% lager:info("will bind to scheduler ~p",[BindScheduler]),
%% logger:info("will bind to scheduler ~p",[BindScheduler]),
%% erlang:process_flag(scheduler, BindScheduler),
%% erlang:process_flag(priority, high),

@@ -83,7 +83,7 @@ init([HostFlag,ProviderConfig,Index]) ->
end,
NowStamp = time_util:timestamp_ms(),
HeartBeatInfo = #heartbeat{last_read = NowStamp,last_write = NowStamp},
lager:info("netty client start ~p",[HostFlag]),
logger:info("netty client start ~p",[HostFlag]),
%% start_heartbeat_timer(HeartBeatInfo),
{ok, State#state{provider_config=ProviderConfig,heartbeat=HeartBeatInfo,host_flag = HostFlag}}.

@@ -119,17 +119,17 @@ handle_call(_Request, _From, State) ->

handle_cast({send_request,Ref,Request,Data,SourcePid,RequestState}, State) ->
RequestState2 = request_context:update(<<"t_net_b">>,RequestState),
lager:debug("[send_request begin] send data to provider consumer mid ~p pid ~p sourcePid ~p",[Request#dubbo_request.mid,self(),SourcePid]),
logger:debug("[send_request begin] send data to provider consumer mid ~p pid ~p sourcePid ~p",[Request#dubbo_request.mid,self(),SourcePid]),
NewState = case send_msg(Data,State) of
ok->
save_request_info(Request,SourcePid,Ref,RequestState2),
lager:debug("[send_request end] send data to provider consumer pid ~p state ok",[self()]),
logger:debug("[send_request end] send data to provider consumer pid ~p state ok",[self()]),
State;
{error,closed}->
State2 = reconnect(State),
State2;
{error,R1}->
lager:error("[send_request end] send data to provider consumer pid error ~p ~p",[self(),R1]),
logger:error("[send_request end] send data to provider consumer pid error ~p ~p",[self(),R1]),
State
end,
HeartbeatInfo =update_heartbeat(write,NewState#state.heartbeat),
@@ -156,10 +156,10 @@ handle_cast(_Request, State) ->

handle_info({tcp,_Port,Data}, #state{recv_buffer = RecvBuffer} = State) ->
%% inet:setopts(State#state.socket, [{active, once}]),
%% lager:debug("[INFO] recv one data ~w",[Data]),
%% logger:debug("[INFO] recv one data ~w",[Data]),
{ok,NextBuffer,NewState} = case check_recv_data(<< RecvBuffer/binary,Data/binary >>,State) of
{next_buffer,NextBuffer2,State3}->
lager:debug("[INFO] recv one data state wait next_buffer"),
logger:debug("[INFO] recv one data state wait next_buffer"),
{ok,NextBuffer2,State3}
end,
%% HeartbeatInfo =update_heartbeat(write,NewState#state.heartbeat),
@@ -184,7 +184,7 @@ handle_info({timeout, _TimerRef, {heartbeat_timer}},State) ->
start_heartbeat_timer(HeartbeatInfo),
{noreply,NewState#state{heartbeat = HeartbeatInfo}};
handle_info(_Info,State) ->
lager:warning("[INFO] get one info:~p",[_Info]),
logger:warning("[INFO] get one info:~p",[_Info]),
%% inet:setopts(State#state.socket, [{active, once}]),
%% case State#state.tmp_pid of
%% undefined ->ok;
@@ -208,7 +208,7 @@ handle_info(_Info,State) ->
-spec(terminate(Reason :: (normal | shutdown | {shutdown, term()} | term()),
State :: #state{}) -> term()).
terminate(_Reason, _State) ->
lager:warning("terminate reason:~p",[_Reason]),
logger:warning("terminate reason:~p",[_Reason]),
ok.

%%--------------------------------------------------------------------
@@ -230,7 +230,7 @@ code_change(_OldVsn, State, _Extra) ->
%%%===================================================================

open(Host,Port)->
lager:debug("will connect to provider ~p ~p",[Host,Port]),
logger:debug("will connect to provider ~p ~p",[Host,Port]),
%
case gen_tcp:connect(Host,Port,[
binary,
@@ -250,7 +250,7 @@ open(Host,Port)->
inet:setopts(Sockets, [{active, true}]),
{ok,Sockets};
Info ->
lager:error("start netty client ~p~n",[Info]),
logger:error("start netty client ~p~n",[Info]),
{error,Info}
end.

@@ -278,7 +278,7 @@ send_msg(Msg,State) ->
ok->
ok;
{error,Reason}->
lager:error("send to server error,reason:~p",[Reason]),
logger:error("send to server error,reason:~p",[Reason]),
{error,Reason}
end
end.
@@ -314,7 +314,7 @@ send_heartbeat_msg(Mid,NeedResponse,State)->
{ok,Bin} = de_heartbeat:generate_request(Mid,NeedResponse),
NewState = case send_msg(Bin,State) of
ok ->
lager:info("send one heartbeat msg to server"),
logger:info("send one heartbeat msg to server"),
State;
{error,_Reason} ->
State2 = reconnect(State),
@@ -335,17 +335,17 @@ check_recv_data(<<?DUBBO_MEGIC_HIGH,?DUBBO_MEGIC_LOW,_OtherFlag:80,DataLen:32,Re
{ok,State2} = process_data(Data,State),
{next_buffer,<<>>,State2};
DataLen>RestSize ->
lager:warning("need wait next buffer data ~p",[Data]),
logger:warning("need wait next buffer data ~p",[Data]),
{next_buffer,Data,State};
DataLen<RestSize ->
<<ReadyData:DataLen/binary,NextBuffer/binary>> = Rest,
OneData = <<?DUBBO_MEGIC_HIGH:8,?DUBBO_MEGIC_LOW:8,_OtherFlag:80,DataLen:32,ReadyData/binary>>,
{ok,State3} = process_data(OneData,State),
%% lager:warning("recevi more data ~w ",[NextBuffer]),
%% logger:warning("recevi more data ~w ",[NextBuffer]),
check_recv_data(NextBuffer,State3)
end;
check_recv_data(<<Error/integer,Data/binary>>,State)->
lager:error("recv bad header data,Begin Byte:~p",[Error]),
logger:error("recv bad header data,Begin Byte:~p",[Error]),
check_recv_data(Data,State);
check_recv_data(<<>>,State)->
{next_buffer,<<>>,State}.
@@ -360,7 +360,7 @@ process_data(Data,State)->
dubbo_traffic_control:decr_count(State#state.host_flag),
case get_earse_request_info(ResponseInfo#dubbo_response.mid) of
undefined->
lager:error("dubbo response can't find request data,response ~p",[ResponseInfo]);
logger:error("dubbo response can't find request data,response ~p",[ResponseInfo]);
{SourcePid,Ref,RequestState} ->
%% RequestState2 = request_context:update(<<"t_net_b">>,TmpTime,RequestState),
RequestState3 = request_context:update(<<"t_net_e">>,RequestState),
@@ -384,26 +384,26 @@ process_data(Data,State)->
end
%% gen_server:cast(SourcePid,{response_process,Ref,ResponseInfo,RestData,RequestState3})

%% lager:debug("will cast mid ~p to source process SourcePid ~p",[Response#dubbo_response.mid,SourcePid]),
%% logger:debug("will cast mid ~p to source process SourcePid ~p",[Response#dubbo_response.mid,SourcePid]),
%% RpcContent=[],
%% ResponseData = de_type_transfer:response_to_native(Response),
%% lager:debug("one response ~p",[Response]),
%% logger:debug("one response ~p",[Response]),
%% gen_server:cast(SourcePid,{msg_back,Ref,Response,RpcContent,RequestState3})
end,



%% {ok,Res} = de_codec:decode_response(ResponseInfo,RestData),
%% lager:info("get one response mid ~p, is_event ~p state ~p",[Res#dubbo_response.mid,Res#dubbo_response.is_event,Res#dubbo_response.state]),
%% logger:info("get one response mid ~p, is_event ~p state ~p",[Res#dubbo_response.mid,Res#dubbo_response.is_event,Res#dubbo_response.state]),
%% {ok,State3} =process_response(Res#dubbo_response.is_event,Res,State,TmpTime),
{ok,State};
{ok,request,RequestInfo}->
{ok,Req} = de_codec:decode_request(RequestInfo,RestData),
lager:info("get one request mid ~p, is_event ~p",[Req#dubbo_request.mid,Req#dubbo_request.is_event]),
logger:info("get one request mid ~p, is_event ~p",[Req#dubbo_request.mid,Req#dubbo_request.is_event]),
{ok,State2} = process_request(Req#dubbo_request.is_event,Req,State),
{ok,State2};
{error,Type,RelData}->
lager:error("process_data error type ~p RelData ~p",[Type,RelData]),
logger:error("process_data error type ~p RelData ~p",[Type,RelData]),
{ok,State}
end.

@@ -414,14 +414,14 @@ process_response(false,Response,State,TmpTime)->
dubbo_traffic_control:decr_count(State#state.host_flag),
case get_earse_request_info(Response#dubbo_response.mid) of
undefined->
lager:error("dubbo response can't find request data,response ~p",[Response]);
logger:error("dubbo response can't find request data,response ~p",[Response]);
{SourcePid,Ref,RequestState} ->
%% RequestState2 = request_context:update(<<"t_net_b">>,TmpTime,RequestState),
RequestState3 = request_context:update(<<"t_net_e">>,RequestState),
%% lager:debug("will cast mid ~p to source process SourcePid ~p",[Response#dubbo_response.mid,SourcePid]),
%% logger:debug("will cast mid ~p to source process SourcePid ~p",[Response#dubbo_response.mid,SourcePid]),
RpcContent=[],
%% ResponseData = de_type_transfer:response_to_native(Response),
%% lager:debug("one response ~p",[Response]),
%% logger:debug("one response ~p",[Response]),
gen_server:cast(SourcePid,{msg_back,Ref,Response,RpcContent,RequestState3})
end,
{ok,State};

0 comments on commit 50126a2

Please sign in to comment.