Commits

Fred T-H  committed 21133ed

renaming usr_dispatch_manager to usr_manager to make a little more sense on its role. It doesn't just do dispatch...

  • Participants
  • Parent commits 494ef2b

Comments (0)

Files changed (4)

         undefined ->
             %% start it here
             usr_sup:start_link(UserId, TimeOut),
-            usr_dispatch_manager:add_handler(UserId, usr_dispatch_handler, UserId),
-            usr_dispatch_manager:add_handler(UserId, usr_history_handler, {UserId,HistoryLimit}),
+            usr_manager:add_handler(UserId, usr_dispatch_handler, UserId),
+            usr_manager:add_handler(UserId, usr_history_handler, {UserId,HistoryLimit}),
             io:format("started user process for id ~p~n",[UserId]),
             started;
         _Pid ->
 %%--------------------------------------------------------------------
 subscribe(UserId) ->
     HandlerId = {usr_listen_handler, make_ref()},
-    usr_dispatch_manager:add_sup_handler(UserId, HandlerId, {UserId, self(), HandlerId}),
+    usr_manager:add_sup_handler(UserId, HandlerId, {UserId, self(), HandlerId}),
     usr_monitor:add_handler(UserId, HandlerId),
     {ok, HandlerId}.
 
 %% user.
 %%--------------------------------------------------------------------
 subscribers(UserId) ->
-    usr_dispatch_manager:get_handlers(UserId).
+    usr_manager:get_handlers(UserId).
 
 %%--------------------------------------------------------------------
 %% Function: unsubscribe(UserId, HandlerId) -> ok
 %% Description: removes a client's listen handler from a user.
 %%--------------------------------------------------------------------
 unsubscribe(UserId, HandlerId) ->
-    usr_dispatch_manager:delete_handler(UserId, HandlerId, []),
+    usr_manager:delete_handler(UserId, HandlerId, []),
     usr_monitor:delete_handler(UserId, HandlerId),
     ok.
 
 %% Description: Takes a message and routes it through the sending user
 %%--------------------------------------------------------------------
 message(From, To, Message) ->
-    usr_dispatch_manager:notify(From, {send, To, Message}),
+    usr_manager:notify(From, {send, To, Message}),
     ok.
 
 %%--------------------------------------------------------------------
 %% message and routes it to the receiving user.
 %%--------------------------------------------------------------------
 relay(From, To, Message) ->
-    usr_dispatch_manager:notify(To, {received, From, Message}),
+    usr_manager:notify(To, {received, From, Message}),
     ok.
 
 %%--------------------------------------------------------------------
 %% that returns the last messages sent and received by UserId.
 %%--------------------------------------------------------------------
 history(UserId) ->
-    usr_dispatch_manager:notify(UserId, {self(), history}),
+    usr_manager:notify(UserId, {self(), history}),
     receive
         {UserId, {history, History}} ->
             History

File src/usr_dispatch_manager.erl

-%%%===================================================================
-%%% This event manager is part of the 3 processes making a user up.
-%%% It is responsible of holding all the handlers having to do with
-%%% message handling.
-%%%===================================================================
--module(usr_dispatch_manager).
-
-%% API
--export([start_link/1, add_handler/3, add_sup_handler/3, delete_handler/3,
-         notify/2, get_handlers/1]).
-
-%%--------------------------------------------------------------------
-%% Function: start_link() -> {ok,Pid} | {error,Error}
-%% Description: Creates an event manager.
-%% The user is global by default as we ought to support a multiple
-%% node system and will need more than a single process
-%%--------------------------------------------------------------------
-start_link(UserId) ->
-    gen_event:start_link({global, {manager, UserId}}).
-
-%%--------------------------------------------------------------------
-%% Function: add_handler(Module,Args) -> ok | {'EXIT',Reason} | term()
-%% Description: Adds an event handler
-%%--------------------------------------------------------------------
-add_handler(UserId, Handler = {_Module, _HandlerId}, Params) ->
-    gen_event:add_handler({global, {manager, UserId}}, Handler, Params);
-add_handler(UserId, Module, Params) when is_atom(Module) ->
-    gen_event:add_handler({global, {manager, UserId}}, Module, Params).
-
-%%--------------------------------------------------------------------
-%% Function: add_sup_handler(Module,Args) -> ok | {'EXIT',Reason} | term()
-%% Description: Adds an event handler that watches for the calling process'
-%% exit signals. This avoids having zombie listeners left over. The actual
-%% handling of errors is done in the callback module's terminate/2 function
-%%--------------------------------------------------------------------
-add_sup_handler(UserId, Handler = {_Module, _HandlerId}, Params) ->
-    gen_event:add_sup_handler({global, {manager, UserId}}, Handler, Params);
-add_sup_handler(UserId, Module, Params) when is_atom(Module) ->
-    gen_event:add_sup_handler({global, {manager, UserId}}, Module, Params).
-
-%%--------------------------------------------------------------------
-%% Function: delete_handler(UserId, Handler, Params) ->
-%% Description: Removes an event handler
-%%--------------------------------------------------------------------
-delete_handler(UserId, Handler, Params) ->
-    gen_event:delete_handler({global, {manager,UserId}}, Handler, Params).
-
-%%--------------------------------------------------------------------
-%% Function: get_handlers(UserId) -> [term()]
-%% Description: returns a list of all the handlers registered
-%%--------------------------------------------------------------------
-get_handlers(UserId) ->
-    gen_event:which_handlers({global, {manager, UserId}}).
-
-%%--------------------------------------------------------------------
-%% Function: notify(Event) -> ok | {error, Reason}
-%% Description: Sends the Event through the event manager.
-%%--------------------------------------------------------------------
-notify(UserId, Message) ->
-  gen_event:notify({global, {manager,UserId}}, Message).

