blob: 502d0d1b66567223d1e72d10e58067ebd1bd62bc [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.*;
27
28import thrift.test.*; // generated code
29
30
31class TestServer
32{
Jens Geyerb5028322014-11-09 02:38:11 +010033 public static function Execute(args : Arguments) : Void
34 {
35 try
36 {
37 // Transport
38 var transport : TServerTransport = null;
39 switch( args.transport) {
40 case socket:
41 trace("- socket port "+args.port);
42 transport = new TServerSocket( args.port);
43 case http:
44 trace("- http");
45 throw "HTTP server not implemented yet";
46 //transport = new THttpServer( targetHost);
47 default:
48 throw "Unhandled transport";
49 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +020050
Jens Geyerb5028322014-11-09 02:38:11 +010051 // optional: layered transport
52 var transfactory : TTransportFactory = null;
53 if ( args.framed) {
54 trace("- framed transport");
55 transfactory = new TFramedTransportFactory();
56 }
57 if ( args.buffered) {
58 trace("- buffered transport");
Jens Geyerd35f6162014-11-29 19:23:03 +010059 transfactory = new TBufferedTransportFactory();
Jens Geyerb5028322014-11-09 02:38:11 +010060 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +020061
Jens Geyerb5028322014-11-09 02:38:11 +010062 // protocol
63 var protfactory : TProtocolFactory = null;
64 switch( args.protocol)
65 {
66 case binary:
67 trace("- binary protocol");
68 protfactory = new TBinaryProtocolFactory();
69 case json:
70 trace("- json protocol");
71 protfactory = new TJSONProtocolFactory();
72 default:
73 throw "Unhandled protocol";
74 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +020075
Jens Geyerbd52f1a2014-07-28 01:25:30 +020076
Jens Geyerb5028322014-11-09 02:38:11 +010077 // Processor
78 var handler = new TestServerHandler();
79 var processor = new ThriftTestProcessor(handler);
Jens Geyerbd52f1a2014-07-28 01:25:30 +020080
Jens Geyerb5028322014-11-09 02:38:11 +010081 // Simple Server
82 var server : TServer = null;
83 switch( args.servertype)
84 {
85 case simple:
86 server = new TSimpleServer( processor, transport, transfactory, protfactory);
87 default:
88 throw "Unhandled server type";
89 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +020090
Jens Geyerbd52f1a2014-07-28 01:25:30 +020091
Jens Geyerb5028322014-11-09 02:38:11 +010092 /*
93 // Server event handler
94 if( args.serverEvents) {
95 var events = new TestServerEventHandler();
96 server.setEventHandler(serverEvents);
97 handler.server = serverEngine;
98 }
99 */
100
101 // Run it
102 server.Serve();
103 trace("done.");
104
105 }
106 catch (x : TException)
107 {
108 trace('$x');
109 }
110 catch (x : Dynamic)
111 {
112 trace('$x');
113 }
114 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200115}