Skip to content

Commit

Permalink
implemented changes as discussed on PR 69
Browse files Browse the repository at this point in the history
  • Loading branch information
GalaxyGorilla committed Sep 15, 2015
1 parent c5b1983 commit a885f9b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/hello_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ incoming_message({error, Reason, NewTransportState}, State = #client_state{id =
[ClientId, Reason], gen_meta_fields(State), ?LOGID07),
{noreply, State#client_state{transport_state = NewTransportState}};
incoming_message({ok, Signature, BinResponse, NewTransportState}, State = #client_state{async_request_map = AsyncMap,
protocol_mod = ProtocolMod, protocol_opts = ProtocolOpts, id = ClientId}) ->
protocol_mod = ProtocolMod, protocol_opts = ProtocolOpts, id = ClientId}) ->
case hello_proto:decode(ProtocolMod, ProtocolOpts, Signature, BinResponse, response) of
{ok, #response{id = null, response = Response}} ->
?LOG_DEBUG("Hello client '~p' received notification.", [ClientId],
Expand Down Expand Up @@ -396,7 +396,7 @@ request_reply(Response, AsyncMap, State) ->
{noreply, State#client_state{async_request_map = NewAsyncMap}};
{not_found, RequestId, NewAsyncMap} ->
?LOG_INFO("Hello client '~p' got response for non-existing request id '~p'.",
[RequestId], gen_meta_fields(Response, State), ?LOGID19),
[RequestId], gen_meta_fields(Response, State), ?LOGID19),
{noreply, State#client_state{async_request_map = NewAsyncMap}}
end.

Expand Down
8 changes: 4 additions & 4 deletions src/hello_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ get_handler(Name, Identifier, HandlerMod, HandlerArgs) ->
case hello_registry:lookup({handler, Name, Identifier}) of
{error, not_found} ->
?LOG_DEBUG("Handler for service ~p and identifier ~p not found. Starting handler.",
[Name, Identifier], [], ?LOGID22),
[Name, Identifier], [], ?LOGID22),
start_handler(Identifier, HandlerMod, HandlerArgs);
{ok, _, Handler} ->
?LOG_DEBUG("Found handler ~p for service ~p and identifier ~p.", [Handler, Name, Identifier], [], ?LOGID23),
Expand Down Expand Up @@ -158,7 +158,7 @@ handle_cast({async_reply, ReqContext, Result}, State = #state{id = Id, async_rep
{noreply, State#state{async_reply_map = gb_trees:delete(ReqRef, AsyncMap)}};
none ->
?LOG_WARNING_reason(Mod, Id, "Hello handler with callback module '~p' and service id '~p' got unknown async reply.",
[Mod, Id], {unknown_async_reply, {ReqRef, Result}}, ?LOGID26),
[Mod, Id], {unknown_async_reply, {ReqRef, Result}}, ?LOGID26),
{noreply, State}
end.

Expand All @@ -170,12 +170,12 @@ handle_call(_Call, _From, State) ->
handle_info({?IDLE_TIMEOUT_MSG, TimerRef}, State = #state{timer = Timer, id = Id, mod = Mod})
when Timer#timer.idle_timeout_ref == TimerRef ->
?LOG_WARNING_reason(Mod, Id, "Hello handler with callback module '~p' and service id '~p' is going to stop due to idle timeout.",
[Mod, Id], {error, idle_timeout}, ?LOGID27),
[Mod, Id], {error, idle_timeout}, ?LOGID27),
NewTimer = Timer#timer{stopped_because_idle = true},
{stop, normal, State#state{timer = NewTimer}};
handle_info({?IDLE_TIMEOUT_MSG, OtherRef}, State = #state{mod = Mod, id = Id}) ->
?LOG_WARNING_reason(Mod, Id, "Hello handler with callback module '~p' and service id '~p' received unknown idle timeout message.",
[Mod, Id], {error, {unknown_timeout_message, OtherRef}}, ?LOGID28),
[Mod, Id], {error, {unknown_timeout_message, OtherRef}}, ?LOGID28),
{noreply, State};
handle_info({?INCOMING_MSG, Request = #request{context = Context}}, State0) ->
State = reset_idle_timeout(State0),
Expand Down
9 changes: 5 additions & 4 deletions src/transports/hello_http_listener.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
-include_lib("ex_uri/include/ex_uri.hrl").

-record(http_listener_state, {
url :: #ex_uri{}
url :: #ex_uri{},
encoded_url :: string()
}).

%% --------------------------------------------------------------------------------
%% -- hello_binding callbacks
listener_specification(ExUriUrl, ListenerOpts) ->
% cowboy dispatch
State = #http_listener_state{ url = ExUriUrl },
State = #http_listener_state{ url = ExUriUrl, encoded_url = ex_uri:encode(ExUriUrl) },
Dispatch = cowboy_router:compile([{'_', [{'_', ?MODULE, [State]}]}]),
%% Copied from cowboy.erl because it doesn't provide an API that
%% allows supervising the listener from the calling application yet.
Expand Down Expand Up @@ -180,5 +181,5 @@ extract_ip_and_host(#ex_uri{authority = #ex_uri_authority{host = Host}}) ->
end
end.

gen_meta_fields(#http_listener_state{url = Url}) ->
[{hello_transport, http}, {hello_transport_url, ex_uri:encode(Url)}].
gen_meta_fields(#http_listener_state{encoded_url = EncUrl}) ->
[{hello_transport, http}, {hello_transport_url, EncUrl}].
18 changes: 10 additions & 8 deletions src/transports/hello_zmq_listener.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ port(_ExUriUrl, ListenerId) ->
%% --------------------------------------------------------------------------------
%% -- gen_server callbacks
-record(state, {
url :: #ex_uri{},
lastmsg_peer :: binary(),
encode_info :: binary(),
socket :: ezmq:socket()
url :: #ex_uri{},
encoded_url :: string(),
lastmsg_peer :: binary(),
encode_info :: binary(),
socket :: ezmq:socket()
}).

start_link(URL) ->
Expand All @@ -67,13 +68,14 @@ start_link(URL) ->
init(URL) ->
process_flag(trap_exit, true),
{ok, Socket} = ezmq:socket([{type, router}, {active, true}]),
EncUrl = ex_uri:encode(URL),
case ezmq_bind_url(Socket, URL) of
ok ->
State = #state{socket = Socket, url = URL},
State = #state{socket = Socket, url = URL, encoded_url = EncUrl},
{ok, State};
{error, Error} ->
?LOG_INFO("Hello ZeroMQ listener was unable to bind on '~p' because of reason '~p'.", [URL, Error],
[{hello_transport, zmtp}, {hello_transport_url, ex_uri:encode(URL)}], ?LOGID47),
[{hello_transport, zmtp}, {hello_transport_url, EncUrl}], ?LOGID47),
{stop, Error}
end.

Expand Down Expand Up @@ -149,5 +151,5 @@ ezmq_ip(inet6, Host) ->
inet:parse_ipv6_address(Host)
end.

gen_meta_fields(#state{url = Url}) ->
[{hello_transport, zmtp}, {hello_transport_url, ex_uri:encode(Url)}].
gen_meta_fields(#state{encoded_url = EncUrl}) ->
[{hello_transport, zmtp}, {hello_transport_url, EncUrl}].

0 comments on commit a885f9b

Please sign in to comment.