blob: 66b06e0092e55aa8f8aaf6445dae71d1bb18807d [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{
33 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 }
50
51 // optional: layered transport
52 var transfactory : TTransportFactory = null;
53 if ( args.framed) {
54 trace("- framed transport");
55 transfactory = new TFramedTransportFactory();
56 } else if ( args.buffered) {
57 trace("- buffered transport");
58 throw "TBufferedTransport not implemented yet";
59 //transfactory = new TBufferedTransportFactory();
60 }
61
62 // 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 }
75
76
77 // Processor
78 var handler = new TestServerHandler();
79 var processor = new ThriftTestProcessor(handler);
80
81 // Simple Server
82 var server = new TSimpleServer( processor, transport, transfactory, protfactory);
83
84
85 /*
86 // Server event handler
87 var events = new TestServerEventHandler();
88 server.setEventHandler(serverEvents);
89 handler.server = serverEngine;
90 */
91
92 // Run it
93 server.Serve();
94 trace("done.");
95
96 }
97 catch (x : TException)
98 {
99 trace('$x');
100 }
101 catch (x : Dynamic)
102 {
103 trace('$x');
104 }
105 }
106}