File src/usr_manager.erl

+%%%===================================================================
+%%% This event manager is part of the 3 processes making a user up.
+%%% It is responsible of holding all the handlers having to do with
+%%% message handling.
+%%%===================================================================
+-module(usr_manager).
+
+%% API
+-export([start_link/1, add_handler/3, add_sup_handler/3, delete_handler/3,
+         notify/2, get_handlers/1]).
+
+%%--------------------------------------------------------------------
+%% Function: start_link() -> {ok,Pid} | {error,Error}
+%% Description: Creates an event manager.
+%% The user is global by default as we ought to support a multiple
+%% node system and will need more than a single process
+%%--------------------------------------------------------------------
+start_link(UserId) ->
+    gen_event:start_link({global, {manager, UserId}}).
+
+%%--------------------------------------------------------------------
+%% Function: add_handler(Module,Args) -> ok | {'EXIT',Reason} | term()
+%% Description: Adds an event handler
+%%--------------------------------------------------------------------
+add_handler(UserId, Handler = {_Module, _HandlerId}, Params) ->
+    gen_event:add_handler({global, {manager, UserId}}, Handler, Params);
+add_handler(UserId, Module, Params) when is_atom(Module) ->
+    gen_event:add_handler({global, {manager, UserId}}, Module, Params).
+
+%%--------------------------------------------------------------------
+%% Function: add_sup_handler(Module,Args) -> ok | {'EXIT',Reason} | term()
+%% Description: Adds an event handler that watches for the calling process'
+%% exit signals. This avoids having zombie listeners left over. The actual
+%% handling of errors is done in the callback module's terminate/2 function
+%%--------------------------------------------------------------------
+add_sup_handler(UserId, Handler = {_Module, _HandlerId}, Params) ->
+    gen_event:add_sup_handler({global, {manager, UserId}}, Handler, Params);
+add_sup_handler(UserId, Module, Params) when is_atom(Module) ->
+    gen_event:add_sup_handler({global, {manager, UserId}}, Module, Params).
+
+%%--------------------------------------------------------------------
+%% Function: delete_handler(UserId, Handler, Params) ->
+%% Description: Removes an event handler
+%%--------------------------------------------------------------------
+delete_handler(UserId, Handler, Params) ->
+    gen_event:delete_handler({global, {manager,UserId}}, Handler, Params).
+
+%%--------------------------------------------------------------------
+%% Function: get_handlers(UserId) -> [term()]
+%% Description: returns a list of all the handlers registered
+%%--------------------------------------------------------------------
+get_handlers(UserId) ->
+    gen_event:which_handlers({global, {manager, UserId}}).
+
+%%--------------------------------------------------------------------
+%% Function: notify(Event) -> ok | {error, Reason}
+%% Description: Sends the Event through the event manager.
+%%--------------------------------------------------------------------
+notify(UserId, Message) ->
+  gen_event:notify({global, {manager,UserId}}, Message).

File src/usr_sup.erl

                    worker,
                    [usr_monitor]},
     ManagerSpec = {ManagerId,
-                   {usr_dispatch_manager, start_link, [UserId]},
+                   {usr_manager, start_link, [UserId]},
                    transient,
                    TimeOut,
                    worker,