Permalink
Browse files

remove debug

  • Loading branch information...
1 parent bd1e55e commit 3399031b6f2ff2df1f9f67afab62e3493037cee1 @mihawk mihawk committed Jul 20, 2012
Showing with 26 additions and 36 deletions.
  1. +4 −0 .gitignore
  2. +4 −3 src/boss/boss_mochicow_handler.erl
  3. +18 −33 src/boss/boss_service.erl
View
@@ -2,3 +2,7 @@ ebin/*.beam
ebin/boss.app
deps
erl_crash.dump
+*~
+#*#
+.*#
+*#
@@ -28,11 +28,12 @@ websocket_init(_Any, Req, _Opts) ->
State= #state{websocket_id=WebsocketId,
session_id=SessionId,
service_name=ServiceName},
+ %error_logger:info_msg("State:~p~n",[State]),
boss_service:join(ServiceName, WebsocketId, SessionId),
{ok, Req, State, hibernate}.
websocket_handle({text, Msg}, Req, State) ->
- %error_logger:info_msg("State:~p~nincoming:~p~n",[State, Msg]),
+ %%error_logger:info_msg("State:~p~nincoming:~p~n",[State, Msg]),
#state{websocket_id=WebsocketId,
session_id=SessionId,
service_name=ServiceName } = State,
@@ -43,7 +44,7 @@ websocket_handle(_Any, Req, State) ->
{ok, Req, State}.
websocket_info({text, Msg}, Req, State) ->
- error_logger:info_msg("State~p~nsend:~p~n", [State,Msg]),
+ %%error_logger:info_msg("State~p~nsend:~p~n", [State,Msg]),
{reply, {text, Msg}, Req, State};
websocket_info(_Info, Req, State) ->
@@ -53,6 +54,6 @@ websocket_terminate(_Reason, _Req, State) ->
#state{websocket_id=WebsocketId,
session_id=SessionId,
service_name=ServiceName } = State,
- %error_logger:info_msg("websocket terminate~nState=~p~n", [State]),
+ %%error_logger:info_msg("websocket terminate~nState=~p~n", [State]),
boss_service:terminate(ServiceName, WebsocketId, SessionId),
ok.
@@ -31,7 +31,7 @@
-define(SERVER, ?MODULE).
--record(boss_consummers,
+-record(boss_consumers,
{
websocket_id, % gateway to send message to consummer
session_id, % the session id to link and user
@@ -79,6 +79,7 @@ service(ServiceName) ->
gen_server:call(?SERVER, {get_service, ServiceName}).
services() ->
gen_server:call(?SERVER, {get_all_service}).
+
%async
@@ -118,8 +119,8 @@ init([]) ->
mnesia:table_info(boss_consummers, type)
catch
exit: _ ->
- mnesia:create_table(boss_consummers, [{attributes,
- record_info(fields, boss_consummers)},
+ mnesia:create_table(boss_consumers, [{attributes,
+ record_info(fields, boss_consumers)},
{type, bag},
{ram_copies, [node()]}])
end,
@@ -201,40 +202,31 @@ handle_call(_Request, _From, State) ->
%% {noreply, #state{nb_ws=Nb}};
handle_cast({join_service, ServiceName, WebSocketId, SessionId}, State) ->
case get_service(ServiceName) of
- [{boss_services, _, ServiceId, _}] ->
- %% error_logger:info_msg("{~p,~p} join Service (~p)~nMailbox:~p~n",
- %% [WebSocketId, SessionId, ServiceName, ServiceId]),
- ServiceId ! {join_service, ServiceName, WebSocketId, SessionId};
+ [{_, _, ServiceId, _}] ->
+ ServiceId:join(ServiceName, WebSocketId, SessionId);
Unknow ->
- %% error_logger:info_msg("unknow Service (~p)~n", [ServiceName]),
Unknow
end,
register_consummer(ServiceName, WebSocketId, SessionId),
{noreply, State};
handle_cast({incoming_msg, ServiceName, WebSocketId, SessionId, Msg}, State) ->
case get_service(ServiceName) of
- [{boss_services, _, ServiceId, _}] ->
- %% error_logger:info_msg("From {~p,~p} incoming_msg to (~p)~nMailbox:~p~n",
- %% [WebSocketId, SessionId, ServiceName, ServiceId]),
- ServiceId ! {incoming_msg, ServiceName, WebSocketId, SessionId, Msg};
+ [{_, _, ServiceId, _}] ->
+ ServiceId:incoming(ServiceName, WebSocketId, SessionId, Msg);
Unknow ->
- %% error_logger:info_msg("unknow Service (~p)~n", [ServiceName]),
Unknow
end,
{noreply, State};
-handle_cast({terminate, ServiceName, WebSocketId, SessionId}, State) ->
+handle_cast({terminate_service, ServiceName, WebSocketId, SessionId}, State) ->
case get_service(ServiceName) of
- [{boss_services, _, ServiceId, _}] ->
- %% error_logger:info_msg("From {~p,~p} incoming_msg to (~p)~nMailBox:~p",
- %% [WebSocketId, SessionId, ServiceName, ServiceId]),
- ServiceId ! {terminate_service, WebSocketId, SessionId};
+ [{_, _, ServiceId, _}] ->
+ ServiceId:close(WebSocketId, SessionId);
Unknow ->
- %% error_logger:info_msg("unknow Service (~p)~n", [ServiceName]),
Unknow
end,
-
+
unregister_consummer([{boss_consummers,
WebSocketId,
SessionId,
@@ -301,17 +293,16 @@ unregister_service(Services) ->
lists:foreach(fun(Msg) -> mnesia:delete_object(Msg) end, Services) end,
mnesia:transaction(F).
-
get_service(ServiceName) ->
F = fun() ->
Query = qlc:q([M || M <- mnesia:table(boss_services),
M#boss_services.service_name =:= ServiceName
]),
- Order = fun(A,B) ->
- A#boss_services.created_on > B#boss_services.created_on
- end,
- Results = qlc:e(qlc:sort(Query, {order, Order})),
- %Results = qlc:e(Query),
+ %% Order = fun(A,B) ->
+ %% A#boss_services.created_on > B#boss_services.created_on
+ %% end,
+ %% Results = qlc:e(qlc:sort(Query, {order, Order})),
+ Results = qlc:e(Query),
Results
end,
{atomic, Service} = mnesia:transaction(F),
@@ -331,7 +322,7 @@ get_all_service() ->
register_consummer(ServiceName, WebsocketId, SessionId) ->
F = fun() ->
{_, CreatedOn, _} = erlang:now(),
- mnesia:write(#boss_consummers{
+ mnesia:write(#boss_consumers{
service_name=ServiceName,
websocket_id=WebsocketId,
session_id=SessionId,
@@ -342,9 +333,3 @@ unregister_consummer(Consummers) ->
F = fun() ->
lists:foreach(fun(Msg) -> mnesia:delete_object(Msg) end, Consummers) end,
mnesia:transaction(F).
-
-
-
-
-
-

0 comments on commit 3399031

Please sign in to comment.