Skip to content
Permalink
Browse files
remove unused code
  • Loading branch information
DLive committed Apr 30, 2020
1 parent a62b956 commit 24e0c1a9028b50d2e9e05e3fe26f4e3335384acc
Showing 6 changed files with 16 additions and 42 deletions.
@@ -68,8 +68,7 @@ init({Ref, Socket, Transport, _Opts}) ->
#state{socket = Socket, transport = Transport},
?IDLE_TIMEOUT).

handle_info({tcp, _Port, Data}, #state{recv_buffer = RecvBuffer, socket = Socket, transport = Transport} = State) ->
%% Transport:setopts(Socket, [{active, once}]),
handle_info({tcp, _Port, Data}, #state{recv_buffer = RecvBuffer} = State) ->
NowBuffer = <<RecvBuffer/binary, Data/binary>>,

{ok, NextBuffer, NewState} = case check_recv_data(NowBuffer, State) of
@@ -79,7 +78,6 @@ handle_info({tcp, _Port, Data}, #state{recv_buffer = RecvBuffer, socket = Socket
logger:debug("[INFO] recv one data state wait next_buffer"),
{ok, NextBuffer2, State3}
end,
%% HeartbeatInfo =update_heartbeat(write,NewState#state.heartbeat),
{noreply, NewState#state{recv_buffer = NextBuffer}, ?IDLE_TIMEOUT};

handle_info({tcp_closed, _Socket}, State) ->
@@ -179,20 +177,10 @@ process_data(Data, State) ->

%% @doc process event
-spec process_response(IsEvent :: boolean(), #dubbo_response{}, #state{}) -> ok.
process_response(true, Response, State) ->
%%
process_response(true, _Response, State) ->
{ok, State};

process_response(false, Response, State) ->
%% case get_earse_request_info(Response#dubbo_response.mid) of
%% undefined->
%% logger:error("dubbo response can't find request data,response ~p",[Response]);
%% {SourcePid,Ref,Request} ->
%% 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),
%% gen_server:cast(SourcePid,{msg_back,Ref,ResponseData,RpcContent})
%% end,
process_response(false, _Response, State) ->
{ok, State}.

process_request(true, Request, State) ->
@@ -67,14 +67,7 @@ init([]) ->
MaxSecondsBetweenRestarts = 3600,

SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts},

Restart = permanent,
Shutdown = 2000,
Type = worker,

AChild = {'AName', {'AModule', start_link, []},
Restart, Shutdown, Type, ['AModule']},


PoolArgs = [{name, {local, provider_worker}},
{worker_module, dubbo_provider_worker},
{size, 5},
@@ -346,7 +346,7 @@ check_and_create_path(Pid, RootPath, [{Item, CreateType} | Rst]) ->
CheckPath = <<RootPath/binary, <<"/">>/binary, Item/binary>>,

case erlzk:exists(Pid, CheckPath) of
{ok, Stat} ->
{ok, _Stat} ->
check_and_create_path(Pid, CheckPath, Rst);
{error, no_node} ->
logger:debug("check_and_create_path unexist no_node ~p", [CheckPath]),
@@ -122,7 +122,7 @@ decode_header(Header) ->
{DecodeState, Req} = decode_header(request, Flag, State, Mid, DataLen),
{DecodeState, request, Req}
end.
decode_header(request, Flag, State, Mid, DataLen) ->
decode_header(request, Flag, _State, Mid, _DataLen) ->
SerializeType = Flag band 16#1f,
IsTwoWay = if
(Flag band 16#40) /= 0 -> true;
@@ -140,7 +140,7 @@ decode_header(request, Flag, State, Mid, DataLen) ->
serialize_type = SerializeType
},
{ok, Req};
decode_header(response, Flag, State, Mid, DataLen) ->
decode_header(response, Flag, State, Mid, _DataLen) ->
SerializeType = Flag band 16#1f,
IsEvent = if
(Flag band 16#20) /= 0 -> true;
@@ -191,7 +191,7 @@ decode_request(Req, Data) ->

decode_request(dubbo_rpc_invocation, Req, Data) ->
{ResultList, _NewState, _RestData} = decode_request_body(Data, cotton_hessian:init(), [dubbo, path, version, method_name, desc_and_args, attachments]),
[_DubboVersion, Path, Version, MethodName, Desc, ArgsObj, Attachments] = ResultList,
[_DubboVersion, Path, Version, MethodName, _Desc, ArgsObj, Attachments] = ResultList,
RpcData = #dubbo_rpc_invocation{className = trans_path_to_classname(Path), classVersion = Version, methodName = MethodName, parameterDesc = Data, parameters = ArgsObj, attachments = Attachments},
Req2 = Req#dubbo_request{data = RpcData},
{ok, Req2};
@@ -19,7 +19,7 @@

-include("dubbo.hrl").
%% API
-export([decode_response/2, decode_request/2, decode_header/1, decode_request/2]).
-export([decode_response/2, decode_request/2, decode_header/1]).

-export([encode_request_data/1, encode_response_data/1]).

@@ -73,7 +73,7 @@ encode_response_data(Response) ->
{ok, Bin} = encode_response_data(DataType, Response, Response#dubbo_response.data, State),
{ok, Bin}.

encode_response_data(dubbo_event, _Response, Data, State) ->
encode_response_data(dubbo_event, _Response, Data, _State) ->
Bin = jsx:encode(Data),
{ok, Bin};
encode_response_data(dubbo_rpc_invocation, _Response, Data, State) ->
@@ -113,7 +113,7 @@ decode_header(Header) ->
{DecodeState, Req} = decode_header(request, Flag, State, Mid, DataLen),
{DecodeState, request, Req}
end.
decode_header(request, Flag, State, Mid, DataLen) ->
decode_header(request, Flag, _State, Mid, _DataLen) ->
SerializeType = Flag band 16#1f,
IsTwoWay = if
(Flag band 16#40) /= 0 -> true;
@@ -131,7 +131,7 @@ decode_header(request, Flag, State, Mid, DataLen) ->
serialize_type = SerializeType
},
{ok, Req};
decode_header(response, Flag, State, Mid, DataLen) ->
decode_header(response, Flag, State, Mid, _DataLen) ->
SerializeType = Flag band 16#1f,
IsEvent = if
(Flag band 16#20) /= 0 -> true;
@@ -155,12 +155,10 @@ decode_response(Res, Data) ->
decode_response(dubbo_rpc_invocation, Res, Data) ->
DataList = binary:split(Data, <<"\n">>, [global]),
[TypeBin | DataList1] = DataList,
%% {Rest,Type,State} = cotton_hessian:decode(Data,cotton_hessian:init()),
Type = jsx:decode(TypeBin),

case Type of
?RESPONSE_VALUE ->
%% {_,Object,DecodeState} = cotton_hessian:decode(Rest,State),
[Value | _] = DataList1,
Object = jsx:decode(Value, [return_maps]),
{ok, Res#dubbo_response{data = Object}};
@@ -175,8 +173,7 @@ decode_response(dubbo_rpc_invocation, Res, Data) ->
{ok, Res#dubbo_response{data = <<"server pool exhausted">>}}

end;
decode_response(dubbo_event, Res, Data) ->
%% {_Rest,undefined,_NewState} = cotton_hessian:decode(Data,cotton_hessian:init()),
decode_response(dubbo_event, Res, _Data) ->
{ok, Res#dubbo_response{data = null}}.

-spec decode_request(#dubbo_request{}, binary()) -> {ok, #dubbo_request{}}.
@@ -189,8 +186,8 @@ decode_request(Req, Data) ->
end.

decode_request(dubbo_rpc_invocation, Req, Data) ->
{ResultList, NewState, RestData} = decode_request_body(Data, #{}, [dubbo, path, version, method_name, desc_and_args, attachments]),
[DubboVersion, Path, Version, MethodName, Desc, ArgsObj, Attachments] = ResultList,
{ResultList, _NewState, _RestData} = decode_request_body(Data, #{}, [dubbo, path, version, method_name, desc_and_args, attachments]),
[_DubboVersion, Path, Version, MethodName, Desc, ArgsObj, Attachments] = ResultList,
RpcData = #dubbo_rpc_invocation{className = Path, classVersion = Version, methodName = MethodName, parameterDesc = Desc, parameters = ArgsObj, attachments = Attachments},
Req2 = Req#dubbo_request{data = RpcData},
{ok, Req2};
@@ -230,7 +227,6 @@ decode_request_body([desc_and_args | List], [DescBin | Data], State, ResultList)
end;
decode_request_body([attachments | List], [DataItem | Data], State, ResultList) ->
Attachments = jsx:decode(DataItem, [return_maps]),
%% AttachmentsList = dict:to_list(Attachments#map.dict),
decode_request_body(List, Data, State, [Attachments] ++ ResultList);
decode_request_body([_Type1 | List], Data, State, ResultList) ->
logger:warning("decode_request_body unknow type"),
@@ -247,16 +243,13 @@ decode_request_body_args([ArgsType | RestList], Data, State, ArgsObjList) when A

decode_request_body_args([ArgsType | RestList], [DataItem | Data], State, ArgsObjList) ->
ArgObj = jsx:decode(DataItem, [return_maps]),
%% {Rest,ArgObj,NewState } = cotton_hessian:decode(Data,State),
ArgObj2 = dubbo_type_transfer:jsonobj_to_native(ArgsType, ArgObj, State),
decode_request_body_args(RestList, Data, State, ArgsObjList ++ [ArgObj2]).

string_encode(Data) when is_binary(Data) ->
<<<<"\"">>/binary, Data/binary, <<"\"">>/binary>>;
string_encode(Data) when is_tuple(Data) ->
[Name | _] = tuple_to_list(Data),
%% Size = record_info(size, Name),
%% Fields = record_info(fields, Name),
case dubbo_type_register:lookup_native_type(Name) of
undefined ->
<<"data encode error">>;
@@ -64,7 +64,7 @@ visit(NativeType, State = #encoding_state{pool = Pool}) ->
%% type_decoding:hash_store(NewTypeDef,NewState), %% 貌似这个没用,可以去掉.
%%%%%%%%%%%%%%%%%%%%%%%%%%
{hash, Ref, NewTypeDef, NewState};
{ok, {Ref, TypeDef}} ->
{ok, {Ref, _TypeDef}} ->
{ref, Ref};
error ->
case get_deftype_public_pool(NativeType) of

0 comments on commit 24e0c1a

Please sign in to comment.