diff options
Diffstat (limited to '')
22 files changed, 1798 insertions, 0 deletions
diff --git a/src/jaegertracing/thrift/tutorial/d/Makefile.am b/src/jaegertracing/thrift/tutorial/d/Makefile.am new file mode 100644 index 000000000..358294ce5 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/d/Makefile.am @@ -0,0 +1,53 @@ +# +# 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. +# + +LIB_D_DIR = $(top_srcdir)/lib/d + +GEN_SRC = gen-d/share/SharedService.d gen-d/share/shared_types.d \ + gen-d/tutorial/tutorial_types.d gen-d/tutorial/Calculator.d + +$(GEN_SRC): $(top_srcdir)/tutorial/tutorial.thrift + $(top_builddir)/compiler/cpp/thrift --gen d -r $< + +server: server.d $(GEN_SRC) + $(DMD) -I${LIB_D_DIR}/src -L-L${LIB_D_DIR} -L-lthriftd server.d ${GEN_SRC} + +client: client.d $(GEN_SRC) + $(DMD) -I${LIB_D_DIR}/src -L-L${LIB_D_DIR} -L-lthriftd client.d ${GEN_SRC} + +PROGS = server client + +if WITH_D_EVENT_TESTS +async_client: async_client.d $(GEN_SRC) + $(DMD) -I${LIB_D_DIR}/src -L-L${LIB_D_DIR} -L-lthriftd-event -L-lthriftd -L-levent async_client.d ${GEN_SRC} + +PROGS += async_client +endif + +all-local: $(PROGS) + +clean: + $(RM) -f $(PROGS) + $(RM) -r gen-d/ + find . -type f -name '*.o' | xargs rm -f + +dist-hook: + $(RM) -f $(distdir)/$(PROGS) + $(RM) -r $(distdir)/gen-d/ + find $(destdir) -type f -name '*.o' | xargs rm -f diff --git a/src/jaegertracing/thrift/tutorial/d/async_client.d b/src/jaegertracing/thrift/tutorial/d/async_client.d new file mode 100644 index 000000000..1defce082 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/d/async_client.d @@ -0,0 +1,86 @@ +/* + * 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 async_client; + +import std.exception; +import std.stdio; +import thrift.async.libevent; +import thrift.async.socket; +import thrift.base; +import thrift.codegen.async_client; +import thrift.protocol.binary; +import thrift.transport.buffered; + +import tutorial.Calculator; +import tutorial.tutorial_types; + +void main() { + auto asyncManager = new TLibeventAsyncManager; + + // If we are done, gracefully stop the async manager to avoid hanging on + // appplication shutdown. + scope (exit) asyncManager.stop(); + + auto socket = new TAsyncSocket(asyncManager, "localhost", 9090); + auto client = new TAsyncClient!Calculator( + socket, + new TBufferedTransportFactory, + new TBinaryProtocolFactory!TBufferedTransport + ); + + socket.open(); + + // Invoke all the methods. + auto pingResult = client.ping(); + + auto addResult = client.add(1, 1); + + auto work = Work(); + work.op = Operation.DIVIDE; + work.num1 = 1; + work.num2 = 0; + auto quotientResult = client.calculate(1, work); + + work.op = Operation.SUBTRACT; + work.num1 = 15; + work.num2 = 10; + auto diffResult = client.calculate(1, work); + + auto logResult = client.getStruct(1); + + // Await the responses. + pingResult.waitGet(); + writeln("ping()"); + + int sum = addResult.waitGet(); + writefln("1 + 1 = %s", sum); + + try { + quotientResult.waitGet(); + writeln("Whoa we can divide by 0"); + } catch (InvalidOperation io) { + writeln("Invalid operation: " ~ io.why); + } + + writefln("15 - 10 = %s", diffResult.waitGet()); + + // TFuture is implicitly convertible to the result type via »alias this«, + // for which it (eagerly, of course) awaits completion. + writefln("Check log: %s", logResult.value); +} diff --git a/src/jaegertracing/thrift/tutorial/d/client.d b/src/jaegertracing/thrift/tutorial/d/client.d new file mode 100644 index 000000000..1867a17bc --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/d/client.d @@ -0,0 +1,64 @@ +/* + * 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; + +import std.stdio; +import thrift.base; +import thrift.codegen.client; +import thrift.protocol.binary; +import thrift.transport.buffered; +import thrift.transport.socket; + +import tutorial.Calculator; +import tutorial.tutorial_types; + +void main() { + auto socket = new TSocket("localhost", 9090); + auto transport = new TBufferedTransport(socket); + auto protocol = tBinaryProtocol(transport); + auto client = tClient!Calculator(protocol); + + transport.open(); + + client.ping(); + writeln("ping()"); + + int sum = client.add(1, 1); + writefln("1 + 1 = %s", sum); + + auto work = Work(); + work.op = Operation.DIVIDE; + work.num1 = 1; + work.num2 = 0; + try { + int quotient = client.calculate(1, work); + writeln("Whoa we can divide by 0"); + } catch (InvalidOperation io) { + writeln("Invalid operation: " ~ io.why); + } + + work.op = Operation.SUBTRACT; + work.num1 = 15; + work.num2 = 10; + int diff = client.calculate(1, work); + writefln("15 - 10 = %s", diff); + + auto log = client.getStruct(1); + writefln("Check log: %s", log.value); +} diff --git a/src/jaegertracing/thrift/tutorial/d/server.d b/src/jaegertracing/thrift/tutorial/d/server.d new file mode 100644 index 000000000..cbcedccf3 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/d/server.d @@ -0,0 +1,111 @@ +/* + * 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; + +import std.conv : to; +import std.stdio; +import thrift.codegen.processor; +import thrift.protocol.binary; +import thrift.server.simple; +import thrift.server.transport.socket; +import thrift.transport.buffered; + +import share.SharedService; +import share.shared_types; +import tutorial.Calculator; +import tutorial.tutorial_types; + +/** + * The actual implementation of the Calculator interface that is called by + * the server to answer the requests. + */ +class CalculatorHandler : Calculator { + void ping() { + writeln("ping()"); + } + + int add(int n1, int n2) { + writefln("add(%s,%s)", n1, n2); + return n1 + n2; + } + + int calculate(int logid, ref const(Work) work) { + writefln("calculate(%s, {%s, %s, %s})", logid, work.op, work.num1, work.num2); + int val; + + switch (work.op) { + case Operation.ADD: + val = work.num1 + work.num2; + break; + case Operation.SUBTRACT: + val = work.num1 - work.num2; + break; + case Operation.MULTIPLY: + val = work.num1 * work.num2; + break; + case Operation.DIVIDE: + if (work.num2 == 0) { + auto io = new InvalidOperation(); + io.whatOp = work.op; + io.why = "Cannot divide by 0"; + throw io; + } + val = work.num1 / work.num2; + break; + default: + auto io = new InvalidOperation(); + io.whatOp = work.op; + io.why = "Invalid Operation"; + throw io; + } + + auto ss = SharedStruct(); + ss.key = logid; + ss.value = to!string(val); + log[logid] = ss; + + return val; + } + + SharedStruct getStruct(int logid) { + writefln("getStruct(%s)", logid); + return log[logid]; + } + + void zip() { + writeln("zip()"); + } + +protected: + SharedStruct[int] log; +} + +void main() { + auto protocolFactory = new TBinaryProtocolFactory!(); + auto processor = new TServiceProcessor!Calculator(new CalculatorHandler); + auto serverTransport = new TServerSocket(9090); + auto transportFactory = new TBufferedTransportFactory; + + auto server = new TSimpleServer( + processor, serverTransport, transportFactory, protocolFactory); + + writeln("Starting the server on port 9090..."); + server.serve(); + writeln("done."); +} diff --git a/src/jaegertracing/thrift/tutorial/dart/Makefile.am b/src/jaegertracing/thrift/tutorial/dart/Makefile.am new file mode 100644 index 000000000..0b93ac859 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/dart/Makefile.am @@ -0,0 +1,81 @@ +# +# 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. +# + +BUILT_SOURCES = gen-dart/tutorial/lib/tutorial.dart gen-dart/shared/lib/shared.dart + +gen-dart/tutorial/lib/tutorial.dart gen-dart/shared/lib/shared.dart: $(top_srcdir)/tutorial/tutorial.thrift + $(THRIFT) --gen dart -r $< + +all-local: gen-dart/tutorial/lib/tutorial.dart pub-get + +clean-local: + $(RM) -r gen-*/ + find . -type d -name ".dart_tool" | xargs $(RM) -r + find . -type d -name "packages" | xargs $(RM) -r + find . -type f -name ".packages" | xargs $(RM) + find . -type f -name "pubspec.lock" | xargs $(RM) + +dist-hook: + $(RM) -r $(distdir)/gen-*/ + find $(distdir) -type d -name ".dart_tool" | xargs $(RM) -r + find $(distdir) -type d -name "packages" | xargs $(RM) -r + find $(distdir) -type f -name ".packages" | xargs $(RM) + find $(distdir) -type f -name "pubspec.lock" | xargs $(RM) + +pub-get: pub-get-gen pub-get-client pub-get-console-client pub-get-server + +pub-get-gen: pub-get-tutorial pub-get-shared + +pub-get-tutorial: gen-dart/tutorial/lib/tutorial.dart + cd gen-dart/tutorial; ${DARTPUB} get + +pub-get-shared: gen-dart/shared/lib/shared.dart + cd gen-dart/shared; ${DARTPUB} get + +pub-get-client: + cd client; ${DARTPUB} get + +pub-get-console-client: + cd console_client; ${DARTPUB} get + +pub-get-server: + cd server; ${DARTPUB} get + +tutorialserver: pub-get-gen pub-get-server + ${DART} server/bin/main.dart + +tutorialclient: pub-get-gen pub-get-client + cd client; ${DARTPUB} serve + +tutorialconsoleclient: pub-get-console-client + ${DART} console_client/bin/main.dart + +EXTRA_DIST = \ + client/web/client.dart \ + client/web/index.html \ + client/web/styles.css \ + client/pubspec.yaml \ + console_client/bin/main.dart \ + console_client/pubspec.yaml \ + server/bin/main.dart \ + server/pubspec.yaml \ + console_client/.analysis_options \ + client/.analysis_options \ + server/.analysis_options \ + build.sh diff --git a/src/jaegertracing/thrift/tutorial/dart/build.sh b/src/jaegertracing/thrift/tutorial/dart/build.sh new file mode 100644 index 000000000..eabe04a18 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/dart/build.sh @@ -0,0 +1,56 @@ +#!/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. + +set -e; +rm -r gen-dart || true; + +thrift --gen dart ../shared.thrift; +cd gen-dart/shared; +pub get; +cd ../..; + +thrift --gen dart ../tutorial.thrift; +cd gen-dart/tutorial; +pub get; +cd ../..; + +cd client; +pub get; +cd ..; + +cd console_client; +pub get; +cd ..; + +cd server; +pub get; +cd ..; + +dartfmt -w gen-dart; + +echo "\nEnjoy the Dart tutorial!"; +echo "\nTo run the server:"; +echo "> dart server/bin/main.dart"; +echo "\nTo run the client:"; +echo "# Serve the app from the client directory and view in a browser"; +echo "> cd client;"; +echo "> pub serve;"; +echo "\nTo run the console client:"; +echo "> dart console_client/bin/main.dart"; +echo ""; diff --git a/src/jaegertracing/thrift/tutorial/dart/client/.analysis_options b/src/jaegertracing/thrift/tutorial/dart/client/.analysis_options new file mode 100644 index 000000000..a10d4c5a0 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/dart/client/.analysis_options @@ -0,0 +1,2 @@ +analyzer: + strong-mode: true diff --git a/src/jaegertracing/thrift/tutorial/dart/client/pubspec.yaml b/src/jaegertracing/thrift/tutorial/dart/client/pubspec.yaml new file mode 100644 index 000000000..6581b4d21 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/dart/client/pubspec.yaml @@ -0,0 +1,33 @@ +# 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. + +name: tutorial_client +version: 0.13.0 +description: A Dart client implementation of the Apache Thrift tutorial +author: Apache Thrift Developers <dev@thrift.apache.org> +homepage: http://thrift.apache.org + +environment: + sdk: ">=1.13.0 <3.0.0" + +dependencies: + shared: + path: ../gen-dart/shared + thrift: + path: ../../../lib/dart + tutorial: + path: ../gen-dart/tutorial diff --git a/src/jaegertracing/thrift/tutorial/dart/client/web/client.dart b/src/jaegertracing/thrift/tutorial/dart/client/web/client.dart new file mode 100644 index 000000000..4f02d0d98 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/dart/client/web/client.dart @@ -0,0 +1,278 @@ +/// 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. + +import 'dart:html'; + +import 'package:thrift/thrift.dart'; +import 'package:thrift/thrift_browser.dart'; +import 'package:shared/shared.dart'; +import 'package:tutorial/tutorial.dart'; + +/// Adapted from the AS3 tutorial +void main() { + new CalculatorUI(querySelector('#output')).start(); +} + +class CalculatorUI { + final DivElement output; + + CalculatorUI(this.output); + + TTransport _transport; + Calculator _calculatorClient; + + void start() { + _buildInterface(); + _initConnection(); + } + + void _validate() { + if (!_transport.isOpen) { + window.alert("The transport is not open!"); + } + } + + void _initConnection() { + _transport = new TAsyncClientSocketTransport( + new TWebSocket(Uri.parse('ws://127.0.0.1:9090/ws')), + new TMessageReader(new TBinaryProtocolFactory())); + TProtocol protocol = new TBinaryProtocol(_transport); + _transport.open(); + + _calculatorClient = new CalculatorClient(protocol); + } + + void _buildInterface() { + output.children.forEach((e) { + e.remove(); + }); + + _buildPingComponent(); + + _buildAddComponent(); + + _buildCalculatorComponent(); + + _buildGetStructComponent(); + } + + void _buildPingComponent() { + output.append(new HeadingElement.h3()..text = "Ping"); + ButtonElement pingButton = new ButtonElement() + ..text = "PING" + ..onClick.listen(_onPingClick); + output.append(pingButton); + } + + void _onPingClick(MouseEvent e) { + _validate(); + + _calculatorClient.ping(); + } + + void _buildAddComponent() { + output.append(new HeadingElement.h3()..text = "Add"); + InputElement num1 = new InputElement() + ..id = "add1" + ..type = "number" + ..style.fontSize = "14px" + ..style.width = "50px"; + output.append(num1); + SpanElement op = new SpanElement() + ..text = "+" + ..style.fontSize = "14px" + ..style.marginLeft = "10px"; + output.append(op); + InputElement num2 = new InputElement() + ..id = "add2" + ..type = "number" + ..style.fontSize = "14px" + ..style.width = "50px" + ..style.marginLeft = "10px"; + output.append(num2); + ButtonElement addButton = new ButtonElement() + ..text = "=" + ..style.fontSize = "14px" + ..style.marginLeft = "10px" + ..onClick.listen(_onAddClick); + output.append(addButton); + SpanElement result = new SpanElement() + ..id = "addResult" + ..style.fontSize = "14px" + ..style.marginLeft = "10px"; + output.append(result); + } + + void _onAddClick(MouseEvent e) { + _validate(); + + InputElement num1 = querySelector("#add1"); + InputElement num2 = querySelector("#add2"); + SpanElement result = querySelector("#addResult"); + + _calculatorClient + .add(int.parse(num1.value), int.parse(num2.value)) + .then((int n) { + result.text = "$n"; + }); + } + + void _buildCalculatorComponent() { + output.append(new HeadingElement.h3()..text = "Calculator"); + InputElement num1 = new InputElement() + ..id = "calc1" + ..type = "number" + ..style.fontSize = "14px" + ..style.width = "50px"; + output.append(num1); + SelectElement op = new SelectElement() + ..id = "calcOp" + ..multiple = false + ..selectedIndex = 0 + ..style.fontSize = "16px" + ..style.marginLeft = "10px" + ..style.width = "50px"; + OptionElement addOp = new OptionElement() + ..text = "+" + ..value = Operation.ADD.toString(); + op.add(addOp, 0); + OptionElement subtractOp = new OptionElement() + ..text = "-" + ..value = Operation.SUBTRACT.toString(); + op.add(subtractOp, 1); + OptionElement multiplyOp = new OptionElement() + ..text = "*" + ..value = Operation.MULTIPLY.toString(); + op.add(multiplyOp, 2); + OptionElement divideOp = new OptionElement() + ..text = "/" + ..value = Operation.DIVIDE.toString(); + op.add(divideOp, 3); + output.append(op); + InputElement num2 = new InputElement() + ..id = "calc2" + ..type = "number" + ..style.fontSize = "14px" + ..style.width = "50px" + ..style.marginLeft = "10px"; + output.append(num2); + ButtonElement calcButton = new ButtonElement() + ..text = "=" + ..style.fontSize = "14px" + ..style.marginLeft = "10px" + ..onClick.listen(_onCalcClick); + output.append(calcButton); + SpanElement result = new SpanElement() + ..id = "calcResult" + ..style.fontSize = "14px" + ..style.marginLeft = "10px"; + output.append(result); + output.append(new BRElement()); + output.append(new BRElement()); + LabelElement logIdLabel = new LabelElement() + ..text = "Log ID:" + ..style.fontSize = "14px"; + output.append(logIdLabel); + InputElement logId = new InputElement() + ..id = "logId" + ..type = "number" + ..value = "1" + ..style.fontSize = "14px" + ..style.width = "50px" + ..style.marginLeft = "10px"; + output.append(logId); + LabelElement commentLabel = new LabelElement() + ..text = "Comment:" + ..style.fontSize = "14px" + ..style.marginLeft = "10px"; + output.append(commentLabel); + InputElement comment = new InputElement() + ..id = "comment" + ..style.fontSize = "14px" + ..style.width = "100px" + ..style.marginLeft = "10px"; + output.append(comment); + } + + void _onCalcClick(MouseEvent e) { + _validate(); + + InputElement num1 = querySelector("#calc1"); + InputElement num2 = querySelector("#calc2"); + SelectElement op = querySelector("#calcOp"); + SpanElement result = querySelector("#calcResult"); + InputElement logId = querySelector("#logId"); + InputElement comment = querySelector("#comment"); + + int logIdValue = int.parse(logId.value); + logId.value = (logIdValue + 1).toString(); + + Work work = new Work(); + work.num1 = int.parse(num1.value); + work.num2 = int.parse(num2.value); + work.op = int.parse(op.options[op.selectedIndex].value); + work.comment = comment.value; + + _calculatorClient.calculate(logIdValue, work).then((int n) { + result.text = "$n"; + }); + } + + void _buildGetStructComponent() { + output.append(new HeadingElement.h3()..text = "Get Struct"); + LabelElement logIdLabel = new LabelElement() + ..text = "Struct Key:" + ..style.fontSize = "14px"; + output.append(logIdLabel); + InputElement logId = new InputElement() + ..id = "structKey" + ..type = "number" + ..value = "1" + ..style.fontSize = "14px" + ..style.width = "50px" + ..style.marginLeft = "10px"; + output.append(logId); + ButtonElement getStructButton = new ButtonElement() + ..text = "GET" + ..style.fontSize = "14px" + ..style.marginLeft = "10px" + ..onClick.listen(_onGetStructClick); + output.append(getStructButton); + output.append(new BRElement()); + output.append(new BRElement()); + TextAreaElement result = new TextAreaElement() + ..id = "getStructResult" + ..style.fontSize = "14px" + ..style.width = "300px" + ..style.height = "50px" + ..style.marginLeft = "10px"; + output.append(result); + } + + void _onGetStructClick(MouseEvent e) { + _validate(); + + InputElement structKey = querySelector("#structKey"); + TextAreaElement result = querySelector("#getStructResult"); + + _calculatorClient + .getStruct(int.parse(structKey.value)) + .then((SharedStruct s) { + result.text = "${s.toString()}"; + }); + } +} diff --git a/src/jaegertracing/thrift/tutorial/dart/client/web/index.html b/src/jaegertracing/thrift/tutorial/dart/client/web/index.html new file mode 100644 index 000000000..9d36b4388 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/dart/client/web/index.html @@ -0,0 +1,35 @@ +<!-- + * 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. +--> +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Thrift Tutorial</title> + <link rel="stylesheet" href="styles.css"> + <script async src="client.dart.js"></script> +</head> + +<body> + + <div id="output"></div> + +</body> +</html> diff --git a/src/jaegertracing/thrift/tutorial/dart/client/web/styles.css b/src/jaegertracing/thrift/tutorial/dart/client/web/styles.css new file mode 100644 index 000000000..c0315025b --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/dart/client/web/styles.css @@ -0,0 +1,33 @@ +/* + * 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. + */ +@import url(https://fonts.googleapis.com/css?family=Roboto); + +html, body { + width: 100%; + height: 100%; + margin: 0; + padding: 10px; + font-family: 'Roboto', sans-serif; +} + +h3 { + border-bottom: solid; + border-width: thin; + padding-top: 20px; +} diff --git a/src/jaegertracing/thrift/tutorial/dart/console_client/.analysis_options b/src/jaegertracing/thrift/tutorial/dart/console_client/.analysis_options new file mode 100644 index 000000000..a10d4c5a0 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/dart/console_client/.analysis_options @@ -0,0 +1,2 @@ +analyzer: + strong-mode: true diff --git a/src/jaegertracing/thrift/tutorial/dart/console_client/bin/main.dart b/src/jaegertracing/thrift/tutorial/dart/console_client/bin/main.dart new file mode 100644 index 000000000..fda206ab9 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/dart/console_client/bin/main.dart @@ -0,0 +1,149 @@ +/// 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. + +import 'dart:async'; +import 'dart:io'; + +import 'package:args/args.dart'; +import 'package:logging/logging.dart'; +import 'package:thrift/thrift.dart'; +import 'package:thrift/thrift_console.dart'; +import 'package:tutorial/tutorial.dart'; + +TTransport _transport; +Calculator _calculator; +int logid = 0; + +const Map<String, int> operationLookup = const { + '+': Operation.ADD, + '-': Operation.SUBTRACT, + '*': Operation.MULTIPLY, + '/': Operation.DIVIDE +}; + +main(List<String> args) { + Logger.root.level = Level.ALL; + Logger.root.onRecord.listen((LogRecord rec) { + print('${rec.level.name}: ${rec.time}: ${rec.message}'); + }); + + var parser = new ArgParser(); + parser.addOption('port', defaultsTo: '9090', help: 'The port to connect to'); + + ArgResults results; + try { + results = parser.parse(args); + } catch (e) { + results = null; + } + + if (results == null) { + print(parser.usage); + exit(0); + } + + int port = int.parse(results['port']); + + _initConnection(port).then((_) => _run()); +} + +Future _initConnection(int port) async { + var socket = await Socket.connect('127.0.0.1', port); + _transport = new TAsyncClientSocketTransport( + new TTcpSocket(socket), new TMessageReader(new TBinaryProtocolFactory())); + TProtocol protocol = new TBinaryProtocol(_transport); + await _transport.open(); + + _calculator = new CalculatorClient(protocol); +} + +Future _run() async { + _help(); + + while (true) { + stdout.write("> "); + var input = stdin.readLineSync(); + var parts = input.split(' '); + var command = parts[0]; + var args = parts.length > 1 ? parts.sublist(1) : []; + + switch (command) { + case 'ping': + await _ping(); + break; + + case 'add': + await _add(int.parse(args[0]), int.parse(args[1])); + break; + + case 'calc': + int op = operationLookup[args[1]]; + if (!Operation.VALID_VALUES.contains(op)) { + stdout.writeln('Unknown operator ${args[1]}'); + break; + } + + var work = new Work() + ..num1 = int.parse(args[0]) + ..op = op + ..num2 = int.parse(args[2]) + ..comment = args.length > 3 ? args[3] : ''; + + await _calc(work); + break; + + case 'struct': + await _struct(int.parse(args[0])); + break; + + case 'help': + default: + _help(); + break; + } + } +} + +void _help() { + stdout.writeln('Commands:'); + stdout.writeln(' help'); + stdout.writeln(' ping'); + stdout.writeln(' add x y'); + stdout.writeln(' calc x op y [comment]'); + stdout.writeln(' struct id'); + stdout.writeln(''); +} + +Future _ping() async { + await _calculator.ping(); + stdout.writeln('ping succeeded'); +} + +Future _add(int x, int y) async { + int result = await _calculator.add(x, y); + stdout.writeln('= $result'); +} + +Future _calc(Work work) async { + int result = await _calculator.calculate(logid++, work); + stdout.writeln('= $result'); +} + +Future _struct(int key) async { + var struct = await _calculator.getStruct(key); + stdout.writeln(struct.toString()); +} diff --git a/src/jaegertracing/thrift/tutorial/dart/console_client/pubspec.yaml b/src/jaegertracing/thrift/tutorial/dart/console_client/pubspec.yaml new file mode 100644 index 000000000..ca122d2fd --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/dart/console_client/pubspec.yaml @@ -0,0 +1,36 @@ +# 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. + +name: tutorial_console_client +version: 0.13.0 +description: > + A Dart console client to implementation of the Apache Thrift tutorial +author: Apache Thrift Developers <dev@thrift.apache.org> +homepage: http://thrift.apache.org + +environment: + sdk: ">=1.13.0 <3.0.0" + +dependencies: + args: ">=0.13.0 <2.0.0" + collection: ^1.1.0 + shared: + path: ../gen-dart/shared + thrift: + path: ../../../lib/dart + tutorial: + path: ../gen-dart/tutorial diff --git a/src/jaegertracing/thrift/tutorial/dart/server/.analysis_options b/src/jaegertracing/thrift/tutorial/dart/server/.analysis_options new file mode 100644 index 000000000..a10d4c5a0 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/dart/server/.analysis_options @@ -0,0 +1,2 @@ +analyzer: + strong-mode: true diff --git a/src/jaegertracing/thrift/tutorial/dart/server/bin/main.dart b/src/jaegertracing/thrift/tutorial/dart/server/bin/main.dart new file mode 100644 index 000000000..b8ac30d3d --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/dart/server/bin/main.dart @@ -0,0 +1,163 @@ +/// 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. + +import 'dart:async'; +import 'dart:io'; + +import 'package:args/args.dart'; +import 'package:logging/logging.dart'; +import 'package:thrift/thrift.dart'; +import 'package:thrift/thrift_console.dart'; +import 'package:tutorial/tutorial.dart'; +import 'package:shared/shared.dart'; + +TProtocol _protocol; +TProcessor _processor; +WebSocket _webSocket; + +main(List<String> args) { + Logger.root.level = Level.ALL; + Logger.root.onRecord.listen((LogRecord rec) { + print('${rec.level.name}: ${rec.time}: ${rec.message}'); + }); + + var parser = new ArgParser(); + parser.addOption('port', defaultsTo: '9090', help: 'The port to listen on'); + parser.addOption('type', + defaultsTo: 'ws', + allowed: ['ws', 'tcp'], + help: 'The type of socket', + allowedHelp: {'ws': 'WebSocket', 'tcp': 'TCP Socket'}); + + ArgResults results; + try { + results = parser.parse(args); + } catch (e) { + results = null; + } + + if (results == null) { + print(parser.usage); + exit(0); + } + + int port = int.parse(results['port']); + String socketType = results['type']; + + if (socketType == 'tcp') { + _runTcpServer(port); + } else if (socketType == 'ws') { + _runWebSocketServer(port); + } +} + +Future _runWebSocketServer(int port) async { + var httpServer = await HttpServer.bind('127.0.0.1', port); + print('listening for WebSocket connections on $port'); + + httpServer.listen((HttpRequest request) async { + if (request.uri.path == '/ws') { + _webSocket = await WebSocketTransformer.upgrade(request); + await _initProcessor(new TWebSocket(_webSocket)); + } else { + print('Invalid path: ${request.uri.path}'); + } + }); +} + +Future _runTcpServer(int port) async { + var serverSocket = await ServerSocket.bind('127.0.0.1', port); + print('listening for TCP connections on $port'); + + Socket socket = await serverSocket.first; + await _initProcessor(new TTcpSocket(socket)); +} + +Future _initProcessor(TSocket socket) async { + TServerSocketTransport transport = new TServerSocketTransport(socket); + transport.onIncomingMessage.listen(_processMessage); + _processor = new CalculatorProcessor(new CalculatorServer()); + _protocol = new TBinaryProtocol(transport); + await _protocol.transport.open(); + + print('connected'); +} + +Future _processMessage(_) async { + _processor.process(_protocol, _protocol); +} + +class CalculatorServer implements Calculator { + final Map<int, SharedStruct> _log = {}; + + Future ping() async { + print('ping()'); + } + + Future<int> add(int num1, int num2) async { + print('add($num1, $num2)'); + + return num1 + num2; + } + + Future<int> calculate(int logid, Work work) async { + print('calulate($logid, ${work.toString()})'); + + int val; + + switch (work.op) { + case Operation.ADD: + val = work.num1 + work.num2; + break; + + case Operation.SUBTRACT: + val = work.num1 - work.num2; + break; + + case Operation.MULTIPLY: + val = work.num1 * work.num2; + break; + + case Operation.DIVIDE: + if (work.num2 == 0) { + var x = new InvalidOperation(); + x.whatOp = work.op; + x.why = 'Cannot divide by 0'; + throw x; + } + val = (work.num1 / work.num2).floor(); + break; + } + + var log = new SharedStruct(); + log.key = logid; + log.value = '$val "${work.comment}"'; + this._log[logid] = log; + + return val; + } + + Future zip() async { + print('zip()'); + } + + Future<SharedStruct> getStruct(int key) async { + print('getStruct($key)'); + + return _log[key]; + } +} diff --git a/src/jaegertracing/thrift/tutorial/dart/server/pubspec.yaml b/src/jaegertracing/thrift/tutorial/dart/server/pubspec.yaml new file mode 100644 index 000000000..e09465e70 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/dart/server/pubspec.yaml @@ -0,0 +1,34 @@ +# 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. + +name: tutorial_server +version: 0.13.0 +description: A Dart server to support the Apache Thrift tutorial +author: Apache Thrift Developers <dev@thrift.apache.org> +homepage: http://thrift.apache.org + +environment: + sdk: ">=1.13.0 <3.0.0" + +dependencies: + args: ">=0.13.0 <2.0.0" + shared: + path: ../gen-dart/shared + thrift: + path: ../../../lib/dart + tutorial: + path: ../gen-dart/tutorial diff --git a/src/jaegertracing/thrift/tutorial/delphi/DelphiClient/DelphiClient.dpr b/src/jaegertracing/thrift/tutorial/delphi/DelphiClient/DelphiClient.dpr new file mode 100644 index 000000000..4ea9eb3e9 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/delphi/DelphiClient/DelphiClient.dpr @@ -0,0 +1,117 @@ +(* + * 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. + *) +program DelphiClient; + +{$APPTYPE CONSOLE} +{$D 'Copyright (c) 2012 The Apache Software Foundation'} + +uses + SysUtils, + Generics.Collections, + Thrift in '..\..\..\lib\delphi\src\Thrift.pas', + Thrift.Collections in '..\..\..\lib\delphi\src\Thrift.Collections.pas', + Thrift.Exception in '..\..\..\lib\delphi\src\Thrift.Exception.pas', + Thrift.Utils in '..\..\..\lib\delphi\src\Thrift.Utils.pas', + Thrift.Stream in '..\..\..\lib\delphi\src\Thrift.Stream.pas', + Thrift.Protocol in '..\..\..\lib\delphi\src\Thrift.Protocol.pas', + Thrift.Server in '..\..\..\lib\delphi\src\Thrift.Server.pas', + Thrift.Transport in '..\..\..\lib\delphi\src\Thrift.Transport.pas', + Thrift.Transport.WinHTTP in '..\..\..\lib\delphi\src\Thrift.Transport.WinHTTP.pas', + Thrift.Transport.MsxmlHTTP in '..\..\..\lib\delphi\src\Thrift.Transport.MsxmlHTTP.pas', + Thrift.WinHTTP in '..\..\..\lib\delphi\src\Thrift.WinHTTP.pas', + Shared in '..\..\gen-delphi\Shared.pas', + Tutorial in '..\..\gen-delphi\Tutorial.pas'; + + +type + DelphiTutorialClient = class + public + class procedure Main; + end; + + +//--- DelphiTutorialClient --------------------------------------- + + +class procedure DelphiTutorialClient.Main; +var transport : ITransport; + protocol : IProtocol; + client : TCalculator.Iface; + work : IWork; + sum, quotient, diff : Integer; + log : ISharedStruct; +begin + try + transport := TSocketImpl.Create( 'localhost', 9090); + protocol := TBinaryProtocolImpl.Create( transport); + client := TCalculator.TClient.Create( protocol); + + transport.Open; + + client.ping; + WriteLn('ping()'); + + sum := client.add( 1, 1); + WriteLn( Format( '1+1=%d', [sum])); + + work := TWorkImpl.Create; + + work.Op := TOperation.DIVIDE; + work.Num1 := 1; + work.Num2 := 0; + try + quotient := client.calculate(1, work); + WriteLn( 'Whoa we can divide by 0'); + WriteLn( Format('1/0=%d',[quotient])); + except + on io: TInvalidOperation + do WriteLn( 'Invalid operation: ' + io.Why); + end; + + work.Op := TOperation.SUBTRACT; + work.Num1 := 15; + work.Num2 := 10; + try + diff := client.calculate( 1, work); + WriteLn( Format('15-10=%d', [diff])); + except + on io: TInvalidOperation + do WriteLn( 'Invalid operation: ' + io.Why); + end; + + log := client.getStruct(1); + WriteLn( Format( 'Check log: %s', [log.Value])); + + transport.Close(); + + except + on e : Exception + do WriteLn( e.ClassName+': '+e.Message); + end; +end; + + +begin + try + DelphiTutorialClient.Main; + except + on E: Exception do + Writeln(E.ClassName, ': ', E.Message); + end; +end. diff --git a/src/jaegertracing/thrift/tutorial/delphi/DelphiClient/DelphiClient.dproj b/src/jaegertracing/thrift/tutorial/delphi/DelphiClient/DelphiClient.dproj new file mode 100644 index 000000000..7026747d0 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/delphi/DelphiClient/DelphiClient.dproj @@ -0,0 +1,122 @@ + <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <ProjectGuid>{2B8FB3A1-2F9E-4883-8C53-0F56220B34F6}</ProjectGuid> + <MainSource>DelphiClient.dpr</MainSource> + <ProjectVersion>12.3</ProjectVersion> + <Basis>True</Basis> + <Config Condition="'$(Config)'==''">Debug</Config> + <Platform>Win32</Platform> + <AppType>Console</AppType> + <FrameworkType>None</FrameworkType> + <DCC_DCCCompiler>DCC32</DCC_DCCCompiler> + </PropertyGroup> + <PropertyGroup Condition="'$(Config)'=='Basis' or '$(Base)'!=''"> + <Base>true</Base> + </PropertyGroup> + <PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_1)'!=''"> + <Cfg_1>true</Cfg_1> + <CfgParent>Base</CfgParent> + <Base>true</Base> + </PropertyGroup> + <PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_2)'!=''"> + <Cfg_2>true</Cfg_2> + <CfgParent>Base</CfgParent> + <Base>true</Base> + </PropertyGroup> + <PropertyGroup Condition="'$(Base)'!=''"> + <DCC_UnitSearchPath>..\..\..\lib\delphi\src;$(DCC_UnitSearchPath)</DCC_UnitSearchPath> + <DCC_ImageBase>00400000</DCC_ImageBase> + <DCC_DcuOutput>.\dcu\$(Config)\$(Platform)</DCC_DcuOutput> + <DCC_UnitAlias>WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;$(DCC_UnitAlias)</DCC_UnitAlias> + <DCC_ExeOutput>..\bin\$(Config)\$(Platform)</DCC_ExeOutput> + <DCC_E>false</DCC_E> + <DCC_N>false</DCC_N> + <DCC_S>false</DCC_S> + <DCC_F>false</DCC_F> + <DCC_K>false</DCC_K> + </PropertyGroup> + <PropertyGroup Condition="'$(Cfg_1)'!=''"> + <DCC_Define>DEBUG;$(DCC_Define)</DCC_Define> + <DCC_Optimize>false</DCC_Optimize> + <DCC_GenerateStackFrames>true</DCC_GenerateStackFrames> + </PropertyGroup> + <PropertyGroup Condition="'$(Cfg_2)'!=''"> + <DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols> + <DCC_Define>RELEASE;$(DCC_Define)</DCC_Define> + <DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo> + <DCC_DebugInformation>false</DCC_DebugInformation> + </PropertyGroup> + <ItemGroup> + <DelphiCompile Include="DelphiClient.dpr"> + <MainSource>MainSource</MainSource> + </DelphiCompile> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.Collections.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.Exception.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.Utils.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.Stream.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.Protocol.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.Server.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.Transport.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.Transport.WinHTTP.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.Transport.MsxmlHTTP.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.WinHTTP.pas"/> + <DCCReference Include="..\..\gen-delphi\Shared.pas"/> + <DCCReference Include="..\..\gen-delphi\Tutorial.pas"/> + <BuildConfiguration Include="Release"> + <Key>Cfg_2</Key> + <CfgParent>Base</CfgParent> + </BuildConfiguration> + <BuildConfiguration Include="Basis"> + <Key>Base</Key> + </BuildConfiguration> + <BuildConfiguration Include="Debug"> + <Key>Cfg_1</Key> + <CfgParent>Base</CfgParent> + </BuildConfiguration> + </ItemGroup> + <Import Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')" Project="$(BDS)\Bin\CodeGear.Delphi.Targets"/> + <Import Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')" Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj"/> + <ProjectExtensions> + <Borland.Personality>Delphi.Personality.12</Borland.Personality> + <Borland.ProjectType/> + <BorlandProject> + <Delphi.Personality> + <VersionInfo> + <VersionInfo Name="IncludeVerInfo">True</VersionInfo> + <VersionInfo Name="AutoIncBuild">False</VersionInfo> + <VersionInfo Name="MajorVer">0</VersionInfo> + <VersionInfo Name="MinorVer">12</VersionInfo> + <VersionInfo Name="Release">0</VersionInfo> + <VersionInfo Name="Build">0</VersionInfo> + <VersionInfo Name="Debug">False</VersionInfo> + <VersionInfo Name="PreRelease">False</VersionInfo> + <VersionInfo Name="Special">False</VersionInfo> + <VersionInfo Name="Private">False</VersionInfo> + <VersionInfo Name="DLL">False</VersionInfo> + <VersionInfo Name="Locale">1033</VersionInfo> + <VersionInfo Name="CodePage">1252</VersionInfo> + </VersionInfo> + <VersionInfoKeys> + <VersionInfoKeys Name="CompanyName"/> + <VersionInfoKeys Name="FileDescription">Thrift Tutorial</VersionInfoKeys> + <VersionInfoKeys Name="FileVersion">0.13.0.0</VersionInfoKeys> + <VersionInfoKeys Name="InternalName">DelphiClient</VersionInfoKeys> + <VersionInfoKeys Name="LegalCopyright">Copyright © 2012 The Apache Software Foundation</VersionInfoKeys> + <VersionInfoKeys Name="LegalTrademarks"/> + <VersionInfoKeys Name="OriginalFilename">DelphiClient.exe</VersionInfoKeys> + <VersionInfoKeys Name="ProductName">Thrift</VersionInfoKeys> + <VersionInfoKeys Name="ProductVersion">0.13.0.0</VersionInfoKeys> + <VersionInfoKeys Name="Comments"/> + </VersionInfoKeys> + <Source> + <Source Name="MainSource">DelphiClient.dpr</Source> + </Source> + </Delphi.Personality> + <Platforms> + <Platform value="Win32">True</Platform> + </Platforms> + </BorlandProject> + <ProjectFileVersion>12</ProjectFileVersion> + </ProjectExtensions> + </Project> diff --git a/src/jaegertracing/thrift/tutorial/delphi/DelphiServer/DelphiServer.dpr b/src/jaegertracing/thrift/tutorial/delphi/DelphiServer/DelphiServer.dpr new file mode 100644 index 000000000..fc9997a3f --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/delphi/DelphiServer/DelphiServer.dpr @@ -0,0 +1,174 @@ +(* + * 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. + *) +program DelphiServer; + +{$APPTYPE CONSOLE} +{$D 'Copyright (c) 2012 The Apache Software Foundation'} + +{$Q+} // throws exceptions on numeric overflows + +uses + SysUtils, + Generics.Collections, + Thrift in '..\..\..\lib\delphi\src\Thrift.pas', + Thrift.Collections in '..\..\..\lib\delphi\src\Thrift.Collections.pas', + Thrift.Exception in '..\..\..\lib\delphi\src\Thrift.Exception.pas', + Thrift.Utils in '..\..\..\lib\delphi\src\Thrift.Utils.pas', + Thrift.Stream in '..\..\..\lib\delphi\src\Thrift.Stream.pas', + Thrift.Protocol in '..\..\..\lib\delphi\src\Thrift.Protocol.pas', + Thrift.Server in '..\..\..\lib\delphi\src\Thrift.Server.pas', + Thrift.Transport in '..\..\..\lib\delphi\src\Thrift.Transport.pas', + Thrift.WinHTTP in '..\..\..\lib\delphi\src\Thrift.WinHTTP.pas', + Shared in '..\..\gen-delphi\Shared.pas', + Tutorial in '..\..\gen-delphi\Tutorial.pas'; + + +type + TCalculatorHandler = class( TInterfacedObject, TCalculator.Iface) + protected + FLog : TDictionary< Integer, ISharedStruct>; + + // TSharedService.Iface + function getStruct(key: Integer): ISharedStruct; + + // TCalculator.Iface + procedure ping(); + function add(num1: Integer; num2: Integer): Integer; + function calculate(logid: Integer; const w: IWork): Integer; + procedure zip(); + + public + constructor Create; + destructor Destroy; override; + + end; + + DelphiTutorialServer = class + public + class procedure Main; + end; + + +//--- TCalculatorHandler --------------------------------------------------- + + +constructor TCalculatorHandler.Create; +begin + inherited Create; + FLog := TDictionary< Integer, ISharedStruct>.Create(); +end; + + +destructor TCalculatorHandler.Destroy; +begin + try + FreeAndNil( FLog); + finally + inherited Destroy; + end; +end; + + +procedure TCalculatorHandler.ping; +begin + WriteLn( 'ping()'); +end; + + +function TCalculatorHandler.add(num1: Integer; num2: Integer): Integer; +begin + WriteLn( Format( 'add( %d, %d)', [num1, num2])); + result := num1 + num2; +end; + + +function TCalculatorHandler.calculate(logid: Integer; const w: IWork): Integer; +var entry : ISharedStruct; +begin + try + WriteLn( Format('calculate( %d, [%d,%d,%d])', [logid, Ord(w.Op), w.Num1, w.Num2])); + + case w.Op of + TOperation.ADD : result := w.Num1 + w.Num2; + TOperation.SUBTRACT : result := w.Num1 - w.Num2; + TOperation.MULTIPLY : result := w.Num1 * w.Num2; + TOperation.DIVIDE : result := Round( w.Num1 / w.Num2); + else + raise TInvalidOperation.Create( Ord(w.Op), 'Unknown operation'); + end; + + except + on e:Thrift.TException do raise; // let Thrift Exceptions pass through + on e:Exception do raise TInvalidOperation.Create( Ord(w.Op), e.Message); // repackage all other + end; + + entry := TSharedStructImpl.Create; + entry.Key := logid; + entry.Value := IntToStr( result); + FLog.AddOrSetValue( logid, entry); +end; + + +function TCalculatorHandler.getStruct(key: Integer): ISharedStruct; +begin + WriteLn( Format( 'getStruct(%d)', [key])); + result := FLog[key]; +end; + + +procedure TCalculatorHandler.zip; +begin + WriteLn( 'zip()'); +end; + + +//--- DelphiTutorialServer ---------------------------------------------------------------------- + + +class procedure DelphiTutorialServer.Main; +var handler : TCalculator.Iface; + processor : IProcessor; + transport : IServerTransport; + server : IServer; +begin + try + handler := TCalculatorHandler.Create; + processor := TCalculator.TProcessorImpl.Create( handler); + transport := TServerSocketImpl.Create( 9090); + server := TSimpleServer.Create( processor, transport); + + WriteLn( 'Starting the server...'); + server.Serve(); + + except + on e: Exception do WriteLn( e.Message); + end; + + WriteLn('done.'); +end; + + +begin + try + DelphiTutorialServer.Main; + except + on E: Exception do + Writeln(E.ClassName, ': ', E.Message); + end; +end. diff --git a/src/jaegertracing/thrift/tutorial/delphi/DelphiServer/DelphiServer.dproj b/src/jaegertracing/thrift/tutorial/delphi/DelphiServer/DelphiServer.dproj new file mode 100644 index 000000000..ec1da2e69 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/delphi/DelphiServer/DelphiServer.dproj @@ -0,0 +1,119 @@ + <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <ProjectGuid>{2B8FB3A1-2F9E-4883-8C53-0F56220B34F6}</ProjectGuid> + <MainSource>DelphiServer.dpr</MainSource> + <ProjectVersion>12.3</ProjectVersion> + <Basis>True</Basis> + <Config Condition="'$(Config)'==''">Debug</Config> + <Platform>Win32</Platform> + <AppType>Console</AppType> + <FrameworkType>None</FrameworkType> + <DCC_DCCCompiler>DCC32</DCC_DCCCompiler> + </PropertyGroup> + <PropertyGroup Condition="'$(Config)'=='Basis' or '$(Base)'!=''"> + <Base>true</Base> + </PropertyGroup> + <PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_1)'!=''"> + <Cfg_1>true</Cfg_1> + <CfgParent>Base</CfgParent> + <Base>true</Base> + </PropertyGroup> + <PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_2)'!=''"> + <Cfg_2>true</Cfg_2> + <CfgParent>Base</CfgParent> + <Base>true</Base> + </PropertyGroup> + <PropertyGroup Condition="'$(Base)'!=''"> + <DCC_ImageBase>00400000</DCC_ImageBase> + <DCC_DcuOutput>.\dcu\$(Config)\$(Platform)</DCC_DcuOutput> + <DCC_UnitAlias>WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;$(DCC_UnitAlias)</DCC_UnitAlias> + <DCC_ExeOutput>..\bin\$(Config)\$(Platform)</DCC_ExeOutput> + <DCC_E>false</DCC_E> + <DCC_N>false</DCC_N> + <DCC_S>false</DCC_S> + <DCC_F>false</DCC_F> + <DCC_K>false</DCC_K> + </PropertyGroup> + <PropertyGroup Condition="'$(Cfg_1)'!=''"> + <DCC_Define>DEBUG;$(DCC_Define)</DCC_Define> + <DCC_Optimize>false</DCC_Optimize> + <DCC_GenerateStackFrames>true</DCC_GenerateStackFrames> + </PropertyGroup> + <PropertyGroup Condition="'$(Cfg_2)'!=''"> + <DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols> + <DCC_Define>RELEASE;$(DCC_Define)</DCC_Define> + <DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo> + <DCC_DebugInformation>false</DCC_DebugInformation> + </PropertyGroup> + <ItemGroup> + <DelphiCompile Include="DelphiServer.dpr"> + <MainSource>MainSource</MainSource> + </DelphiCompile> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.Collections.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.Exception.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.Utils.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.Stream.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.Protocol.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.Server.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.Transport.pas"/> + <DCCReference Include="..\..\..\lib\delphi\src\Thrift.WinHTTP.pas"/> + <DCCReference Include="..\..\gen-delphi\Shared.pas"/> + <DCCReference Include="..\..\gen-delphi\Tutorial.pas"/> + <BuildConfiguration Include="Release"> + <Key>Cfg_2</Key> + <CfgParent>Base</CfgParent> + </BuildConfiguration> + <BuildConfiguration Include="Basis"> + <Key>Base</Key> + </BuildConfiguration> + <BuildConfiguration Include="Debug"> + <Key>Cfg_1</Key> + <CfgParent>Base</CfgParent> + </BuildConfiguration> + </ItemGroup> + <Import Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')" Project="$(BDS)\Bin\CodeGear.Delphi.Targets"/> + <Import Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')" Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj"/> + <ProjectExtensions> + <Borland.Personality>Delphi.Personality.12</Borland.Personality> + <Borland.ProjectType/> + <BorlandProject> + <Delphi.Personality> + <VersionInfo> + <VersionInfo Name="IncludeVerInfo">True</VersionInfo> + <VersionInfo Name="AutoIncBuild">False</VersionInfo> + <VersionInfo Name="MajorVer">0</VersionInfo> + <VersionInfo Name="MinorVer">12</VersionInfo> + <VersionInfo Name="Release">0</VersionInfo> + <VersionInfo Name="Build">0</VersionInfo> + <VersionInfo Name="Debug">False</VersionInfo> + <VersionInfo Name="PreRelease">False</VersionInfo> + <VersionInfo Name="Special">False</VersionInfo> + <VersionInfo Name="Private">False</VersionInfo> + <VersionInfo Name="DLL">False</VersionInfo> + <VersionInfo Name="Locale">1033</VersionInfo> + <VersionInfo Name="CodePage">1252</VersionInfo> + </VersionInfo> + <VersionInfoKeys> + <VersionInfoKeys Name="CompanyName"/> + <VersionInfoKeys Name="FileDescription">Thrift Tutorial</VersionInfoKeys> + <VersionInfoKeys Name="FileVersion">0.13.0.0</VersionInfoKeys> + <VersionInfoKeys Name="InternalName">DelphiServer</VersionInfoKeys> + <VersionInfoKeys Name="LegalCopyright">Copyright © 2012 The Apache Software Foundation</VersionInfoKeys> + <VersionInfoKeys Name="LegalTrademarks"/> + <VersionInfoKeys Name="OriginalFilename">DelphiServer.exe</VersionInfoKeys> + <VersionInfoKeys Name="ProductName">Thrift</VersionInfoKeys> + <VersionInfoKeys Name="ProductVersion">0.13.0.0</VersionInfoKeys> + <VersionInfoKeys Name="Comments"/> + </VersionInfoKeys> + <Source> + <Source Name="MainSource">DelphiServer.dpr</Source> + </Source> + </Delphi.Personality> + <Platforms> + <Platform value="Win32">True</Platform> + </Platforms> + </BorlandProject> + <ProjectFileVersion>12</ProjectFileVersion> + </ProjectExtensions> + </Project> diff --git a/src/jaegertracing/thrift/tutorial/delphi/Tutorial.groupproj b/src/jaegertracing/thrift/tutorial/delphi/Tutorial.groupproj new file mode 100644 index 000000000..3a2a23751 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/delphi/Tutorial.groupproj @@ -0,0 +1,48 @@ + <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <ProjectGuid>{3D042C7F-3EF2-4574-8304-AB7FB79F814C}</ProjectGuid> + </PropertyGroup> + <ItemGroup> + <Projects Include="DelphiServer\DelphiServer.dproj"> + <Dependencies/> + </Projects> + <Projects Include="DelphiClient\DelphiClient.dproj"> + <Dependencies/> + </Projects> + </ItemGroup> + <ProjectExtensions> + <Borland.Personality>Default.Personality.12</Borland.Personality> + <Borland.ProjectType/> + <BorlandProject> + <Default.Personality/> + </BorlandProject> + </ProjectExtensions> + <Target Name="DelphiServer"> + <MSBuild Projects="DelphiServer\DelphiServer.dproj"/> + </Target> + <Target Name="DelphiServer:Clean"> + <MSBuild Projects="DelphiServer\DelphiServer.dproj" Targets="Clean"/> + </Target> + <Target Name="DelphiServer:Make"> + <MSBuild Projects="DelphiServer\DelphiServer.dproj" Targets="Make"/> + </Target> + <Target Name="DelphiClient"> + <MSBuild Projects="DelphiClient\DelphiClient.dproj"/> + </Target> + <Target Name="DelphiClient:Clean"> + <MSBuild Projects="DelphiClient\DelphiClient.dproj" Targets="Clean"/> + </Target> + <Target Name="DelphiClient:Make"> + <MSBuild Projects="DelphiClient\DelphiClient.dproj" Targets="Make"/> + </Target> + <Target Name="Build"> + <CallTarget Targets="DelphiServer;DelphiClient"/> + </Target> + <Target Name="Clean"> + <CallTarget Targets="DelphiServer:Clean;DelphiClient:Clean"/> + </Target> + <Target Name="Make"> + <CallTarget Targets="DelphiServer:Make;DelphiClient:Make"/> + </Target> + <Import Condition="Exists('$(BDS)\Bin\CodeGear.Group.Targets')" Project="$(BDS)\Bin\CodeGear.Group.Targets"/> + </Project> |