소스 검색

代码修改

erlArango_v1
AICells 5 년 전
부모
커밋
eef3ea18a6
3개의 변경된 파일31개의 추가작업 그리고 188개의 파일을 삭제
  1. +11
    -0
      src/arangoApi/agDbMgr.erl
  2. +0
    -91
      src/arangoApi/genActor.erlbak
  3. +20
    -97
      src/httpCli/agHttpCli.erl

+ 11
- 0
src/arangoApi/agDbMgr.erl 파일 보기

@ -0,0 +1,11 @@
-module(agDbMgr).
-export([]).
%% _system访访
%%
% GET /_api/database/current
dbCurrent(PoolName) ->
ok.

+ 0
- 91
src/arangoApi/genActor.erlbak 파일 보기

@ -1,91 +0,0 @@
-module(genActor).
-compile(inline).
-compile({inline_size, 128}).
-export([
start_link/3,
init_it/3,
system_code_change/4,
system_continue/3,
system_get_state/1,
system_terminate/4
]).
-spec start_link(module(), atom(), term(), [proc_lib:spawn_option()]) -> {ok, pid()}.
start_link(Name, Args, SpawnOpts) ->
proc_lib:start_link(?MODULE, init_it, [Name, self(), Args], infinity, SpawnOpts).
init_it(Name, Parent, Args) ->
case safeRegister(Name) of
true ->
process_flag(trap_exit, true),
moduleInit(Parent, Args);
{false, Pid} ->
proc_lib:init_ack(Parent, {error, {already_started, Pid}})
end.
%% sys callbacks
-spec system_code_change(term(), module(), undefined | term(), term()) -> {ok, term()}.
system_code_change(State, _Module, _OldVsn, _Extra) ->
{ok, State}.
-spec system_continue(pid(), [], {module(), atom(), pid(), term()}) -> ok.
system_continue(_Parent, _Debug, {Parent, State}) ->
loop(Parent, State).
-spec system_get_state(term()) -> {ok, term()}.
system_get_state(State) ->
{ok, State}.
-spec system_terminate(term(), pid(), [], term()) -> none().
system_terminate(Reason, _Parent, _Debug, _State) ->
exit(Reason).
safeRegister(Name) ->
try register(Name, self()) of
true -> true
catch
_:_ -> {false, whereis(Name)}
end.
moduleInit(Parent, Args) ->
case ?MODULE:init(Args) of
{ok, State} ->
proc_lib:init_ack(Parent, {ok, self()}),
loop(Parent, State);
{stop, Reason} ->
proc_lib:init_ack(Parent, {error, Reason}),
exit(Reason)
end.
loop(Parent, State) ->
receive
{system, From, Request} ->
sys:handle_system_msg(Request, From, Parent, ?MODULE, [], {Parent, State});
{'EXIT', Parent, Reason} ->
terminate(Reason, State);
Msg ->
{ok, NewState} = ?MODULE:handleMsg(Msg, State),
loop(Parent, NewState)
end.
terminate(Reason, State) ->
?MODULE:terminate(Reason, State),
exit(Reason).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% need %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec init(Args :: term()) -> {ok, term()}.
init(Args) ->
{ok, {}}.
-spec handleMsg(Msg :: term(), State :: term()) -> {ok, term()}.
handleMsg(Msg, State) ->
{ok, term}.
-spec terminate(Reason :: term(), State :: term()) -> ok.
terminate(Reason, State) ->
ok.

+ 20
- 97
src/httpCli/agHttpCli.erl 파일 보기

