WIP: rearrange client code to approach some semblance of modularity someday
This commit is contained in:
parent
a06055ac23
commit
a8c5879d21
1 changed files with 42 additions and 30 deletions
|
@ -77,8 +77,6 @@
|
||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||||
terminate/2, code_change/3]).
|
terminate/2, code_change/3]).
|
||||||
|
|
||||||
-define(FLU_C, machi_flu1_client).
|
|
||||||
|
|
||||||
-record(state, {
|
-record(state, {
|
||||||
i :: #p_srvr{},
|
i :: #p_srvr{},
|
||||||
sock :: 'undefined' | port()
|
sock :: 'undefined' | port()
|
||||||
|
@ -308,22 +306,30 @@ do_req(Req, S) ->
|
||||||
{{error, partition}, S2}
|
{{error, partition}, S2}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
make_req_fun({append_chunk, EpochID, Prefix, Chunk}, #state{sock=Sock}) ->
|
make_req_fun({append_chunk, EpochID, Prefix, Chunk},
|
||||||
fun() -> ?FLU_C:append_chunk(Sock, EpochID, Prefix, Chunk) end;
|
#state{sock=Sock,i=#p_srvr{proto_mod=Mod}}) ->
|
||||||
make_req_fun({append_chunk_extra, EpochID, Prefix, Chunk, ChunkExtra}, #state{sock=Sock}) ->
|
fun() -> Mod:append_chunk(Sock, EpochID, Prefix, Chunk) end;
|
||||||
fun() -> ?FLU_C:append_chunk_extra(Sock, EpochID, Prefix, Chunk, ChunkExtra) end;
|
make_req_fun({append_chunk_extra, EpochID, Prefix, Chunk, ChunkExtra},
|
||||||
make_req_fun({read_chunk, EpochID, File, Offset, Size}, #state{sock=Sock}) ->
|
#state{sock=Sock,i=#p_srvr{proto_mod=Mod}}) ->
|
||||||
fun() -> ?FLU_C:read_chunk(Sock, EpochID, File, Offset, Size) end;
|
fun() -> Mod:append_chunk_extra(Sock, EpochID, Prefix, Chunk, ChunkExtra) end;
|
||||||
make_req_fun({write_chunk, EpochID, File, Offset, Chunk}, #state{sock=Sock}) ->
|
make_req_fun({read_chunk, EpochID, File, Offset, Size},
|
||||||
fun() -> ?FLU_C:write_chunk(Sock, EpochID, File, Offset, Chunk) end;
|
#state{sock=Sock,i=#p_srvr{proto_mod=Mod}}) ->
|
||||||
make_req_fun({checksum_list, EpochID, File}, #state{sock=Sock}) ->
|
fun() -> Mod:read_chunk(Sock, EpochID, File, Offset, Size) end;
|
||||||
fun() -> ?FLU_C:checksum_list(Sock, EpochID, File) end;
|
make_req_fun({write_chunk, EpochID, File, Offset, Chunk},
|
||||||
make_req_fun({list_files, EpochID}, #state{sock=Sock}) ->
|
#state{sock=Sock,i=#p_srvr{proto_mod=Mod}}) ->
|
||||||
fun() -> ?FLU_C:list_files(Sock, EpochID) end;
|
fun() -> Mod:write_chunk(Sock, EpochID, File, Offset, Chunk) end;
|
||||||
make_req_fun({wedge_status}, #state{sock=Sock}) ->
|
make_req_fun({checksum_list, EpochID, File},
|
||||||
fun() -> ?FLU_C:wedge_status(Sock) end;
|
#state{sock=Sock,i=#p_srvr{proto_mod=Mod}}) ->
|
||||||
make_req_fun({get_epoch_id}, #state{sock=Sock}) ->
|
fun() -> Mod:checksum_list(Sock, EpochID, File) end;
|
||||||
fun() -> case ?FLU_C:read_latest_projection(Sock, private) of
|
make_req_fun({list_files, EpochID},
|
||||||
|
#state{sock=Sock,i=#p_srvr{proto_mod=Mod}}) ->
|
||||||
|
fun() -> Mod:list_files(Sock, EpochID) end;
|
||||||
|
make_req_fun({wedge_status},
|
||||||
|
#state{sock=Sock,i=#p_srvr{proto_mod=Mod}}) ->
|
||||||
|
fun() -> Mod:wedge_status(Sock) end;
|
||||||
|
make_req_fun({get_epoch_id},
|
||||||
|
#state{sock=Sock,i=#p_srvr{proto_mod=Mod}}) ->
|
||||||
|
fun() -> case Mod:read_latest_projection(Sock, private) of
|
||||||
{ok, P} ->
|
{ok, P} ->
|
||||||
#projection_v1{epoch_number=Epoch,
|
#projection_v1{epoch_number=Epoch,
|
||||||
epoch_csum=CSum} =
|
epoch_csum=CSum} =
|
||||||
|
@ -333,18 +339,24 @@ make_req_fun({get_epoch_id}, #state{sock=Sock}) ->
|
||||||
Error
|
Error
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
make_req_fun({get_latest_epoch, ProjType}, #state{sock=Sock}) ->
|
make_req_fun({get_latest_epoch, ProjType},
|
||||||
fun() -> ?FLU_C:get_latest_epoch(Sock, ProjType) end;
|
#state{sock=Sock,i=#p_srvr{proto_mod=Mod}}) ->
|
||||||
make_req_fun({read_latest_projection, ProjType}, #state{sock=Sock}) ->
|
fun() -> Mod:get_latest_epoch(Sock, ProjType) end;
|
||||||
fun() -> ?FLU_C:read_latest_projection(Sock, ProjType) end;
|
make_req_fun({read_latest_projection, ProjType},
|
||||||
make_req_fun({read_projection, ProjType, Epoch}, #state{sock=Sock}) ->
|
#state{sock=Sock,i=#p_srvr{proto_mod=Mod}}) ->
|
||||||
fun() -> ?FLU_C:read_projection(Sock, ProjType, Epoch) end;
|
fun() -> Mod:read_latest_projection(Sock, ProjType) end;
|
||||||
make_req_fun({write_projection, ProjType, Proj}, #state{sock=Sock}) ->
|
make_req_fun({read_projection, ProjType, Epoch},
|
||||||
fun() -> ?FLU_C:write_projection(Sock, ProjType, Proj) end;
|
#state{sock=Sock,i=#p_srvr{proto_mod=Mod}}) ->
|
||||||
make_req_fun({get_all_projections, ProjType}, #state{sock=Sock}) ->
|
fun() -> Mod:read_projection(Sock, ProjType, Epoch) end;
|
||||||
fun() -> ?FLU_C:get_all_projections(Sock, ProjType) end;
|
make_req_fun({write_projection, ProjType, Proj},
|
||||||
make_req_fun({list_all_projections, ProjType}, #state{sock=Sock}) ->
|
#state{sock=Sock,i=#p_srvr{proto_mod=Mod}}) ->
|
||||||
fun() -> ?FLU_C:list_all_projections(Sock, ProjType) end.
|
fun() -> Mod:write_projection(Sock, ProjType, Proj) end;
|
||||||
|
make_req_fun({get_all_projections, ProjType},
|
||||||
|
#state{sock=Sock,i=#p_srvr{proto_mod=Mod}}) ->
|
||||||
|
fun() -> Mod:get_all_projections(Sock, ProjType) end;
|
||||||
|
make_req_fun({list_all_projections, ProjType},
|
||||||
|
#state{sock=Sock,i=#p_srvr{proto_mod=Mod}}) ->
|
||||||
|
fun() -> Mod:list_all_projections(Sock, ProjType) end.
|
||||||
|
|
||||||
connected_p(#state{sock=SockMaybe,
|
connected_p(#state{sock=SockMaybe,
|
||||||
i=#p_srvr{proto_mod=Mod}=_I}=_S) ->
|
i=#p_srvr{proto_mod=Mod}=_I}=_S) ->
|
||||||
|
|
Loading…
Reference in a new issue