%%%-------------------------------------------------------------------
%%% File : thrift_processor.erl
%%% Author : <todd@lipcon.org>
-%%% Description :
+%%% Description :
%%%
%%% Created : 28 Jan 2008 by <todd@lipcon.org>
%%%-------------------------------------------------------------------
ok
end.
-
handle_function(State = #state{in_protocol = IProto,
out_protocol = OProto,
handler = Handler,
{ok, Params} = thrift_protocol:read(IProto, InParams),
try
- {Micro, Result} = better_timer(Handler, handle_function, [Function, Params]),
+ Result = Handler:handle_function(Function, Params),
+ % {Micro, Result} = better_timer(Handler, handle_function, [Function, Params]),
% error_logger:info_msg("Processed ~p(~p) in ~.4fms~n",
% [Function, Params, Micro/1000.0]),
handle_success(State, Function, Result)
service = Service},
Function,
Result) ->
- ReplyType = Service:function_info(Function, reply_type),
+ ReplyType = Service:function_info(Function, reply_type),
StructName = atom_to_list(Function) ++ "_result",
-
+
case Result of
- {reply, ReplyData} ->
+ {reply, ReplyData} ->
Reply = {{struct, [{0, ReplyType}]}, {StructName, ReplyData}},
ok = send_reply(OProto, Function, ?tMessageType_REPLY, Reply);
ok when ReplyType == {struct, []} ->
ok = send_reply(OProto, Function, ?tMessageType_REPLY, {ReplyType, {StructName}});
-
+
ok when ReplyType == async_void ->
% no reply for async void
ok
{struct, XInfo} = ReplySpec,
true = is_list(XInfo),
-
+
+ % Assuming we had a type1 exception, we'd get: [undefined, Exception, undefined]
% e.g.: [{-1, type0}, {-2, type1}, {-3, type2}]
- XPairs = [{Fid, Type} || {Fid, {struct, {_Module, Type}}} <- XInfo],
-
- Mapper = fun({Fid, Type}) ->
- case Type of
- ExceptionType ->
- Exception;
- _ ->
- undefined
+ ExceptionList = [case Type of
+ ExceptionType -> Exception;
+ _ -> undefined
end
- end,
- % Assuming we had a type1 exception, we get: [undefined, Exception, undefined]
- ExceptionList = lists:map(Mapper, XPairs),
+ || {_Fid, {struct, {_Module, Type}}} <- XInfo],
+
ExceptionTuple = list_to_tuple([Function | ExceptionList]),
-
+
% Make sure we got at least one defined
case lists:all(fun(X) -> X =:= undefined end, ExceptionList) of
true ->
handle_error(#state{out_protocol = OProto}, Function, Error) ->
Stack = erlang:get_stacktrace(),
error_logger:error_msg("~p had an error: ~p~n", [Function, {Error, Stack}]),
-
+
Message =
case application:get_env(thrift, exceptions_include_traces) of
{ok, true} ->
%%%-------------------------------------------------------------------
%%% File : thrift_server.erl
%%% Author : <todd@lipcon.org>
-%%% Description :
+%%% Description :
%%%
%%% Created : 28 Jan 2008 by <todd@lipcon.org>
%%%-------------------------------------------------------------------
start_link(Port, Service, HandlerModule) when is_integer(Port), is_atom(HandlerModule) ->
gen_server:start_link({local, ?SERVER}, ?MODULE, {Port, Service, HandlerModule}, []).
-
%%--------------------------------------------------------------------
%% Function: stop(Pid) -> ok, {error, Reason}
%% Description: Stops the server.
Error
end.
-
-
start_processor(Socket, Service, Handler) ->
Server = self(),
{ok, Protocol} = thrift_binary_protocol:new(BufferedTransport),
{ok, Protocol, Protocol}
end,
-
+
thrift_processor:start(ProtoGen, Service, Handler).