TServer.php 2.2 KB

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