summaryrefslogtreecommitdiffstats
path: root/src/jaegertracing/thrift/tutorial/erl
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/jaegertracing/thrift/tutorial/erl/README.md8
-rw-r--r--src/jaegertracing/thrift/tutorial/erl/client.erl78
-rwxr-xr-xsrc/jaegertracing/thrift/tutorial/erl/client.sh37
-rw-r--r--src/jaegertracing/thrift/tutorial/erl/json_client.erl89
-rw-r--r--src/jaegertracing/thrift/tutorial/erl/server.erl82
-rwxr-xr-xsrc/jaegertracing/thrift/tutorial/erl/server.sh37
6 files changed, 331 insertions, 0 deletions
diff --git a/src/jaegertracing/thrift/tutorial/erl/README.md b/src/jaegertracing/thrift/tutorial/erl/README.md
new file mode 100644
index 000000000..9d17cd0c5
--- /dev/null
+++ b/src/jaegertracing/thrift/tutorial/erl/README.md
@@ -0,0 +1,8 @@
+To try things out, run
+
+% ./server.sh
+Erlang R14B (erts-5.8.1) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] [hipe] [kernel-poll:false]
+
+Eshell V5.8.1 (abort with ^G)
+> server:start().
+> client:t().
diff --git a/src/jaegertracing/thrift/tutorial/erl/client.erl b/src/jaegertracing/thrift/tutorial/erl/client.erl
new file mode 100644
index 000000000..037422085
--- /dev/null
+++ b/src/jaegertracing/thrift/tutorial/erl/client.erl
@@ -0,0 +1,78 @@
+%%
+%% Licensed to the Apache Software Foundation (ASF) under one
+%% or more contributor license agreements. See the NOTICE file
+%% distributed with this work for additional information
+%% regarding copyright ownership. The ASF licenses this file
+%% to you under the Apache License, Version 2.0 (the
+%% "License"); you may not use this file except in compliance
+%% with the License. You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing,
+%% software distributed under the License is distributed on an
+%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+%% KIND, either express or implied. See the License for the
+%% specific language governing permissions and limitations
+%% under the License.
+%%
+
+-module(client).
+
+-include("calculator_thrift.hrl").
+
+-export([t/0]).
+
+p(X) ->
+ io:format("~p~n", [X]),
+ ok.
+
+t() ->
+ Port = 9090,
+
+ {ok, Client0} = thrift_client_util:new("127.0.0.1",
+ Port,
+ calculator_thrift,
+ []),
+
+ {Client1, {ok, ok}} = thrift_client:call(Client0, ping, []),
+ io:format("ping~n", []),
+
+ {Client2, {ok, Sum}} = thrift_client:call(Client1, add, [1, 1]),
+ io:format("1+1=~p~n", [Sum]),
+
+ {Client3, {ok, Sum1}} = thrift_client:call(Client2, add, [1, 4]),
+ io:format("1+4=~p~n", [Sum1]),
+
+ Work = #'Work'{op=?TUTORIAL_OPERATION_SUBTRACT,
+ num1=15,
+ num2=10},
+ {Client4, {ok, Diff}} = thrift_client:call(Client3, calculate, [1, Work]),
+ io:format("15-10=~p~n", [Diff]),
+
+ {Client5, {ok, Log}} = thrift_client:call(Client4, getStruct, [1]),
+ io:format("Log: ~p~n", [Log]),
+
+ Client6 =
+ try
+ Work1 = #'Work'{op=?TUTORIAL_OPERATION_DIVIDE,
+ num1=1,
+ num2=0},
+ {ClientS1, {ok, _Quot}} = thrift_client:call(Client5, calculate, [2, Work1]),
+
+ io:format("LAME: exception handling is broken~n", []),
+ ClientS1
+ catch
+ throw:{ClientS2, Z} ->
+ io:format("Got exception where expecting - the " ++
+ "following is NOT a problem!!!~n"),
+ p(Z),
+ ClientS2
+ end,
+
+
+ {Client7, {ok, ok}} = thrift_client:call(Client6, zip, []),
+ io:format("zip~n", []),
+
+ {_Client8, ok} = thrift_client:close(Client7),
+ ok.
diff --git a/src/jaegertracing/thrift/tutorial/erl/client.sh b/src/jaegertracing/thrift/tutorial/erl/client.sh
new file mode 100755
index 000000000..775afb62d
--- /dev/null
+++ b/src/jaegertracing/thrift/tutorial/erl/client.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+ERL_THRIFT=../../lib/erl
+
+if ! [ -d ${ERL_THRIFT}/ebin ]; then
+ echo "Please build the Thrift library by running \`make' in ${ERL_THRIFT}"
+ exit 1
+fi
+
+if ! [ -d gen-erl ]; then
+ ../../compiler/cpp/thrift -r --gen erl ../tutorial.thrift
+fi
+
+
+erlc -I ${ERL_THRIFT}/include -I ${ERL_THRIFT}/ebin \
+ -I gen-erl -o gen-erl gen-erl/*.erl &&
+ erlc -I ${ERL_THRIFT}/include -I gen-erl *.erl &&
+ erl +K true -pa ${ERL_THRIFT}/ebin -pa gen-erl
diff --git a/src/jaegertracing/thrift/tutorial/erl/json_client.erl b/src/jaegertracing/thrift/tutorial/erl/json_client.erl
new file mode 100644
index 000000000..0b39ceda9
--- /dev/null
+++ b/src/jaegertracing/thrift/tutorial/erl/json_client.erl
@@ -0,0 +1,89 @@
+%%
+%% Licensed to the Apache Software Foundation (ASF) under one
+%% or more contributor license agreements. See the NOTICE file
+%% distributed with this work for additional information
+%% regarding copyright ownership. The ASF licenses this file
+%% to you under the Apache License, Version 2.0 (the
+%% "License"); you may not use this file except in compliance
+%% with the License. You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing,
+%% software distributed under the License is distributed on an
+%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+%% KIND, either express or implied. See the License for the
+%% specific language governing permissions and limitations
+%% under the License.
+%%
+%% The JSON protocol over HTTP implementation was created by
+%% Peter Neumark <neumark.peter@gmail.com> based on
+%% the binary protocol + socket tutorial. Use with the same server
+%% that the Javascript tutorial uses!
+
+-module(json_client).
+
+-include("calculator_thrift.hrl").
+
+-export([t/0]).
+
+%% Client constructor for the http transports
+%% with the json protocol
+new_client(Host, Path, Service, _Options) ->
+ {ProtoOpts, TransOpts} = {[],[]},
+ TransportFactory = fun() -> thrift_http_transport:new(Host, Path, TransOpts) end,
+ {ok, ProtocolFactory} = thrift_json_protocol:new_protocol_factory(
+ TransportFactory, ProtoOpts),
+ {ok, Protocol} = ProtocolFactory(),
+ thrift_client:new(Protocol, Service).
+
+p(X) ->
+ io:format("~p~n", [X]),
+ ok.
+
+t() ->
+ inets:start(),
+ {ok, Client0} = new_client("127.0.0.1:8088", "/thrift/service/tutorial/",
+ calculator_thrift,
+ []),
+ {Client1, {ok, ok}} = thrift_client:call(Client0, ping, []),
+ io:format("ping~n", []),
+
+ {Client2, {ok, Sum}} = thrift_client:call(Client1, add, [1, 1]),
+ io:format("1+1=~p~n", [Sum]),
+
+ {Client3, {ok, Sum1}} = thrift_client:call(Client2, add, [1, 4]),
+ io:format("1+4=~p~n", [Sum1]),
+
+ Work = #'Work'{op=?TUTORIAL_OPERATION_SUBTRACT,
+ num1=15,
+ num2=10},
+ {Client4, {ok, Diff}} = thrift_client:call(Client3, calculate, [1, Work]),
+ io:format("15-10=~p~n", [Diff]),
+
+ {Client5, {ok, Log}} = thrift_client:call(Client4, getStruct, [1]),
+ io:format("Log: ~p~n", [Log]),
+
+ Client6 =
+ try
+ Work1 = #'Work'{op=?TUTORIAL_OPERATION_DIVIDE,
+ num1=1,
+ num2=0},
+ {ClientS1, {ok, _Quot}} = thrift_client:call(Client5, calculate, [2, Work1]),
+
+ io:format("LAME: exception handling is broken~n", []),
+ ClientS1
+ catch
+ throw:{ClientS2, Z} ->
+ io:format("Got exception where expecting - the " ++
+ "following is NOT a problem!!!~n"),
+ p(Z),
+ ClientS2
+ end,
+
+
+ {Client7, {ok, ok}} = thrift_client:call(Client6, zip, []),
+ io:format("zip~n", []),
+
+ {_Client8, ok} = thrift_client:close(Client7),
+ ok.
diff --git a/src/jaegertracing/thrift/tutorial/erl/server.erl b/src/jaegertracing/thrift/tutorial/erl/server.erl
new file mode 100644
index 000000000..647cc2474
--- /dev/null
+++ b/src/jaegertracing/thrift/tutorial/erl/server.erl
@@ -0,0 +1,82 @@
+%%
+%% Licensed to the Apache Software Foundation (ASF) under one
+%% or more contributor license agreements. See the NOTICE file
+%% distributed with this work for additional information
+%% regarding copyright ownership. The ASF licenses this file
+%% to you under the Apache License, Version 2.0 (the
+%% "License"); you may not use this file except in compliance
+%% with the License. You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing,
+%% software distributed under the License is distributed on an
+%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+%% KIND, either express or implied. See the License for the
+%% specific language governing permissions and limitations
+%% under the License.
+%%
+
+-module(server).
+
+-include("calculator_thrift.hrl").
+
+-export([start/0, start/1, handle_function/2,
+ stop/1, ping/0, add/2, calculate/2, getStruct/1, zip/0]).
+
+debug(Format, Data) ->
+ error_logger:info_msg(Format, Data).
+
+ping() ->
+ debug("ping()",[]),
+ ok.
+
+add(N1, N2) ->
+ debug("add(~p,~p)",[N1,N2]),
+ N1+N2.
+
+calculate(Logid, Work) ->
+ { Op, Num1, Num2 } = { Work#'Work'.op, Work#'Work'.num1, Work#'Work'.num2 },
+ debug("calculate(~p, {~p,~p,~p})", [Logid, Op, Num1, Num2]),
+ case Op of
+ ?TUTORIAL_OPERATION_ADD -> Num1 + Num2;
+ ?TUTORIAL_OPERATION_SUBTRACT -> Num1 - Num2;
+ ?TUTORIAL_OPERATION_MULTIPLY -> Num1 * Num2;
+
+ ?TUTORIAL_OPERATION_DIVIDE when Num2 == 0 ->
+ throw(#'InvalidOperation'{whatOp=Op, why="Cannot divide by 0"});
+ ?TUTORIAL_OPERATION_DIVIDE ->
+ Num1 div Num2;
+
+ _Else ->
+ throw(#'InvalidOperation'{whatOp=Op, why="Invalid operation"})
+ end.
+
+getStruct(Key) ->
+ debug("getStruct(~p)", [Key]),
+ #'SharedStruct'{key=Key, value="RARG"}.
+
+zip() ->
+ debug("zip", []),
+ ok.
+
+%%
+
+start() ->
+ start(9090).
+
+start(Port) ->
+ Handler = ?MODULE,
+ thrift_socket_server:start([{handler, Handler},
+ {service, calculator_thrift},
+ {port, Port},
+ {name, tutorial_server}]).
+
+stop(Server) ->
+ thrift_socket_server:stop(Server).
+
+handle_function(Function, Args) when is_atom(Function), is_tuple(Args) ->
+ case apply(?MODULE, Function, tuple_to_list(Args)) of
+ ok -> ok;
+ Reply -> {reply, Reply}
+ end.
diff --git a/src/jaegertracing/thrift/tutorial/erl/server.sh b/src/jaegertracing/thrift/tutorial/erl/server.sh
new file mode 100755
index 000000000..775afb62d
--- /dev/null
+++ b/src/jaegertracing/thrift/tutorial/erl/server.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+ERL_THRIFT=../../lib/erl
+
+if ! [ -d ${ERL_THRIFT}/ebin ]; then
+ echo "Please build the Thrift library by running \`make' in ${ERL_THRIFT}"
+ exit 1
+fi
+
+if ! [ -d gen-erl ]; then
+ ../../compiler/cpp/thrift -r --gen erl ../tutorial.thrift
+fi
+
+
+erlc -I ${ERL_THRIFT}/include -I ${ERL_THRIFT}/ebin \
+ -I gen-erl -o gen-erl gen-erl/*.erl &&
+ erlc -I ${ERL_THRIFT}/include -I gen-erl *.erl &&
+ erl +K true -pa ${ERL_THRIFT}/ebin -pa gen-erl