| Bryan Duxbury | 17115d7 | 2010-08-12 16:59:19 +0000 | [diff] [blame] | 1 | <?php | 
 | 2 |  | 
 | 3 | /** | 
 | 4 |  * Generic class for a Thrift server. | 
 | 5 |  * | 
 | 6 |  * @package thrift.server | 
 | 7 |  */ | 
 | 8 | abstract class TServer { | 
 | 9 |  | 
 | 10 |   /** | 
 | 11 |    * Processor to handle new clients | 
 | 12 |    * | 
 | 13 |    * @var TProcessor | 
 | 14 |    */ | 
 | 15 |   protected $processor_; | 
 | 16 |  | 
 | 17 |   /** | 
 | 18 |    * Server transport to be used for listening | 
 | 19 |    * and accepting new clients | 
 | 20 |    * | 
 | 21 |    * @var TServerTransport | 
 | 22 |    */ | 
 | 23 |   protected $transport_; | 
 | 24 |  | 
 | 25 |   /** | 
 | 26 |    * Input transport factory | 
 | 27 |    * | 
 | 28 |    * @var TTransportFactory | 
 | 29 |    */ | 
 | 30 |   protected $inputTransportFactory_; | 
 | 31 |  | 
 | 32 |   /** | 
 | 33 |    * Output transport factory | 
 | 34 |    * | 
 | 35 |    * @var TTransportFactory | 
 | 36 |    */ | 
 | 37 |   protected $outputTransportFactory_; | 
 | 38 |  | 
 | 39 |   /** | 
 | 40 |    * Input protocol factory | 
 | 41 |    * | 
 | 42 |    * @var TProtocolFactory | 
 | 43 |    */ | 
 | 44 |   protected $inputProtocolFactory_; | 
 | 45 |  | 
 | 46 |   /** | 
 | 47 |    * Output protocol factory | 
 | 48 |    * | 
 | 49 |    * @var TProtocolFactory | 
 | 50 |    */ | 
 | 51 |   protected $outputProtocolFactory_; | 
 | 52 |  | 
 | 53 |   /** | 
 | 54 |    * Sets up all the factories, etc | 
 | 55 |    * | 
 | 56 |    * @param object $processor | 
 | 57 |    * @param TServerTransport $transport | 
 | 58 |    * @param TTransportFactory $inputTransportFactory | 
 | 59 |    * @param TTransportFactory $outputTransportFactory | 
 | 60 |    * @param TProtocolFactory $inputProtocolFactory | 
 | 61 |    * @param TProtocolFactory $outputProtocolFactory | 
 | 62 |    * @return void | 
 | 63 |    */ | 
 | 64 |   public function __construct($processor, | 
 | 65 |                               TServerTransport $transport, | 
 | 66 |                               TTransportFactory $inputTransportFactory, | 
 | 67 |                               TTransportFactory $outputTransportFactory, | 
 | 68 |                               TProtocolFactory $inputProtocolFactory, | 
 | 69 |                               TProtocolFactory $outputProtocolFactory) { | 
 | 70 |     $this->processor_ = $processor; | 
 | 71 |     $this->transport_ = $transport; | 
 | 72 |     $this->inputTransportFactory_ = $inputTransportFactory; | 
 | 73 |     $this->outputTransportFactory_ = $outputTransportFactory; | 
 | 74 |     $this->inputProtocolFactory_ = $inputProtocolFactory; | 
 | 75 |     $this->outputProtocolFactory_ = $outputProtocolFactory; | 
 | 76 |   } | 
 | 77 |  | 
 | 78 |   /** | 
 | 79 |    * Serves the server. This should never return | 
 | 80 |    * unless a problem permits it to do so or it | 
 | 81 |    * is interrupted intentionally | 
 | 82 |    * | 
 | 83 |    * @abstract | 
 | 84 |    * @return void | 
 | 85 |    */ | 
 | 86 |   abstract public function serve(); | 
 | 87 |  | 
 | 88 |   /** | 
 | 89 |    * Stops the server serving | 
 | 90 |    * | 
 | 91 |    * @abstract | 
 | 92 |    * @return void | 
 | 93 |    */ | 
 | 94 |   abstract public function stop(); | 
 | 95 | } |