From eef3ea18a633c6fae2e0e3c4c31bd7ab7cb120c7 Mon Sep 17 00:00:00 2001 From: AICells <1713699517@qq.com> Date: Mon, 30 Dec 2019 00:03:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/arangoApi/agDbMgr.erl | 11 ++++ src/arangoApi/genActor.erlbak | 91 -------------------------- src/httpCli/agHttpCli.erl | 117 ++++++---------------------------- 3 files changed, 31 insertions(+), 188 deletions(-) create mode 100644 src/arangoApi/agDbMgr.erl delete mode 100644 src/arangoApi/genActor.erlbak diff --git a/src/arangoApi/agDbMgr.erl b/src/arangoApi/agDbMgr.erl new file mode 100644 index 0000000..5f7e72a --- /dev/null +++ b/src/arangoApi/agDbMgr.erl @@ -0,0 +1,11 @@ +-module(agDbMgr). + +-export([]). + + +%% 请注意,所有数据库管理操作只能通过默认数据库(_system)访问,而不能通过其他数据库访问。 + +%% 检索有关当前数据库的信息 +% GET /_api/database/current +dbCurrent(PoolName) -> + ok. \ No newline at end of file diff --git a/src/arangoApi/genActor.erlbak b/src/arangoApi/genActor.erlbak deleted file mode 100644 index b406b04..0000000 --- a/src/arangoApi/genActor.erlbak +++ /dev/null @@ -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. diff --git a/src/httpCli/agHttpCli.erl b/src/httpCli/agHttpCli.erl index e7f9f8f..86c1fa2 100644 --- a/src/httpCli/agHttpCli.erl +++ b/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.