blob: abcef134911305aeed8b6a8b270603b20537c3e1 [file] [log] [blame]
Jens Geyerbd52f1a2014-07-28 01:25:30 +02001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20package;
21
22import org.apache.thrift.*;
23import org.apache.thrift.protocol.*;
24import org.apache.thrift.transport.*;
25import org.apache.thrift.server.*;
26import org.apache.thrift.meta_data.*;
27import org.apache.thrift.helper.*;
28
29import haxe.Int32;
30import haxe.Int64;
31import haxe.io.Bytes;
32import haxe.ds.IntMap;
33import haxe.ds.StringMap;
34import haxe.ds.ObjectMap;
35
36import thrift.test.*; // generated code
37
38
39class TestServerHandler implements ThriftTest {
40
41 public var server:TServer;
42
43 public function new() {
44 }
45
Jens Geyerb5028322014-11-09 02:38:11 +010046 /**
47 * Prints "testVoid()" and returns nothing.
48 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +020049 public function testVoid():Void
50 {
Jens Geyerb5028322014-11-09 02:38:11 +010051 trace("testVoid()");
Jens Geyerbd52f1a2014-07-28 01:25:30 +020052 }
53
Jens Geyerb5028322014-11-09 02:38:11 +010054 /**
55 * Prints 'testString("%s")' with thing as '%s'
56 * @param string thing - the string to print
57 * @return string - returns the string 'thing'
58 *
59 * @param thing
60 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +020061 public function testString(thing:String):String
62 {
Jens Geyerb5028322014-11-09 02:38:11 +010063 trace("teststring(\"" + thing + "\")");
64 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +020065 }
66
Jens Geyerb5028322014-11-09 02:38:11 +010067 /**
68 * Prints 'testByte("%d")' with thing as '%d'
69 * @param byte thing - the byte to print
70 * @return byte - returns the byte 'thing'
71 *
72 * @param thing
73 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +020074 public function testByte(thing:haxe.Int32):haxe.Int32
75 {
Jens Geyerb5028322014-11-09 02:38:11 +010076 trace("testByte(" + thing + ")");
77 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +020078 }
79
Jens Geyerb5028322014-11-09 02:38:11 +010080 /**
81 * Prints 'testI32("%d")' with thing as '%d'
82 * @param i32 thing - the i32 to print
83 * @return i32 - returns the i32 'thing'
84 *
85 * @param thing
86 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +020087 public function testI32(thing:haxe.Int32):haxe.Int32
88 {
Jens Geyerb5028322014-11-09 02:38:11 +010089 trace("testI32(" + thing + ")");
90 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +020091 }
92
Jens Geyerb5028322014-11-09 02:38:11 +010093 /**
94 * Prints 'testI64("%d")' with thing as '%d'
95 * @param i64 thing - the i64 to print
96 * @return i64 - returns the i64 'thing'
97 *
98 * @param thing
99 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200100 public function testI64(thing:haxe.Int64):haxe.Int64
101 {
Jens Geyerb5028322014-11-09 02:38:11 +0100102 trace("testI64(" + thing + ")");
103 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200104 }
105
Jens Geyerb5028322014-11-09 02:38:11 +0100106 /**
107 * Prints 'testDouble("%f")' with thing as '%f'
108 * @param double thing - the double to print
109 * @return double - returns the double 'thing'
110 *
111 * @param thing
112 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200113 public function testDouble(thing:Float):Float
114 {
Jens Geyerb5028322014-11-09 02:38:11 +0100115 trace("testDouble(" + thing + ")");
116 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200117 }
118
Jens Geyerb5028322014-11-09 02:38:11 +0100119 /**
Jens Geyer43e195a2014-12-14 00:29:17 +0100120 * Prints 'testBinary("%s")' where '%s' is a hex-formatted string of thing's data
121 * @param binary thing - the binary data to print
122 * @return binary - returns the binary 'thing'
Jens Geyer426ab862015-03-02 23:37:15 +0100123 *
Jens Geyer43e195a2014-12-14 00:29:17 +0100124 * @param thing
125 */
126 public function testBinary(thing : haxe.io.Bytes) : haxe.io.Bytes
127 {
Jens Geyer426ab862015-03-02 23:37:15 +0100128 var hex = "";
129 for ( i in 0 ... thing.length) {
130 hex += StringTools.hex( thing.get(i), 2);
131 }
Jens Geyer43e195a2014-12-14 00:29:17 +0100132 trace('testBinary($hex)');
133 return thing;
134 }
Jens Geyer426ab862015-03-02 23:37:15 +0100135
Jens Geyer43e195a2014-12-14 00:29:17 +0100136 /**
Jens Geyerb5028322014-11-09 02:38:11 +0100137 * Prints 'testStruct("{%s}")' where thing has been formatted
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100138 * into a string of comma separated values
Jens Geyerb5028322014-11-09 02:38:11 +0100139 * @param Xtruct thing - the Xtruct to print
140 * @return Xtruct - returns the Xtruct 'thing'
141 *
142 * @param thing
143 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200144 public function testStruct(thing:Xtruct):Xtruct
145 {
Jens Geyerb5028322014-11-09 02:38:11 +0100146 trace("testStruct({" +
147 "\"" + thing.string_thing + "\", " +
148 thing.byte_thing + ", " +
149 thing.i32_thing + ", " +
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200150 Int64.toStr(thing.i64_thing) + "})");
Jens Geyerb5028322014-11-09 02:38:11 +0100151 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200152 }
153
Jens Geyerb5028322014-11-09 02:38:11 +0100154 /**
155 * Prints 'testNest("{%s}")' where thing has been formatted
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200156 * into a string of the nested struct
Jens Geyerb5028322014-11-09 02:38:11 +0100157 * @param Xtruct2 thing - the Xtruct2 to print
158 * @return Xtruct2 - returns the Xtruct2 'thing'
159 *
160 * @param thing
161 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200162 public function testNest(nest:Xtruct2):Xtruct2
163 {
Jens Geyerb5028322014-11-09 02:38:11 +0100164 var thing:Xtruct = nest.struct_thing;
165 trace("testNest({" +
166 nest.byte_thing + ", {" +
167 "\"" + thing.string_thing + "\", " +
168 thing.byte_thing + ", " +
169 thing.i32_thing + ", " +
170 Int64.toStr(thing.i64_thing) + "}, " +
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200171 nest.i32_thing + "})");
Jens Geyerb5028322014-11-09 02:38:11 +0100172 return nest;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200173 }
174
Jens Geyerb5028322014-11-09 02:38:11 +0100175 /**
176 * Prints 'testMap("{%s")' where thing has been formatted
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200177 * into a string of 'key => value' pairs
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100178 * separated by commas and new lines
Jens Geyerb5028322014-11-09 02:38:11 +0100179 * @param map<i32,i32> thing - the map<i32,i32> to print
180 * @return map<i32,i32> - returns the map<i32,i32> 'thing'
181 *
182 * @param thing
183 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200184 public function testMap(thing:IntMap<haxe.Int32>):IntMap<haxe.Int32>
185 {
Jens Geyerb5028322014-11-09 02:38:11 +0100186 trace("testMap({");
187 var first:Bool = true;
188 for (key in thing.keys()) {
189 if (first) {
190 first = false;
191 } else {
192 trace(", ");
193 };
194 trace(key + " => " + thing.get(key));
195 };
196 trace("})");
197 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200198 }
199
Jens Geyerb5028322014-11-09 02:38:11 +0100200 /**
201 * Prints 'testStringMap("{%s}")' where thing has been formatted
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200202 * into a string of 'key => value' pairs
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100203 * separated by commas and new lines
Jens Geyerb5028322014-11-09 02:38:11 +0100204 * @param map<string,string> thing - the map<string,string> to print
205 * @return map<string,string> - returns the map<string,string> 'thing'
206 *
207 * @param thing
208 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200209 public function testStringMap(thing:StringMap<String>):StringMap<String>
210 {
Jens Geyerb5028322014-11-09 02:38:11 +0100211 trace("testStringMap({");
212 var first:Bool = true;
213 for (key in thing.keys()) {
214 if (first) {
215 first = false;
216 } else {
217 trace(", ");
218 };
219 trace(key + " => " + thing.get(key));
220 };
221 trace("})");
222 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200223 }
224
Jens Geyerb5028322014-11-09 02:38:11 +0100225 /**
226 * Prints 'testSet("{%s}")' where thing has been formatted
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200227 * into a string of values
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100228 * separated by commas and new lines
Jens Geyerb5028322014-11-09 02:38:11 +0100229 * @param set<i32> thing - the set<i32> to print
230 * @return set<i32> - returns the set<i32> 'thing'
231 *
232 * @param thing
233 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200234 public function testSet(thing:IntSet):IntSet
235 {
Jens Geyerb5028322014-11-09 02:38:11 +0100236 trace("testSet({");
237 var first:Bool = true;
238 for (elem in thing) {
239 if (first) {
240 first = false;
241 } else {
242 trace(", ");
243 };
244 trace(elem);
245 };
246 trace("})");
247 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200248 }
249
Jens Geyerb5028322014-11-09 02:38:11 +0100250 /**
251 * Prints 'testList("{%s}")' where thing has been formatted
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200252 * into a string of values
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100253 * separated by commas and new lines
Jens Geyerb5028322014-11-09 02:38:11 +0100254 * @param list<i32> thing - the list<i32> to print
255 * @return list<i32> - returns the list<i32> 'thing'
256 *
257 * @param thing
258 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200259 public function testList(thing:List<haxe.Int32>):List<haxe.Int32>
260 {
Jens Geyerb5028322014-11-09 02:38:11 +0100261 trace("testList({");
262 var first:Bool = true;
263 for (elem in thing) {
264 if (first) {
265 first = false;
266 } else {
267 trace(", ");
268 };
269 trace(elem);
270 };
271 trace("})");
272 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200273 }
274
Jens Geyerb5028322014-11-09 02:38:11 +0100275 /**
276 * Prints 'testEnum("%d")' where thing has been formatted into it's numeric value
277 * @param Numberz thing - the Numberz to print
278 * @return Numberz - returns the Numberz 'thing'
279 *
280 * @param thing
281 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200282 public function testEnum(thing:Int):Int
283 {
Jens Geyerb5028322014-11-09 02:38:11 +0100284 trace("testEnum(" + thing + ")");
285 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200286 }
287
Jens Geyerb5028322014-11-09 02:38:11 +0100288 /**
289 * Prints 'testTypedef("%d")' with thing as '%d'
290 * @param UserId thing - the UserId to print
291 * @return UserId - returns the UserId 'thing'
292 *
293 * @param thing
294 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200295 public function testTypedef(thing:haxe.Int64):haxe.Int64
296 {
Jens Geyerb5028322014-11-09 02:38:11 +0100297 trace("testTypedef(" + thing + ")");
298 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200299 }
300
Jens Geyerb5028322014-11-09 02:38:11 +0100301 /**
302 * Prints 'testMapMap("%d")' with hello as '%d'
303 * @param i32 hello - the i32 to print
304 * @return map<i32,map<i32,i32>> - returns a dictionary with these values:
305 * {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, },
306 * 4 => {1 => 1, 2 => 2, 3 => 3, 4 => 4, }, }
307 *
308 * @param hello
309 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200310 public function testMapMap(hello:haxe.Int32):IntMap<IntMap<haxe.Int32>>
311 {
Jens Geyerb5028322014-11-09 02:38:11 +0100312 trace("testMapMap(" + hello + ")");
313 var mapmap = new IntMap<IntMap<Int>>();
314 var pos = new IntMap<Int>();
315 var neg = new IntMap<Int>();
316 for (i in 1 ... 5) {
317 pos.set(i, i);
318 neg.set(-i, -i);
319 };
320 mapmap.set(4, pos);
321 mapmap.set(-4, neg);
322 return mapmap;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200323 }
324
Jens Geyerb5028322014-11-09 02:38:11 +0100325 /**
326 * So you think you've got this all worked, out eh?
327 *
328 * Creates a the returned map with these values and prints it out:
329 * { 1 => { 2 => argument,
330 * 3 => argument,
331 * },
332 * 2 => { 6 => <empty Insanity struct>, },
333 * }
334 * @return map<UserId, map<Numberz,Insanity>> - a map with the above values
335 *
336 * @param argument
337 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200338 public function testInsanity(argument : Insanity) : Int64Map< IntMap< Insanity>>
339 {
Jens Geyerb5028322014-11-09 02:38:11 +0100340 trace("testInsanity()");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200341
Jens Geyerb5028322014-11-09 02:38:11 +0100342 var hello = new Xtruct();
343 hello.string_thing = "Hello2";
344 hello.byte_thing = 2;
345 hello.i32_thing = 2;
346 hello.i64_thing = Int64.make(0, 2);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200347
Jens Geyerb5028322014-11-09 02:38:11 +0100348 var goodbye = new Xtruct();
349 goodbye.string_thing = "Goodbye4";
350 goodbye.byte_thing = 4;
351 goodbye.i32_thing = 4;
352 goodbye.i64_thing = Int64.make(0, 4);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200353
Jens Geyerb5028322014-11-09 02:38:11 +0100354 var crazy = new Insanity();
355 crazy.userMap = new IntMap< haxe.Int64>();
356 crazy.userMap.set(Numberz.EIGHT, Int64.make(0,8));
357 crazy.xtructs = new List<Xtruct>();
358 crazy.xtructs.add(goodbye);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200359
Jens Geyerb5028322014-11-09 02:38:11 +0100360 var looney = new Insanity();
361 crazy.userMap.set(Numberz.FIVE, Int64.make(0,5));
362 crazy.xtructs.add(hello);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200363
Jens Geyerb5028322014-11-09 02:38:11 +0100364 var first_map = new IntMap< Insanity>();
365 first_map.set(Numberz.TWO, crazy);
366 first_map.set(Numberz.THREE, crazy);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200367
Jens Geyerb5028322014-11-09 02:38:11 +0100368 var second_map = new IntMap< Insanity>();
369 second_map.set(Numberz.SIX, looney);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200370
Jens Geyerb5028322014-11-09 02:38:11 +0100371 var insane = new Int64Map< IntMap< Insanity>>();
372 insane.set( Int64.make(0,1), first_map);
373 insane.set( Int64.make(0,2), second_map);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200374
Jens Geyerb5028322014-11-09 02:38:11 +0100375 return insane;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200376 }
377
Jens Geyerb5028322014-11-09 02:38:11 +0100378 /**
379 * Prints 'testMulti()'
380 * @param byte arg0 -
381 * @param i32 arg1 -
382 * @param i64 arg2 -
383 * @param map<i16, string> arg3 -
384 * @param Numberz arg4 -
385 * @param UserId arg5 -
386 * @return Xtruct - returns an Xtruct
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200387 * with string_thing = "Hello2, byte_thing = arg0, i32_thing = arg1
Jens Geyerb5028322014-11-09 02:38:11 +0100388 * and i64_thing = arg2
389 *
390 * @param arg0
391 * @param arg1
392 * @param arg2
393 * @param arg3
394 * @param arg4
395 * @param arg5
396 */
397 public function testMulti(arg0:haxe.Int32, arg1:haxe.Int32, arg2:haxe.Int64,
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200398 arg3:IntMap<String>, arg4:Int, arg5:haxe.Int64):Xtruct
399 {
Jens Geyerb5028322014-11-09 02:38:11 +0100400 trace("testMulti()");
401 var hello = new Xtruct();
402 hello.string_thing = "Hello2";
403 hello.byte_thing = arg0;
404 hello.i32_thing = arg1;
405 hello.i64_thing = arg2;
406 return hello;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200407 }
408
Jens Geyerb5028322014-11-09 02:38:11 +0100409 /**
410 * Print 'testException(%s)' with arg as '%s'
411 * @param string arg - a string indication what type of exception to throw
412 * if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
413 * elsen if arg == "TException" throw TException
414 * else do not throw anything
415 *
416 * @param arg
417 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200418 public function testException(arg:String):Void
419 {
Jens Geyerb5028322014-11-09 02:38:11 +0100420 trace("testException(" + arg + ")");
421 if (arg == "Xception") {
422 var x = new Xception();
423 x.errorCode = 1001;
424 x.message = arg;
425 throw x;
426 };
427 if (arg == "TException") {
428 throw new TException();
429 };
430 return;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200431 }
432
Jens Geyerb5028322014-11-09 02:38:11 +0100433 /**
434 * Print 'testMultiException(%s, %s)' with arg0 as '%s' and arg1 as '%s'
435 * @param string arg - a string indication what type of exception to throw
436 * if arg0 == "Xception"
437 * throw Xception with errorCode = 1001 and message = "This is an Xception"
438 * else if arg0 == "Xception2"
439 * throw Xception2 with errorCode = 2002 and message = "This is an Xception2"
440 * else do not throw anything
441 * @return Xtruct - an Xtruct with string_thing = arg1
442 *
443 * @param arg0
444 * @param arg1
445 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200446 public function testMultiException(arg0:String, arg1:String):Xtruct
447 {
Jens Geyerb5028322014-11-09 02:38:11 +0100448 trace("testMultiException(" + arg0 + ", " + arg1 + ")");
449 if (arg0 == "Xception") {
450 var x = new Xception();
451 x.errorCode = 1001;
452 x.message = "This is an Xception";
453 throw x;
454 } else if (arg0 == "Xception2") {
455 var x = new Xception2();
456 x.errorCode = 2002;
457 x.struct_thing = new Xtruct();
458 x.struct_thing.string_thing = "This is an Xception2";
459 throw x;
460 };
461 var result = new Xtruct();
462 result.string_thing = arg1;
463 return result;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200464 }
465
Jens Geyerb5028322014-11-09 02:38:11 +0100466 /**
467 * Print 'testOneway(%d): Sleeping...' with secondsToSleep as '%d'
468 * sleep 'secondsToSleep'
469 * Print 'testOneway(%d): done sleeping!' with secondsToSleep as '%d'
470 * @param i32 secondsToSleep - the number of seconds to sleep
471 *
472 * @param secondsToSleep
473 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200474 public function testOneway(secondsToSleep:haxe.Int32):Void
475 {
Jens Geyerb5028322014-11-09 02:38:11 +0100476 trace("testOneway(" + secondsToSleep + "), sleeping...");
477 Sys.sleep(secondsToSleep);
478 trace("testOneway finished");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200479 }
480
481 public function testStop():Void
482 {
Jens Geyerb5028322014-11-09 02:38:11 +0100483 if (server != null) {
484 server.Stop();
485 };
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200486 }
487}