Skip to content

Commit

Permalink
3.19: uniquely start event processes
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesaimonetti committed Mar 6, 2015
1 parent 6e3b8a5 commit 059feee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion applications/ecallmgr/src/ecallmgr.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@
-define(FS_EVENT_REG_MSG(Node, EvtName), {'event', Node, EvtName}).
-define(FS_CALL_EVENT_REG_MSG(Node, EvtName), {'call_event', Node, EvtName}).
-define(FS_CALL_EVENTS_PROCESS_REG(Node, CallId)
,{'call_events_process', Node, CallId}
,{'n', 'l', {'call_events_process', Node, CallId}}
).

-define(FS_CARRIER_ACL_LIST, <<"trusted">>).
Expand Down
2 changes: 1 addition & 1 deletion applications/ecallmgr/src/ecallmgr_call_event_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ start_link() ->

-spec start_proc(list()) -> sup_startchild_ret().
start_proc([Node, CallId|_]=Args) ->
case gproc:lookup_values({'p', 'l', ?FS_CALL_EVENTS_PROCESS_REG(Node, CallId)}) of
case gproc:lookup_values(?FS_CALL_EVENTS_PROCESS_REG(Node, CallId)) of
[] ->
lager:debug("no registrations for ~s", [Node]),
supervisor:start_child(?SERVER, Args);
Expand Down
16 changes: 11 additions & 5 deletions applications/ecallmgr/src/ecallmgr_call_events.erl
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ handle_publisher_usurp(JObj, Props) ->
%%--------------------------------------------------------------------
-spec init([atom() | ne_binary(),...]) -> {'ok', state()}.
init([Node, CallId]) when is_atom(Node) andalso is_binary(CallId) ->
try gproc:reg(?FS_CALL_EVENTS_PROCESS_REG(Node, CallId)) of
'true' -> init(Node, CallId)
catch
_E:_R ->
lager:debug("failed to register for ~s:~s: ~s:~p", [Node, CallId, _E, _R]),
{'stop', 'normal'}
end.

init(Node, CallId) ->
wh_util:put_callid(CallId),
register_for_events(Node, CallId),
gen_listener:cast(self(), 'init'),
Expand Down Expand Up @@ -288,13 +297,11 @@ handle_cast(_Msg, State) ->

-spec register_for_events(atom(), ne_binary()) -> 'true'.
register_for_events(Node, CallId) ->
update_events(Node, CallId, fun gproc:reg/1),
catch gproc:reg({'p', 'l', ?FS_CALL_EVENTS_PROCESS_REG(Node, CallId)}, self()).
update_events(Node, CallId, fun gproc:reg/1).

-spec unregister_for_events(atom(), ne_binary()) -> 'true'.
unregister_for_events(Node, CallId) ->
update_events(Node, CallId, fun gproc:unreg/1),
catch gproc:unreg({'p', 'l', ?FS_CALL_EVENTS_PROCESS_REG(Node, CallId)}, self()).
update_events(Node, CallId, fun gproc:unreg/1).

-spec update_events(atom(), ne_binary(), function()) -> 'true'.
update_events(Node, CallId, Fun) ->
Expand Down Expand Up @@ -440,7 +447,6 @@ handle_info('timeout', #state{node=Node
{'stop', 'normal', State};
{'ok', <<"true">>} ->
lager:debug("processing call events from ~s", [Node]),
'true' = gproc:reg({'p', 'l', ?FS_CALL_EVENTS_PROCESS_REG(Node, CallId)}, self()),
'true' = gproc:reg({'p', 'l', ?FS_CALL_EVENT_REG_MSG(Node, CallId)}),
'true' = gproc:reg({'p', 'l', ?FS_EVENT_REG_MSG(Node, ?CHANNEL_MOVE_RELEASED_EVENT_BIN)}),
_ = usurp_other_publishers(State),
Expand Down

0 comments on commit 059feee

Please sign in to comment.