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 20package org.apache.thrift.server; 21 22import org.apache.thrift.*; 23import org.apache.thrift.protocol.*; 24import org.apache.thrift.transport.*; 25import org.apache.thrift.meta_data.*; 26 27class TServer 28{ 29 private var processor : TProcessor = null; 30 private var serverTransport : TServerTransport = null; 31 private var inputTransportFactory : TTransportFactory = null; 32 private var outputTransportFactory : TTransportFactory = null; 33 private var inputProtocolFactory : TProtocolFactory = null; 34 private var outputProtocolFactory : TProtocolFactory = null; 35 36 // server events 37 public var serverEventHandler : TServerEventHandler = null; 38 39 // Log delegation 40 private var _logDelegate : Dynamic->Void = null; 41 public var logDelegate(get,set) : Dynamic->Void; 42 43 public function new( processor : TProcessor, 44 serverTransport : TServerTransport, 45 inputTransportFactory : TTransportFactory = null, 46 outputTransportFactory : TTransportFactory = null, 47 inputProtocolFactory : TProtocolFactory = null, 48 outputProtocolFactory : TProtocolFactory = null, 49 logDelegate : Dynamic->Void = null) 50 { 51 this.processor = processor; 52 this.serverTransport = serverTransport; 53 this.inputTransportFactory = inputTransportFactory; 54 this.outputTransportFactory = outputTransportFactory; 55 this.inputProtocolFactory = inputProtocolFactory; 56 this.outputProtocolFactory = outputProtocolFactory; 57 this.logDelegate = logDelegate; 58 59 ApplyMissingDefaults(); 60 } 61 62 private function ApplyMissingDefaults() { 63 if( processor == null) 64 throw "Invalid server configuration: processor missing"; 65 if( serverTransport == null) 66 throw "Invalid server configuration: serverTransport missing"; 67 if( inputTransportFactory == null) 68 inputTransportFactory = new TTransportFactory(); 69 if( outputTransportFactory == null) 70 outputTransportFactory = new TTransportFactory(); 71 if( inputProtocolFactory == null) 72 inputProtocolFactory = new TBinaryProtocolFactory(); 73 if( outputProtocolFactory == null) 74 outputProtocolFactory= new TBinaryProtocolFactory(); 75 if( logDelegate == null) 76 logDelegate = DefaultLogDelegate; 77 } 78 79 80 private function set_logDelegate(value : Dynamic->Void) : Dynamic->Void { 81 if(value != null) { 82 _logDelegate = value; 83 } else { 84 _logDelegate = DefaultLogDelegate; 85 } 86 return _logDelegate; 87 } 88 89 90 private function get_logDelegate() : Dynamic->Void { 91 return _logDelegate; 92 } 93 94 95 private function DefaultLogDelegate(value : Dynamic) : Void { 96 trace( value); 97 } 98 99 100 101 public function Serve() : Void { 102 throw new AbstractMethodError(); 103 } 104 105 106 public function Stop() : Void { 107 throw new AbstractMethodError(); 108 } 109 110} 111