From: Christopher Piro Date: Tue, 15 Jan 2008 12:52:51 +0000 (+0000) Subject: [thrift] flesh out thrift Erlang tutorial client X-Git-Tag: 0.2.0~1044 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=3f1d8c7cf645256455c2231a8273411a4f83d594;p=common%2Fthrift.git [thrift] flesh out thrift Erlang tutorial client Summary: Added examples for all examples except inheritance and application exception handling (divide by zero); looks like both are currently broken. Weak. Reviewed By: eletuchy Test Plan: works just like RubyClient.rb (modulo the commented out bits) Revert Plan: ok git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665428 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/tutorial/erl/client.erl b/tutorial/erl/client.erl index f4ff7b3e..9e187467 100644 --- a/tutorial/erl/client.erl +++ b/tutorial/erl/client.erl @@ -6,63 +6,68 @@ -include("calculator_thrift.hrl"). --export([t/0]). +-export([go/0]). + +p(X) -> + io:format("~p~n", [X]), + ok. t() -> + thrift:start(), Host = "dev020", Port = 9999, - _Sock = oop:start_new(tSocket, [Host, Port]), - Trans = oop:start_new(tBufferedTransport, [_Sock]), - Prot = oop:start_new(tBinaryProtocol, [Trans]), - - ?R0(Trans, effectful_open), - - Client = calculator_thrift:new(Prot), - - calculator_thrift:ping(Client), - p("ping"), - - %% - %% sum = client.add(1,1) - %% print "1+1=", sum, "\n" - %% - %% sum = client.add(1,4) - %% print "1+4=", sum, "\n" - %% - %% work = Work.new() - %% - %% work.op = Operation::SUBTRACT - %% work.num1 = 15 - %% work.num2 = 10 - %% diff = client.calculate(1, work) - %% print "15-10=", diff, "\n" - %% - %% log = client.getStruct(1) - %% print "Log: ", log.value, "\n" - %% - %% begin - %% work.op = Operation::DIVIDE - %% work.num1 = 1 - %% work.num2 = 0 - %% quot = client.calculate(1, work) - %% puts "Whoa, we can divide by 0 now?" - %% rescue InvalidOperation => io - %% print "InvalidOperation: ", io.why, "\n" - %% end - %% - %% client.zip() - %% print "zip\n" - %% - %% transport.close() - %% - %% rescue TException => tx - %% print 'TException: ', tx.message, "\n" - %% end - %% - %% - %% - %% XXX if we don't close, the connection doesn't time out on the other side - ?R0(Trans, effectful_close), + try + _Sock = oop:start_new(tSocket, [Host, Port]), + Trans = oop:start_new(tBufferedTransport, [_Sock]), + Prot = oop:start_new(tBinaryProtocol, [Trans]), + + ?R0(Trans, effectful_open), + + Client = calculator_thrift:new(Prot), + + calculator_thrift:ping(Client), + io:format("ping~n", []), + + Sum = calculator_thrift:add(Client, 1, 1), + io:format("1+1=~p~n", [Sum]), + + Sum1 = calculator_thrift:add(Client, 1, 4), + io:format("1+4=~p~n", [Sum1]), + + Work = #work{op=?tutorial_SUBTRACT, + num1=15, + num2=10}, + Diff = calculator_thrift:calculate(Client, 1, Work), + io:format("15-10=~p~n", [Diff]), + + %% xxx inheritance doesn't work + %% Log = sharedService_thrift:getStruct(Client, 1), + %% io:format("Log: ~p~n", [Log]), + + %% xxx neither do exceptions :( + try + Work1 = #work{op=?tutorial_DIVIDE, + num1=1, + num2=0}, + _Quot = (calculator_thrift:calculate(Client, 1, Work1)), + + io:format("LAME: exception handling is broken~n", []) + catch + Z -> + p(Z) + %% rescue InvalidOperation => io + %% print "InvalidOperation: ", io.why, "\n" + %% end + end, + + calculator_thrift:zip(Client), + io:format("zip~n", []), + + ?R0(Trans, effectful_close) + catch + Y -> + p(Y) + end, ok. diff --git a/tutorial/erl/client.sh b/tutorial/erl/client.sh new file mode 120000 index 00000000..a417e0da --- /dev/null +++ b/tutorial/erl/client.sh @@ -0,0 +1 @@ +server.sh \ No newline at end of file