[thrift] highly concurrent Erlang goodness

Summary:
 * shim to use object-oriented code as gen_servers
 * high(er) performance Erlang-style server and transport
 * sane packaging based on otp-base, i.e. Makefiles and real structure

Test Plan: tutorial server offers the same (subset of) functionality as previous version

Revert Plan: ok


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665164 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/tutorial/erl/calculatorHandler.erl b/tutorial/erl/calculatorHandler.erl
deleted file mode 100644
index 5d42019..0000000
--- a/tutorial/erl/calculatorHandler.erl
+++ /dev/null
@@ -1,68 +0,0 @@
--module(calculatorHandler).
-
--include("thrift/thrift.hrl").
--include("thrift/transport/tSocket.hrl").
--include("thrift/protocol/tBinaryProtocol.hrl").
--include("thrift/server/tServer.hrl").
--include("thrift/transport/tServerSocket.hrl").
-
--include("gen-erl/calculator.hrl").
-%-include("gen-erl/shared_types.hrl").
-
-%-include("gen-erl/tutorial_types.hrl"). % TODO(cpiro): o rly?
-
--export([start/0, ping/0, add/2, calculate/2, getStruct/1, zip/0]).
-
-%%%   def initialize()
-%%%     @log = {}
-%%%   end
-
-% TODO: voids take only ok as return? 
-
-ping() ->
-    io:format("ping()~n",[]),
-    {ok, nil}.
-
-add(N1, N2) ->
-    io:format("add(~p,~p)~n",[N1,N2]),
-    {ok, N1+N2}.
-
-calculate(Logid, Work) ->
-    { Op, Num1, Num2 } = { Work#work.op, Work#work.num1, Work#work.num2 },
-    io:format("calculate(~p, {~p,~p,~p})~n", [Logid, Op, Num1, Num2]),
-    case Op of
-        ?ADD      -> {ok, Num1 + Num2};
-	?SUBTRACT -> {ok, Num1 - Num2};
-	?MULTIPLY -> {ok, Num1 * Num2};
-	?DIVIDE ->
-	    if 	Num2 == 0 -> {error, #invalidOperation{what=Op, why="Cannot divide by 0"}};
-		true      -> {ok, Num1 / Num2}
-	    end;
-	true ->
-	    {error, #invalidOperation{what=Op, why="Invalid operation"}}
-    end.
-
-getStruct(Key) ->
-    io:format("getStruct(~p)~n", [Key]),
-    {ok, get(Key)}.
-
-zip() ->
-    io:format("zip~n").
-
-start() ->
-    Transport = tServerSocket:new(9090),
-    Server = tServer:new(calculator, ?MODULE, Transport),
-    io:format("Starting the server...~n", []),
-    ?M0(Server, serve),
-    io:format("done.~n", []), % won't ever reach, rookie beotch
-    ok.
-
-%%% handler = CalculatorHandler.new()
-%%% processor = Calculator::Processor.new(handler)
-%%% transport = TServerSocket.new(9090)
-%%% transportFactory = TBufferedTransportFactory.new()
-%%% server = TSimpleServer.new(processor, transport, transportFactory)
-%%% 
-%%% puts "Starting the server..."
-%%% server.serve()
-%%% puts "done."
diff --git a/tutorial/erl/server.erl b/tutorial/erl/server.erl
new file mode 100644
index 0000000..c924589
--- /dev/null
+++ b/tutorial/erl/server.erl
@@ -0,0 +1,66 @@
+-module(server).
+
+-include("thrift.hrl").
+-include("transport/tSocket.hrl").
+-include("protocol/tBinaryProtocol.hrl").
+
+-include("server/tErlServer.hrl").
+-include("transport/tErlAcceptor.hrl").
+
+-include("calculator.hrl").
+
+-export([start/0, stop/1, ping/0, add/2, calculate/2, getStruct/1, zip/0]).
+
+ping() ->
+    io:format("ping()~n",[]),
+    {ok, nil}.
+
+add(N1, N2) ->
+    io:format("add(~p,~p)~n",[N1,N2]),
+    {ok, N1+N2}.
+
+calculate(Logid, Work) ->
+    { Op, Num1, Num2 } = { Work#work.op, Work#work.num1, Work#work.num2 },
+    io:format("calculate(~p, {~p,~p,~p})~n", [Logid, Op, Num1, Num2]),
+    case Op of
+        ?ADD      -> {ok, Num1 + Num2};
+	?SUBTRACT -> {ok, Num1 - Num2};
+	?MULTIPLY -> {ok, Num1 * Num2};
+	?DIVIDE ->
+	    if 	Num2 == 0 -> {error, #invalidOperation{what=Op, why="Cannot divide by 0"}};
+		true      -> {ok, Num1 / Num2}
+	    end;
+	true ->
+	    {error, #invalidOperation{what=Op, why="Invalid operation"}}
+    end.
+
+getStruct(Key) ->
+    io:format("getStruct(~p)~n", [Key]),
+    {ok, get(Key)}.
+
+zip() ->
+    io:format("zip~n").
+
+%%
+
+start() ->
+    Handler   = ?MODULE, % cpiro: or generated handler?
+    Processor = calculator,
+    Port      = 9090,
+
+    TF = tBufferedTransportFactory:new(),
+    PF = tBinaryProtocolFactory:new(),
+
+    ServerTransport = tErlAcceptor,
+    ServerFlavor    = tErlServer,
+
+    Server = oop:start_new(ServerFlavor, [Port, Handler, Processor, ServerTransport, TF, PF]),
+
+    ?R0(Server, effectful_serve),
+
+    Server.
+
+stop(Server) ->
+    ?C0(Server, stop),
+    ok.
+