blob: e9c838f397cd1a13d30643738b0232463515345d [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");
59 throw "TBufferedTransport not implemented yet";
60 //transfactory = new TBufferedTransportFactory();
61 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +020062
Jens Geyerb5028322014-11-09 02:38:11 +010063 // protocol
64 var protfactory : TProtocolFactory = null;
65 switch( args.protocol)
66 {
67 case binary:
68 trace("- binary protocol");
69 protfactory = new TBinaryProtocolFactory();
70 case json:
71 trace("- json protocol");
72 protfactory = new TJSONProtocolFactory();
73 default:
74 throw "Unhandled protocol";
75 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +020076
Jens Geyerbd52f1a2014-07-28 01:25:30 +020077
Jens Geyerb5028322014-11-09 02:38:11 +010078 // Processor
79 var handler = new TestServerHandler();
80 var processor = new ThriftTestProcessor(handler);
Jens Geyerbd52f1a2014-07-28 01:25:30 +020081
Jens Geyerb5028322014-11-09 02:38:11 +010082 // Simple Server
83 var server : TServer = null;
84 switch( args.servertype)
85 {
86 case simple:
87 server = new TSimpleServer( processor, transport, transfactory, protfactory);
88 default:
89 throw "Unhandled server type";
90 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +020091
Jens Geyerbd52f1a2014-07-28 01:25:30 +020092
Jens Geyerb5028322014-11-09 02:38:11 +010093 /*
94 // Server event handler
95 if( args.serverEvents) {
96 var events = new TestServerEventHandler();
97 server.setEventHandler(serverEvents);
98 handler.server = serverEngine;
99 }
100 */
101
102 // Run it
103 server.Serve();
104 trace("done.");
105
106 }
107 catch (x : TException)
108 {
109 trace('$x');
110 }
111 catch (x : Dynamic)
112 {
113 trace('$x');
114 }
115 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200116}