diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/jaegertracing/thrift/tutorial/as3 | |
parent | Initial commit. (diff) | |
download | ceph-upstream/16.2.11+ds.tar.xz ceph-upstream/16.2.11+ds.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/jaegertracing/thrift/tutorial/as3')
-rw-r--r-- | src/jaegertracing/thrift/tutorial/as3/build.xml | 50 | ||||
-rw-r--r-- | src/jaegertracing/thrift/tutorial/as3/src/CalculatorUI.as | 142 |
2 files changed, 192 insertions, 0 deletions
diff --git a/src/jaegertracing/thrift/tutorial/as3/build.xml b/src/jaegertracing/thrift/tutorial/as3/build.xml new file mode 100644 index 000000000..f7ed32d04 --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/as3/build.xml @@ -0,0 +1,50 @@ +<project name="tutorial" default="dist" basedir="."> + + <description>Thrift actionscript 3.0 tutorial.</description> + + <property name="gen" location="gen-as3" /> + <property name="src" location="src" /> + <property name="thrift.src" location="../../lib/as3/src/" /> + <property name="dist" location="dist" /> + + <property name="final.name" value="as3-tutorial" /> + <property name="swf.name" value="${dist}/${final.name}.swf" /> + + <target name="flex.check" unless="FLEX_HOME"> + <fail message='You must set the FLEX_HOME property pointing to your flex SDK, eg. ant -DFLEX_HOME="/Applications/Adobe Flex Builder 3/sdks/3.2.0"'/> + </target> + + <target name="flex.init" depends="flex.check" unless="flex.finished"> + <taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" /> + <property name="flex.finished" value="true"/> + </target> + + <target name="init"> + <tstamp /> + <mkdir dir="${dist}"/> + </target> + + <target name="dist" depends="generate, flex.init, init"> + <mxmlc output="${swf.name}" file="${src}/CalculatorUI.as"> + <source-path path-element="${gen}" /> + <source-path path-element="${src}" /> + <source-path path-element="${thrift.src}" /> + </mxmlc> + </target> + + <target name="generate"> + <!-- Generate the thrift gen-java source --> + <exec executable="../../compiler/cpp/thrift" failonerror="true"> + <arg line="--gen as3 ../shared.thrift"/> + </exec> + <exec executable="../../compiler/cpp/thrift" failonerror="true"> + <arg line="--gen as3 ../tutorial.thrift"/> + </exec> + </target> + + <target name="clean"> + <delete dir="${gen}"/> + <delete dir="${dist}" /> + </target> + +</project> diff --git a/src/jaegertracing/thrift/tutorial/as3/src/CalculatorUI.as b/src/jaegertracing/thrift/tutorial/as3/src/CalculatorUI.as new file mode 100644 index 000000000..d996df5fa --- /dev/null +++ b/src/jaegertracing/thrift/tutorial/as3/src/CalculatorUI.as @@ -0,0 +1,142 @@ +package { + import flash.display.Sprite; + import flash.text.TextField; + import flash.text.TextFieldType; + import flash.events.MouseEvent; + import flash.system.Security; + + import org.apache.thrift.transport.TSocket; + import org.apache.thrift.transport.TTransport; + import org.apache.thrift.protocol.TProtocol; + import org.apache.thrift.protocol.TBinaryProtocol; + + /** + * Simple interface and connection logic implementation for tutorial. + */ + public class CalculatorUI extends Sprite { + public static const BUTTON_PADDING:uint = 5; + + private var mCalculatorClient:Calculator; // we use calculator through interface + private var mTransport:TTransport; // Transport, used to comunicate with server + + private var mAddButton:Sprite; + private var mLeft:TextField; + private var mRight:TextField; + private var mResult:TextField; + + private var pingButton:Sprite; + + public function CalculatorUI() { + buildInterface(); + initSecurity(); + initConnection(); + } + + private function initSecurity():void { + Security.loadPolicyFile("xmlsocket://127.0.0.1:9092"); + } + + /** + * Example of initializing connection. + */ + private function initConnection():void { + mTransport = new TSocket("127.0.0.1", 9090); // we connect to server + mTransport.open(); + // initialize protocol: + var protocol:TProtocol = new TBinaryProtocol(mTransport, false, false); + mCalculatorClient = new CalculatorImpl(protocol); // finally, we create calculator client instance + } + + private function onPingClick(me:MouseEvent):void { + if(!mTransport.isOpen()) return; + mCalculatorClient.ping(onPingError, onPingSuccess); + } + + private function onPingError(error:Error):void { + trace("Error, while requesting ping."); + throw error; + } + + private function onPingSuccess():void { + trace("Ping returned successfully"); + } + + private function onAddClick(me:MouseEvent):void { + if(!mTransport.isOpen()) return; + var num1:Number = Number(mLeft.text); + var num2:Number = Number(mRight.text); + mResult.text = "Processing..."; + mCalculatorClient.add(num1, num2, onAddError, onAddSuccess); + } + + private function onAddError(error:Error):void { + trace("Error, while requesting add."); + throw error; + } + + private function onAddSuccess(res:Number):void { + mResult.text = String(res); + } + + private function buildInterface():void { + addChild(pingButton = buildButton("PING")); + pingButton.x = (stage.stageWidth - pingButton.width) / 2; + pingButton.y = 10; + pingButton.addEventListener(MouseEvent.CLICK, onPingClick); + + var top:Number = pingButton.y + pingButton.height + 20; + addChild(mLeft = buildDigitInput()); + mLeft.x = 15; + mLeft.y = top + BUTTON_PADDING; + addChild(mRight = buildDigitInput()); + mRight.x = mLeft.x + mLeft.width + 15; + mRight.y = top + BUTTON_PADDING; + addChild(mAddButton = buildButton("ADD")); + mAddButton.x = mRight.x + mRight.width + 15; + mAddButton.y = top; + mAddButton.addEventListener(MouseEvent.CLICK, onAddClick); + addChild(mResult = buildDigitInput()); + mResult.x = mAddButton.x + mAddButton.width + 15; + mResult.y = top + BUTTON_PADDING; + } + + /** + * Simple digit-only input field. + */ + private function buildDigitInput():TextField { + var textField:TextField = new TextField; + textField.width = 75; + textField.height = 20; + textField.restrict = "0987654321."; + textField.type = TextFieldType.INPUT; + textField.background = true; + textField.backgroundColor = 0xaaaaff; + textField.textColor = 0xffff00; + return textField; + } + + /** + * Simple button drawing. + */ + private function buildButton(text:String):Sprite { + var button:Sprite = new Sprite; + var textField:TextField = new TextField; + textField.width = 4000; + textField.text = text; + textField.textColor = 0xffff00; + textField.width = textField.textWidth + 4; + textField.height = textField.textHeight + 4; + textField.mouseEnabled = false; + button.graphics.beginFill(0x0000ff); + button.graphics.lineStyle(0, 0x000000); + button.graphics.drawRoundRect(0, 0, textField.width + BUTTON_PADDING * 2, + textField.height + BUTTON_PADDING * 2, BUTTON_PADDING); + button.graphics.endFill(); + button.addChild(textField); + textField.x = BUTTON_PADDING; + textField.y = BUTTON_PADDING; + button.useHandCursor = button.buttonMode = true; + return button; + } + } +} |