Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 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 | |
| 28 | import thrift.test.*; // generated code |
| 29 | |
| 30 | |
| 31 | class TestServer |
| 32 | { |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 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 | } |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 50 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 51 | // 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 Geyer | d35f616 | 2014-11-29 19:23:03 +0100 | [diff] [blame^] | 59 | transfactory = new TBufferedTransportFactory(); |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 60 | } |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 61 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 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 | } |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 75 | |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 76 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 77 | // Processor |
| 78 | var handler = new TestServerHandler(); |
| 79 | var processor = new ThriftTestProcessor(handler); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 80 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 81 | // 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 Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 90 | |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 91 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 92 | /* |
| 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 Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 115 | } |