Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 1 | package com.facebook.thrift.server; |
| 2 | |
| 3 | import com.facebook.thrift.TProcessor; |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 4 | import com.facebook.thrift.protocol.TBinaryProtocol; |
| 5 | import com.facebook.thrift.protocol.TProtocolFactory; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 6 | import com.facebook.thrift.transport.TServerTransport; |
| 7 | import com.facebook.thrift.transport.TTransportFactory; |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 8 | |
| 9 | /** |
| 10 | * Generic interface for a Thrift server. |
| 11 | * |
| 12 | * @author Mark Slee <mcslee@facebook.com> |
| 13 | */ |
| 14 | public abstract class TServer { |
| 15 | |
| 16 | /** |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 17 | * Core processor |
| 18 | */ |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 19 | protected TProcessor processor_; |
| 20 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 21 | /** |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 22 | * Server transport |
Mark Slee | ffcddd6 | 2006-09-06 20:37:03 +0000 | [diff] [blame] | 23 | */ |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 24 | protected TServerTransport serverTransport_; |
Mark Slee | ffcddd6 | 2006-09-06 20:37:03 +0000 | [diff] [blame] | 25 | |
| 26 | /** |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 27 | * Transport Factory |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 28 | */ |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 29 | protected TTransportFactory transportFactory_; |
| 30 | |
| 31 | /** |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 32 | * Protocol Factory |
| 33 | */ |
| 34 | protected TProtocolFactory protocolFactory_; |
| 35 | |
| 36 | /** |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 37 | * Default constructors. |
| 38 | */ |
| 39 | |
| 40 | protected TServer(TProcessor processor, |
| 41 | TServerTransport serverTransport) { |
| 42 | this(processor, |
| 43 | serverTransport, |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 44 | new TTransportFactory(), |
| 45 | new TBinaryProtocol.Factory()); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | protected TServer(TProcessor processor, |
| 49 | TServerTransport serverTransport, |
| 50 | TTransportFactory transportFactory) { |
| 51 | this(processor, |
| 52 | serverTransport, |
| 53 | transportFactory, |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 54 | new TBinaryProtocol.Factory()); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | protected TServer(TProcessor processor, |
| 58 | TServerTransport serverTransport, |
| 59 | TTransportFactory transportFactory, |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 60 | TProtocolFactory protocolFactory) { |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 61 | processor_ = processor; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 62 | serverTransport_ = serverTransport; |
| 63 | transportFactory_ = transportFactory; |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 64 | protocolFactory_ = protocolFactory; |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /** |
| 68 | * The run method fires up the server and gets things going. |
| 69 | */ |
Mark Slee | 4e755ca | 2006-09-12 00:46:08 +0000 | [diff] [blame] | 70 | public abstract void serve(); |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 71 | |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 72 | } |