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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.thrift.*;
23 import org.apache.thrift.protocol.*;
24 import org.apache.thrift.transport.*;
25 import org.apache.thrift.server.*;
26 import org.apache.thrift.meta_data.*;
38 enum EndpointTransport {
55 public var printHelpOnly(default,null) : Bool = false;
57 public var server(default,null) : Bool = false;
58 public var servertype(default,null) : ServerType = simple;
60 public var host(default,null) : String = "localhost";
61 public var port(default,null) : Int = 9090;
63 public var protocol(default,null) : ProtocolType = binary;
64 public var transport(default,null) : EndpointTransport = socket;
65 public var framed(default,null) : Bool = false;
66 public var buffered(default,null) : Bool = false;
68 public var numIterations(default,null) : Int = 1;
69 public var numThreads(default,null) : Int = 1;
70 public var skipSpeedTest(default,null) : Bool = false;
73 public function new() {
78 } catch (e : String) {
88 trace("WN: Platform does not support program arguments, using defaults.");
94 private static function GetHelp() : String {
95 var sProg = Path.withoutDirectory( Sys.executablePath());
97 +sProg+" [client|server] [options]\n"
99 +"Modus: Either client or server, the default is client.\n"
102 +" -h [ --help ] produce help message\n"
103 +" --port arg (=9090) Port number to listen / connect to\n"
105 +" --domain-socket arg Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)\n"
106 +" --named-pipe arg Windows Named Pipe (e.g. MyThriftPipe)\n"
108 +" --protocol arg (=binary) protocol: binary, compact, json\n"
110 +" --ssl Encrypted Transport using SSL\n"
113 +"Server only options:\n"
114 +" --transport arg (=sockets) Transport: buffered, framed, http, anonpipe\n"
116 +" --processor-events processor-events\n"
117 +" --server-type arg (=simple) type of server, \"simple\", \"thread-pool\", \n"
118 +" \"threaded\", or \"nonblocking\"\n"
119 +" -n [ --workers ] arg (=4) Number of thread pools workers. Only valid for \n"
120 +" thread-pool server type\n"
123 +"Client only options:\n"
124 +" --host arg (=localhost) Host to connect\n"
125 +" --transport arg (=sockets) Transport: buffered, framed, http, evhttp\n"
127 +" --anon-pipes hRead hWrite Windows Anonymous Pipes pair (handles)\n"
129 +" -n [ --testloops ] arg (=1) Number of Tests\n"
130 +" -t [ --threads ] arg (=1) Number of Test threads\n"
131 +" --skip-speed-test Skip the speed test\n"
133 +"All arguments are optional.\n"
138 private function ParseArgs() : Void {
140 var args = Sys.args().copy();
141 if( (args == null) || (args.length <= 0)) {
147 var arg = args.shift();
148 if ( arg == "client") {
152 else if ( arg == "server") {
156 else if ( (arg == "-h") || (arg == "--help")) {
157 // -h [ --help ] produce help message
158 Sys.println( GetHelp());
159 printHelpOnly = true;
163 throw "First argument must be 'server' or 'client'";
167 while( args.length > 0) {
170 if ( (arg == "-h") || (arg == "--help")) {
171 // -h [ --help ] produce help message
172 Sys.println( GetHelp());
173 printHelpOnly = true;
176 else if (arg == "--port") {
177 // --port arg (=9090) Port number to listen
179 var tmp = Std.parseInt(arg);
183 throw "Invalid port number "+arg;
186 else if (arg == "--domain-socket") {
187 // --domain-socket arg Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)
188 throw "domain sockets not supported yet";
190 else if (arg == "--named-pipe") {
191 // --named-pipe arg Windows Named Pipe (e.g. MyThriftPipe)
192 throw "named pipes not supported yet";
194 else if (arg == "--protocol") {
195 // --protocol arg (=binary) protocol: binary, compact, json
197 if( arg == "binary") {
199 } else if( arg == "compact") {
201 } else if( arg == "json") {
207 else if (arg == "--ssl") {
208 // --ssl Encrypted Transport using SSL
209 throw "SSL not supported yet";
212 //Server only options:
214 ParseServerArgument( arg, args);
216 ParseClientArgument( arg, args);
223 private function ParseServerArgument( arg : String, args : Array<String>) : Void {
224 if (arg == "--transport") {
225 // --transport arg (=sockets) Transport: buffered, framed, http, anonpipe
227 if( arg == "buffered") {
229 } else if( arg == "framed") {
231 } else if( arg == "http") {
233 } else if( arg == "anonpipe") {
234 throw "Anon pipes transport not supported yet";
239 else if (arg == "--processor-events") {
240 throw "Processor events not supported yet";
242 else if (arg == "--server-type") {
243 // --server-type arg (=simple) type of server,
244 // one of "simple", "thread-pool", "threaded", "nonblocking"
246 if( arg == "simple") {
248 } else if( arg == "thread-pool") {
249 throw arg+" server not supported yet";
250 } else if( arg == "threaded") {
251 throw arg+" server not supported yet";
252 } else if( arg == "nonblocking") {
253 throw arg+" server not supported yet";
258 else if ((arg == "-n") || (arg == "--workers")) {
259 // -n [ --workers ] arg (=4) Number of thread pools workers. Only valid for
260 // thread-pool server type
262 var tmp = Std.parseInt(arg);
266 throw "Invalid number "+arg;
275 private function ParseClientArgument( arg : String, args : Array<String>) : Void {
276 if (arg == "--host") {
277 // --host arg (=localhost) Host to connect
280 else if (arg == "--transport") {
281 // --transport arg (=sockets) Transport: buffered, framed, http, evhttp
283 if( arg == "buffered") {
285 } else if( arg == "framed") {
287 } else if( arg == "http") {
289 } else if( arg == "evhttp") {
290 throw "evhttp transport not supported yet";
295 else if (arg == "--anon-pipes") {
296 // --anon-pipes hRead hWrite Windows Anonymous Pipes pair (handles)
297 throw "Anon pipes transport not supported yet";
299 else if ((arg == "-n") || (arg == "--testloops")) {
300 // -n [ --testloops ] arg (=1) Number of Tests
302 var tmp = Std.parseInt(arg);
306 throw "Invalid number "+arg;
309 else if ((arg == "-t") || (arg == "--threads")) {
310 // -t [ --threads ] arg (=1) Number of Test threads
312 var tmp = Std.parseInt(arg);
316 throw "Invalid number "+arg;
319 else if (arg == "--skip-speed-test") {
320 // --skip-speed-test Skip the speed test
321 skipSpeedTest = true;
332 private function InvalidArg( arg : String) : Void {
333 throw 'Invalid argument $arg';