@ -5,25 +5,11 @@
-compile({inline_size, 128}).
-export([
syncGet/3
, syncPost/3
, syncPut/3
, syncGet/4
, syncPost/4
, syncPut/4
, syncRequest/5
, asyncGet/2
, asyncPost/2
, asyncPut/2
, asyncCustom/3
, asyncRequest/3
, callAgency/2
, callAgency/3
, castAgency/2
, castAgency/3
, castAgency/4
callAgency/5
, callAgency/6
, castAgency/5
, castAgency/6
, castAgency/7
, receiveResponse/1
, startPool/2
@ -33,92 +19,29 @@
]).
-spec syncGet(dbUrl(), headers(), body()) -> {ok, recvState()} | error().
syncGet(Url, Headers, Body) ->
syncRequest(<<"GET">>, Url, Headers, Body, ?DEFAULT_TIMEOUT).
-spec syncGet(dbUrl(), headers(), body(), timeout()) -> {ok, recvState()} | error().
syncGet(Url, Headers, Body, Timeout) ->
syncRequest(<<"GET">>, Url, Headers, Body, Timeout).
-spec syncPost(dbUrl(), headers(), body()) -> {ok, recvState()} | error().
syncPost(Url, Headers, Body) ->
syncRequest(<<"POST">>, Url, Headers, Body, ?DEFAULT_TIMEOUT).
-spec syncPost(dbUrl(), headers(), body(), timeout()) -> {ok, recvState()} | error().
syncPost(Url, Headers, Body, Timeout) ->
syncRequest(<<"POST">>, Url, Headers, Body, Timeout).
-spec syncPut(dbUrl(), headers(), body()) -> {ok, recvState()} | error().
syncPut(Url, Headers, Body) ->
syncRequest(<<"PUT">>, Url, Headers, Body, ?DEFAULT_TIMEOUT).
-spec syncPut(dbUrl(), headers(), body(), timeout()) -> {ok, recvState()} | error().
syncPut(Url, Headers, Body, Timeout) ->
syncRequest(<<"PUT">>, Url, Headers, Body, Timeout).
%% -spec syncCustom(binary(), dbUrl(), httpParam()) -> {ok, requestRet()} | error().
%% syncCustom(Verb, Url, Headers, Body) ->
%% syncRequest({custom, Verb}, Url, Headers, Body).
-spec syncRequest(method(), dbUrl(), headers(), body(), timeout()) -> {ok, recvState()} | error().
syncRequest(Method, #dbUrl{
host = Host,
path = Path,
poolName = PoolName
}, Headers, Body, Timeout) ->
Request = {request, Method, Path, Headers, Host, Body},
callAgency(PoolName, Request, Timeout).
-spec asyncGet(dbUrl(), httpParam()) -> {ok, requestId()} | error().
asyncGet(Url, HttpParam) ->
asyncRequest(<<"GET">>, Url, HttpParam).
-spec asyncPost(dbUrl(), httpParam()) ->
{ok, shackle:request_id()} | error().
asyncPost(Url, HttpParam) ->
asyncRequest(<<"POST">>, Url, HttpParam).
-spec asyncPut(dbUrl(), httpParam()) -> {ok, requestId()} | error().
asyncPut(Url, HttpParam) ->
asyncRequest(<<"PUT">>, Url, HttpParam).
-spec asyncCustom(binary(), dbUrl(), httpParam()) -> {ok, requestId()} | error().
asyncCustom(Verb, Url, HttpParam) ->
asyncRequest({custom, Verb}, Url, HttpParam).
-spec asyncRequest(method(), dbUrl(), httpParam()) -> {ok, requestId()} | error().
asyncRequest(Method,
#dbUrl{path = Path, poolName = PoolName},
#httpParam{headers = Headers, body = Body, pid = Pid, timeout = Timeout}) ->
RequestContent = {Method, Path, Headers, Body},
castAgency(PoolName, RequestContent, Pid, Timeout).
-spec callAgency(poolName(), term()) -> term() | {error, term()}.
callAgency(PoolName, Request) ->
callAgency(PoolName, Request, ?DEFAULT_TIMEOUT).
-spec callAgency(poolName(), method(), path(), headers(), body()) -> term() | {error, term()}.
callAgency(PoolName, Method, Path, Headers, Body) ->
callAgency(PoolName, Method, Path, Headers, Body, infinity).
-spec callAgency(atom(), term(), timeout()) -> term() | {error, atom()}.
callAgency(PoolName, Request, Timeout) ->
case castAgency(PoolName, Request, self(), Timeout) of
-spec callAgency(poolName(), method(), path(), headers(), body(), timeout()) -> term() | {error, atom()}.
callAgency(PoolName, Method, Path, Headers, Body, Timeout) ->
case castAgency(PoolName, Method, Path, Headers, Body, Timeout, self()) of
{ok, RequestId} ->
%io:format("IMY************************ todo receiveResponse ~p ~n", [RequestId]),
receiveResponse(RequestId);
{error, Reason} ->
{error, Reason}
end.
-spec castAgency(poolName(), term()) -> {ok, requestId()} | {error, atom()}.
castAgency(PoolName, Request) ->
castAgency(PoolName, Request, self()).
-spec castAgency(poolName(), method(), path(), headers(), body()) -> {ok, requestId()} | {error, atom()}.
castAgency(PoolName, Method, Path, Headers, Body) ->
castAgency(PoolName, Method, Path, Headers, Body, infinity, self()).
-spec castAgency(poolName(), term(), pid()) -> {ok, requestId()} | {error, atom()}.
castAgency(PoolName, Request, Pid) ->
castAgency(PoolName, Request, Pid, ?DEFAULT_TIMEOUT).
-spec castAgency(poolName(), method(), path(), headers(), body(), timeout()) -> {ok, requestId()} | {error, atom()}.
castAgency(PoolName, Method, Path, Headers, Body, Timeout) ->
castAgency(PoolName, Method, Path, Headers, Body, Timeout, self()).
-spec castAgency(poolName(), term(), pid(), timeout()) -> {ok, requestId()} | {error, atom()}.
castAgency(PoolName, {Method, Path, Headers, Body}, Pid, Timeout) ->
-spec castAgency(poolName(), method(), path(), headers(), body(), timeout(), pid()) -> {ok, requestId()} | {error, atom()}.
castAgency(PoolName, Method, Path, Headers, Body, Timeout, Pid) ->
case agAgencyPoolMgrIns:getOneAgency(PoolName) of
{error, pool_not_found} = Error ->
Error;
@ -135,7 +58,7 @@ castAgency(PoolName, {Method, Path, Headers, Body}, Pid, Timeout) ->
receiveResponse(RequestId) ->
receive
#miAgHttpCliRet{requestId = RequestId, reply = Reply} ->
io:format("IMY************************ miAgHttpCliRet ~p ~p ~n", [111, size(element(4, Reply))]),
%io:format("IMY************************ miAgHttpCliRet ~p ~p ~n", [111, size(element(4, Reply))]),
Reply
end.

불러오는 중...
취소
저장