]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/test/haxe/src/Arguments.hx
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / test / haxe / src / Arguments.hx
1 /*
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
20 package;
21
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.*;
27 import haxe.io.Path;
28
29 using StringTools;
30
31
32 enum ProtocolType {
33 binary;
34 json;
35 compact;
36 }
37
38 enum EndpointTransport {
39 socket;
40 http;
41 }
42
43 enum ServerType {
44 simple;
45 /*
46 threadpool;
47 threaded;
48 nonblocking;
49 */
50 }
51
52
53 class Arguments
54 {
55 public var printHelpOnly(default,null) : Bool = false;
56
57 public var server(default,null) : Bool = false;
58 public var servertype(default,null) : ServerType = simple;
59
60 public var host(default,null) : String = "localhost";
61 public var port(default,null) : Int = 9090;
62
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;
67
68 public var numIterations(default,null) : Int = 1;
69 public var numThreads(default,null) : Int = 1;
70 public var skipSpeedTest(default,null) : Bool = false;
71
72
73 public function new() {
74 #if sys
75 #if !phpwebserver
76 try {
77 ParseArgs();
78 } catch (e : String) {
79 trace(GetHelp());
80 throw e;
81 }
82 #else
83 //forcing server
84 server = true;
85 transport = http;
86 #end
87 #else
88 trace("WN: Platform does not support program arguments, using defaults.");
89 #end
90 }
91
92 #if sys
93
94 private static function GetHelp() : String {
95 var sProg = Path.withoutDirectory( Sys.executablePath());
96 return "\n"
97 +sProg+" [client|server] [options]\n"
98 +"\n"
99 +"Modus: Either client or server, the default is client.\n"
100 +"\n"
101 +"Common options:\n"
102 +" -h [ --help ] produce help message\n"
103 +" --port arg (=9090) Port number to listen / connect to\n"
104 /* not supported yet
105 +" --domain-socket arg Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)\n"
106 +" --named-pipe arg Windows Named Pipe (e.g. MyThriftPipe)\n"
107 */
108 +" --protocol arg (=binary) protocol: binary, compact, json\n"
109 /* not supported yet
110 +" --ssl Encrypted Transport using SSL\n"
111 */
112 +"\n"
113 +"Server only options:\n"
114 +" --transport arg (=sockets) Transport: buffered, framed, http, anonpipe\n"
115 /* not supported yet
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"
121 */
122 +"\n"
123 +"Client only options:\n"
124 +" --host arg (=localhost) Host to connect\n"
125 +" --transport arg (=sockets) Transport: buffered, framed, http, evhttp\n"
126 /* not supported yet
127 +" --anon-pipes hRead hWrite Windows Anonymous Pipes pair (handles)\n"
128 */
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"
132 +"\n"
133 +"All arguments are optional.\n"
134 ;
135 }
136
137
138 private function ParseArgs() : Void {
139
140 var args = Sys.args().copy();
141 if( (args == null) || (args.length <= 0)) {
142 server = false;
143 numThreads = 1;
144 return;
145 }
146
147 var arg = args.shift();
148 if ( arg == "client") {
149 server = false;
150 numThreads = 1;
151 }
152 else if ( arg == "server") {
153 server = true;
154 numThreads = 4;
155 }
156 else if ( (arg == "-h") || (arg == "--help")) {
157 // -h [ --help ] produce help message
158 Sys.println( GetHelp());
159 printHelpOnly = true;
160 return;
161 }
162 else {
163 throw "First argument must be 'server' or 'client'";
164 }
165
166
167 while( args.length > 0) {
168 arg = args.shift();
169
170 if ( (arg == "-h") || (arg == "--help")) {
171 // -h [ --help ] produce help message
172 Sys.println( GetHelp());
173 printHelpOnly = true;
174 return;
175 }
176 else if (arg == "--port") {
177 // --port arg (=9090) Port number to listen
178 arg = args.shift();
179 var tmp = Std.parseInt(arg);
180 if( tmp != null) {
181 port = tmp;
182 } else {
183 throw "Invalid port number "+arg;
184 }
185 }
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";
189 }
190 else if (arg == "--named-pipe") {
191 // --named-pipe arg Windows Named Pipe (e.g. MyThriftPipe)
192 throw "named pipes not supported yet";
193 }
194 else if (arg == "--protocol") {
195 // --protocol arg (=binary) protocol: binary, compact, json
196 arg = args.shift();
197 if( arg == "binary") {
198 protocol = binary;
199 } else if( arg == "compact") {
200 protocol = compact;
201 } else if( arg == "json") {
202 protocol = json;
203 } else {
204 InvalidArg(arg);
205 }
206 }
207 else if (arg == "--ssl") {
208 // --ssl Encrypted Transport using SSL
209 throw "SSL not supported yet";
210 }
211 else {
212 //Server only options:
213 if( server) {
214 ParseServerArgument( arg, args);
215 } else {
216 ParseClientArgument( arg, args);
217 }
218 }
219 }
220 }
221
222
223 private function ParseServerArgument( arg : String, args : Array<String>) : Void {
224 if (arg == "--transport") {
225 // --transport arg (=sockets) Transport: buffered, framed, http, anonpipe
226 arg = args.shift();
227 if( arg == "buffered") {
228 buffered = true;
229 } else if( arg == "framed") {
230 framed = true;
231 } else if( arg == "http") {
232 transport = http;
233 } else if( arg == "anonpipe") {
234 throw "Anon pipes transport not supported yet";
235 } else {
236 InvalidArg(arg);
237 }
238 }
239 else if (arg == "--processor-events") {
240 throw "Processor events not supported yet";
241 }
242 else if (arg == "--server-type") {
243 // --server-type arg (=simple) type of server,
244 // one of "simple", "thread-pool", "threaded", "nonblocking"
245 arg = args.shift();
246 if( arg == "simple") {
247 servertype = 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";
254 } else {
255 InvalidArg(arg);
256 }
257 }
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
261 arg = args.shift();
262 var tmp = Std.parseInt(arg);
263 if( tmp != null) {
264 numThreads = tmp;
265 } else{
266 throw "Invalid number "+arg;
267 }
268 }
269 else {
270 InvalidArg(arg);
271 }
272 }
273
274
275 private function ParseClientArgument( arg : String, args : Array<String>) : Void {
276 if (arg == "--host") {
277 // --host arg (=localhost) Host to connect
278 host = args.shift();
279 }
280 else if (arg == "--transport") {
281 // --transport arg (=sockets) Transport: buffered, framed, http, evhttp
282 arg = args.shift();
283 if( arg == "buffered") {
284 buffered = true;
285 } else if( arg == "framed") {
286 framed = true;
287 } else if( arg == "http") {
288 transport = http;
289 } else if( arg == "evhttp") {
290 throw "evhttp transport not supported yet";
291 } else {
292 InvalidArg(arg);
293 }
294 }
295 else if (arg == "--anon-pipes") {
296 // --anon-pipes hRead hWrite Windows Anonymous Pipes pair (handles)
297 throw "Anon pipes transport not supported yet";
298 }
299 else if ((arg == "-n") || (arg == "--testloops")) {
300 // -n [ --testloops ] arg (=1) Number of Tests
301 arg = args.shift();
302 var tmp = Std.parseInt(arg);
303 if( tmp != null) {
304 numIterations = tmp;
305 } else {
306 throw "Invalid number "+arg;
307 }
308 }
309 else if ((arg == "-t") || (arg == "--threads")) {
310 // -t [ --threads ] arg (=1) Number of Test threads
311 arg = args.shift();
312 var tmp = Std.parseInt(arg);
313 if( tmp != null) {
314 numThreads = tmp;
315 } else {
316 throw "Invalid number "+arg;
317 }
318 }
319 else if (arg == "--skip-speed-test") {
320 // --skip-speed-test Skip the speed test
321 skipSpeedTest = true;
322 }
323 else {
324 InvalidArg(arg);
325 }
326 }
327
328
329 #end
330
331
332 private function InvalidArg( arg : String) : Void {
333 throw 'Invalid argument $arg';
334 }
335 }