chut / src / chut_user_monitor.erl

Diff from to

src/chut_user_monitor.erl

 start_link(UserId, Dispatcher, TimeOut) ->
   gen_fsm:start_link({global, {monitor,UserId}},
                      ?MODULE,
-                     [{id, UserId},
-                      {dispatcher, Dispatcher},
-                      {timeout, TimeOut}],
+                     orddict:from_list([{id, UserId},
+                                        {dispatcher, Dispatcher},
+                                        {timeout, TimeOut}]),
                      []).
 
 %%====================================================================
 %% handlers.
 %%--------------------------------------------------------------------
 init(Opts) ->
-    {timeout, T} = proplists:lookup(timeout,Opts),
-    {ok, waiting, [{handlers, []} | Opts], T}.
+    T = orddict:fetch(timeout,Opts),
+    {ok, waiting, orddict:store(handlers, [], Opts), T}.
 
 
 %%--------------------------------------------------------------------
 waiting(timeout, State) ->
     %% maybe store messages?
     io:format("timing out~n"),
-    {id, UserId} = proplists:lookup(id, State),
+    UserId = orddict:fetch(id, State),
     chut_user:terminate(UserId), % take care, circular dependency!
     {stop, normal, State};
 waiting(_Event, State) -> % catch-all to avoid crashing
     io:format("invalid timeout msg:~p~n",[_Event]),
-    {timeout, TimeOut} = proplists:lookup(timeout, State),
+    TimeOut = orddict:fetch(timeout, State),
     {next_state, waiting, State, TimeOut}.
 
 %%--------------------------------------------------------------------
 %% waiting state, otherwise, keep listening.
 %%--------------------------------------------------------------------
 listening({delete_handler, HandlerId}, State) ->
-    {handlers, Handlers} = proplists:lookup(handlers, State),
-    {timeout, TimeOut} = proplists:lookup(timeout, State),
-    TempState = proplists:delete(handlers, State),
+    Handlers = orddict:fetch(handlers, State),
+    TimeOut = orddict:fetch(timeout, State),
+    TempState = orddict:erase(handlers, State),
     NewHandlers = lists:delete(HandlerId, Handlers),
-    NewState = [{handlers, NewHandlers} | TempState],
+    NewState = orddict:store(handlers, NewHandlers, TempState),
     case NewHandlers of
         [] ->    {next_state, waiting, NewState, TimeOut};
         [_|_] -> {next_state, listening, NewState}
 %% make the fsm start tracking it and switch the state to listening.
 %%--------------------------------------------------------------------
 handle_sync_event({add_handler, HandlerId}, _From, _StateName, State) ->
-    {handlers, Handlers} = proplists:lookup(handlers, State),
-    TempState = proplists:delete(handlers, State),
-    NewState = [{handlers, [HandlerId | Handlers]} | TempState],
+    Handlers = orddict:fetch(handlers, State),
+    TempState = orddict:erase(handlers, State),
+    NewState = orddict:store(handlers, [HandlerId | Handlers], TempState),
     {reply, ok, listening, NewState};
 handle_sync_event(_Event, _From, StateName, State) ->
     Reply = ok,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.