blob: b8a2590d568886b99adcdd13cc579a96f9691eba [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 Geyer1d20a372016-03-15 23:04:27 +020054 /**
55 * Prints 'testBool("%s")' where '%s' with thing as 'true' or 'false'
56 * @param bool thing - the bool data to print
57 * @return bool - returns the bool 'thing'
58 *
59 * @param thing
60 */
61 public function testBool(thing : Bool) : Bool
Jens Geyerfa2daef2015-09-22 00:11:01 +020062 {
63 trace('testBool($thing)');
64 return thing;
65 }
66
Jens Geyerb5028322014-11-09 02:38:11 +010067 /**
68 * Prints 'testString("%s")' with thing as '%s'
69 * @param string thing - the string to print
70 * @return string - returns the string 'thing'
71 *
72 * @param thing
73 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +020074 public function testString(thing:String):String
75 {
Jens Geyerb5028322014-11-09 02:38:11 +010076 trace("teststring(\"" + thing + "\")");
77 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +020078 }
79
Jens Geyerb5028322014-11-09 02:38:11 +010080 /**
81 * Prints 'testByte("%d")' with thing as '%d'
82 * @param byte thing - the byte to print
83 * @return byte - returns the byte 'thing'
84 *
85 * @param thing
86 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +020087 public function testByte(thing:haxe.Int32):haxe.Int32
88 {
Jens Geyerb5028322014-11-09 02:38:11 +010089 trace("testByte(" + thing + ")");
90 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +020091 }
92
Jens Geyerb5028322014-11-09 02:38:11 +010093 /**
94 * Prints 'testI32("%d")' with thing as '%d'
95 * @param i32 thing - the i32 to print
96 * @return i32 - returns the i32 'thing'
97 *
98 * @param thing
99 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200100 public function testI32(thing:haxe.Int32):haxe.Int32
101 {
Jens Geyerb5028322014-11-09 02:38:11 +0100102 trace("testI32(" + thing + ")");
103 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200104 }
105
Jens Geyerb5028322014-11-09 02:38:11 +0100106 /**
107 * Prints 'testI64("%d")' with thing as '%d'
108 * @param i64 thing - the i64 to print
109 * @return i64 - returns the i64 'thing'
110 *
111 * @param thing
112 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200113 public function testI64(thing:haxe.Int64):haxe.Int64
114 {
Jens Geyerb5028322014-11-09 02:38:11 +0100115 trace("testI64(" + thing + ")");
116 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200117 }
118
Jens Geyerb5028322014-11-09 02:38:11 +0100119 /**
120 * Prints 'testDouble("%f")' with thing as '%f'
121 * @param double thing - the double to print
122 * @return double - returns the double 'thing'
123 *
124 * @param thing
125 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200126 public function testDouble(thing:Float):Float
127 {
Jens Geyerb5028322014-11-09 02:38:11 +0100128 trace("testDouble(" + thing + ")");
129 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200130 }
131
Jens Geyerb5028322014-11-09 02:38:11 +0100132 /**
Jens Geyer43e195a2014-12-14 00:29:17 +0100133 * Prints 'testBinary("%s")' where '%s' is a hex-formatted string of thing's data
134 * @param binary thing - the binary data to print
135 * @return binary - returns the binary 'thing'
Jens Geyer426ab862015-03-02 23:37:15 +0100136 *
Jens Geyer43e195a2014-12-14 00:29:17 +0100137 * @param thing
138 */
139 public function testBinary(thing : haxe.io.Bytes) : haxe.io.Bytes
140 {
Jens Geyer426ab862015-03-02 23:37:15 +0100141 var hex = "";
142 for ( i in 0 ... thing.length) {
143 hex += StringTools.hex( thing.get(i), 2);
144 }
Jens Geyer43e195a2014-12-14 00:29:17 +0100145 trace('testBinary($hex)');
146 return thing;
147 }
Jens Geyer426ab862015-03-02 23:37:15 +0100148
Jens Geyer43e195a2014-12-14 00:29:17 +0100149 /**
Jens Geyerb5028322014-11-09 02:38:11 +0100150 * Prints 'testStruct("{%s}")' where thing has been formatted
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100151 * into a string of comma separated values
Jens Geyerb5028322014-11-09 02:38:11 +0100152 * @param Xtruct thing - the Xtruct to print
153 * @return Xtruct - returns the Xtruct 'thing'
154 *
155 * @param thing
156 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200157 public function testStruct(thing:Xtruct):Xtruct
158 {
Jens Geyerb5028322014-11-09 02:38:11 +0100159 trace("testStruct({" +
160 "\"" + thing.string_thing + "\", " +
161 thing.byte_thing + ", " +
162 thing.i32_thing + ", " +
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200163 Int64.toStr(thing.i64_thing) + "})");
Jens Geyerb5028322014-11-09 02:38:11 +0100164 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200165 }
166
Jens Geyerb5028322014-11-09 02:38:11 +0100167 /**
168 * Prints 'testNest("{%s}")' where thing has been formatted
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200169 * into a string of the nested struct
Jens Geyerb5028322014-11-09 02:38:11 +0100170 * @param Xtruct2 thing - the Xtruct2 to print
171 * @return Xtruct2 - returns the Xtruct2 'thing'
172 *
173 * @param thing
174 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200175 public function testNest(nest:Xtruct2):Xtruct2
176 {
Jens Geyerb5028322014-11-09 02:38:11 +0100177 var thing:Xtruct = nest.struct_thing;
178 trace("testNest({" +
179 nest.byte_thing + ", {" +
180 "\"" + thing.string_thing + "\", " +
181 thing.byte_thing + ", " +
182 thing.i32_thing + ", " +
183 Int64.toStr(thing.i64_thing) + "}, " +
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200184 nest.i32_thing + "})");
Jens Geyerb5028322014-11-09 02:38:11 +0100185 return nest;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200186 }
187
Jens Geyerb5028322014-11-09 02:38:11 +0100188 /**
189 * Prints 'testMap("{%s")' where thing has been formatted
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200190 * into a string of 'key => value' pairs
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100191 * separated by commas and new lines
Jens Geyerb5028322014-11-09 02:38:11 +0100192 * @param map<i32,i32> thing - the map<i32,i32> to print
193 * @return map<i32,i32> - returns the map<i32,i32> 'thing'
194 *
195 * @param thing
196 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200197 public function testMap(thing:IntMap<haxe.Int32>):IntMap<haxe.Int32>
198 {
Jens Geyerb5028322014-11-09 02:38:11 +0100199 trace("testMap({");
200 var first:Bool = true;
201 for (key in thing.keys()) {
202 if (first) {
203 first = false;
204 } else {
205 trace(", ");
206 };
207 trace(key + " => " + thing.get(key));
208 };
209 trace("})");
210 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200211 }
212
Jens Geyerb5028322014-11-09 02:38:11 +0100213 /**
214 * Prints 'testStringMap("{%s}")' where thing has been formatted
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200215 * into a string of 'key => value' pairs
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100216 * separated by commas and new lines
Jens Geyerb5028322014-11-09 02:38:11 +0100217 * @param map<string,string> thing - the map<string,string> to print
218 * @return map<string,string> - returns the map<string,string> 'thing'
219 *
220 * @param thing
221 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200222 public function testStringMap(thing:StringMap<String>):StringMap<String>
223 {
Jens Geyerb5028322014-11-09 02:38:11 +0100224 trace("testStringMap({");
225 var first:Bool = true;
226 for (key in thing.keys()) {
227 if (first) {
228 first = false;
229 } else {
230 trace(", ");
231 };
232 trace(key + " => " + thing.get(key));
233 };
234 trace("})");
235 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200236 }
237
Jens Geyerb5028322014-11-09 02:38:11 +0100238 /**
239 * Prints 'testSet("{%s}")' where thing has been formatted
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200240 * into a string of values
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100241 * separated by commas and new lines
Jens Geyerb5028322014-11-09 02:38:11 +0100242 * @param set<i32> thing - the set<i32> to print
243 * @return set<i32> - returns the set<i32> 'thing'
244 *
245 * @param thing
246 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200247 public function testSet(thing:IntSet):IntSet
248 {
Jens Geyerb5028322014-11-09 02:38:11 +0100249 trace("testSet({");
250 var first:Bool = true;
251 for (elem in thing) {
252 if (first) {
253 first = false;
254 } else {
255 trace(", ");
256 };
257 trace(elem);
258 };
259 trace("})");
260 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200261 }
262
Jens Geyerb5028322014-11-09 02:38:11 +0100263 /**
264 * Prints 'testList("{%s}")' where thing has been formatted
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200265 * into a string of values
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100266 * separated by commas and new lines
Jens Geyerb5028322014-11-09 02:38:11 +0100267 * @param list<i32> thing - the list<i32> to print
268 * @return list<i32> - returns the list<i32> 'thing'
269 *
270 * @param thing
271 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200272 public function testList(thing:List<haxe.Int32>):List<haxe.Int32>
273 {
Jens Geyerb5028322014-11-09 02:38:11 +0100274 trace("testList({");
275 var first:Bool = true;
276 for (elem in thing) {
277 if (first) {
278 first = false;
279 } else {
280 trace(", ");
281 };
282 trace(elem);
283 };
284 trace("})");
285 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200286 }
287
Jens Geyerb5028322014-11-09 02:38:11 +0100288 /**
289 * Prints 'testEnum("%d")' where thing has been formatted into it's numeric value
290 * @param Numberz thing - the Numberz to print
291 * @return Numberz - returns the Numberz 'thing'
292 *
293 * @param thing
294 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200295 public function testEnum(thing:Int):Int
296 {
Jens Geyerb5028322014-11-09 02:38:11 +0100297 trace("testEnum(" + thing + ")");
298 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200299 }
300
Jens Geyerb5028322014-11-09 02:38:11 +0100301 /**
302 * Prints 'testTypedef("%d")' with thing as '%d'
303 * @param UserId thing - the UserId to print
304 * @return UserId - returns the UserId 'thing'
305 *
306 * @param thing
307 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200308 public function testTypedef(thing:haxe.Int64):haxe.Int64
309 {
Jens Geyerb5028322014-11-09 02:38:11 +0100310 trace("testTypedef(" + thing + ")");
311 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200312 }
313
Jens Geyerb5028322014-11-09 02:38:11 +0100314 /**
315 * Prints 'testMapMap("%d")' with hello as '%d'
316 * @param i32 hello - the i32 to print
317 * @return map<i32,map<i32,i32>> - returns a dictionary with these values:
318 * {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, },
319 * 4 => {1 => 1, 2 => 2, 3 => 3, 4 => 4, }, }
320 *
321 * @param hello
322 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200323 public function testMapMap(hello:haxe.Int32):IntMap<IntMap<haxe.Int32>>
324 {
Jens Geyerb5028322014-11-09 02:38:11 +0100325 trace("testMapMap(" + hello + ")");
326 var mapmap = new IntMap<IntMap<Int>>();
327 var pos = new IntMap<Int>();
328 var neg = new IntMap<Int>();
329 for (i in 1 ... 5) {
330 pos.set(i, i);
331 neg.set(-i, -i);
332 };
333 mapmap.set(4, pos);
334 mapmap.set(-4, neg);
335 return mapmap;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200336 }
337
Jens Geyerb5028322014-11-09 02:38:11 +0100338 /**
339 * So you think you've got this all worked, out eh?
340 *
341 * Creates a the returned map with these values and prints it out:
342 * { 1 => { 2 => argument,
343 * 3 => argument,
344 * },
345 * 2 => { 6 => <empty Insanity struct>, },
346 * }
347 * @return map<UserId, map<Numberz,Insanity>> - a map with the above values
348 *
349 * @param argument
350 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200351 public function testInsanity(argument : Insanity) : Int64Map< IntMap< Insanity>>
352 {
Jens Geyerb5028322014-11-09 02:38:11 +0100353 trace("testInsanity()");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200354
Jens Geyerb5028322014-11-09 02:38:11 +0100355 var first_map = new IntMap< Insanity>();
Jens Geyer1ca09d02017-01-10 22:48:09 +0100356 first_map.set(Numberz.TWO, argument);
357 first_map.set(Numberz.THREE, argument);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200358
Jens Geyerb5028322014-11-09 02:38:11 +0100359 var second_map = new IntMap< Insanity>();
Jens Geyer1ca09d02017-01-10 22:48:09 +0100360 var looney = new Insanity();
Jens Geyerb5028322014-11-09 02:38:11 +0100361 second_map.set(Numberz.SIX, looney);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200362
Jens Geyerb5028322014-11-09 02:38:11 +0100363 var insane = new Int64Map< IntMap< Insanity>>();
364 insane.set( Int64.make(0,1), first_map);
365 insane.set( Int64.make(0,2), second_map);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200366
Jens Geyerb5028322014-11-09 02:38:11 +0100367 return insane;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200368 }
369
Jens Geyerb5028322014-11-09 02:38:11 +0100370 /**
371 * Prints 'testMulti()'
372 * @param byte arg0 -
373 * @param i32 arg1 -
374 * @param i64 arg2 -
375 * @param map<i16, string> arg3 -
376 * @param Numberz arg4 -
377 * @param UserId arg5 -
378 * @return Xtruct - returns an Xtruct
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200379 * with string_thing = "Hello2, byte_thing = arg0, i32_thing = arg1
Jens Geyerb5028322014-11-09 02:38:11 +0100380 * and i64_thing = arg2
381 *
382 * @param arg0
383 * @param arg1
384 * @param arg2
385 * @param arg3
386 * @param arg4
387 * @param arg5
388 */
389 public function testMulti(arg0:haxe.Int32, arg1:haxe.Int32, arg2:haxe.Int64,
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200390 arg3:IntMap<String>, arg4:Int, arg5:haxe.Int64):Xtruct
391 {
Jens Geyerb5028322014-11-09 02:38:11 +0100392 trace("testMulti()");
393 var hello = new Xtruct();
394 hello.string_thing = "Hello2";
395 hello.byte_thing = arg0;
396 hello.i32_thing = arg1;
397 hello.i64_thing = arg2;
398 return hello;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200399 }
400
Jens Geyerb5028322014-11-09 02:38:11 +0100401 /**
402 * Print 'testException(%s)' with arg as '%s'
403 * @param string arg - a string indication what type of exception to throw
404 * if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
405 * elsen if arg == "TException" throw TException
406 * else do not throw anything
407 *
408 * @param arg
409 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200410 public function testException(arg:String):Void
411 {
Jens Geyerb5028322014-11-09 02:38:11 +0100412 trace("testException(" + arg + ")");
413 if (arg == "Xception") {
414 var x = new Xception();
415 x.errorCode = 1001;
416 x.message = arg;
417 throw x;
418 };
419 if (arg == "TException") {
420 throw new TException();
421 };
422 return;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200423 }
424
Jens Geyerb5028322014-11-09 02:38:11 +0100425 /**
426 * Print 'testMultiException(%s, %s)' with arg0 as '%s' and arg1 as '%s'
427 * @param string arg - a string indication what type of exception to throw
428 * if arg0 == "Xception"
429 * throw Xception with errorCode = 1001 and message = "This is an Xception"
430 * else if arg0 == "Xception2"
431 * throw Xception2 with errorCode = 2002 and message = "This is an Xception2"
432 * else do not throw anything
433 * @return Xtruct - an Xtruct with string_thing = arg1
434 *
435 * @param arg0
436 * @param arg1
437 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200438 public function testMultiException(arg0:String, arg1:String):Xtruct
439 {
Jens Geyerb5028322014-11-09 02:38:11 +0100440 trace("testMultiException(" + arg0 + ", " + arg1 + ")");
441 if (arg0 == "Xception") {
442 var x = new Xception();
443 x.errorCode = 1001;
444 x.message = "This is an Xception";
445 throw x;
446 } else if (arg0 == "Xception2") {
447 var x = new Xception2();
448 x.errorCode = 2002;
449 x.struct_thing = new Xtruct();
450 x.struct_thing.string_thing = "This is an Xception2";
451 throw x;
452 };
453 var result = new Xtruct();
454 result.string_thing = arg1;
455 return result;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200456 }
457
Jens Geyerb5028322014-11-09 02:38:11 +0100458 /**
459 * Print 'testOneway(%d): Sleeping...' with secondsToSleep as '%d'
460 * sleep 'secondsToSleep'
461 * Print 'testOneway(%d): done sleeping!' with secondsToSleep as '%d'
462 * @param i32 secondsToSleep - the number of seconds to sleep
463 *
464 * @param secondsToSleep
465 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200466 public function testOneway(secondsToSleep:haxe.Int32):Void
467 {
Jens Geyerb5028322014-11-09 02:38:11 +0100468 trace("testOneway(" + secondsToSleep + "), sleeping...");
469 Sys.sleep(secondsToSleep);
470 trace("testOneway finished");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200471 }
472
473 public function testStop():Void
474 {
Jens Geyerb5028322014-11-09 02:38:11 +0100475 if (server != null) {
476 server.Stop();
477 };
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200478 }
479}