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 | /** |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 27 | * Input Transport Factory |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 28 | */ |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 29 | protected TTransportFactory inputTransportFactory_; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 30 | |
| 31 | /** |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 32 | * Output Transport Factory |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 33 | */ |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 34 | protected TTransportFactory outputTransportFactory_; |
| 35 | |
| 36 | /** |
| 37 | * Input Protocol Factory |
| 38 | */ |
| 39 | protected TProtocolFactory inputProtocolFactory_; |
| 40 | |
| 41 | /** |
| 42 | * Output Protocol Factory |
| 43 | */ |
| 44 | protected TProtocolFactory outputProtocolFactory_; |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 45 | |
| 46 | /** |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 47 | * Default constructors. |
| 48 | */ |
| 49 | |
| 50 | protected TServer(TProcessor processor, |
| 51 | TServerTransport serverTransport) { |
| 52 | this(processor, |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 53 | serverTransport, |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 54 | new TTransportFactory(), |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 55 | new TTransportFactory(), |
| 56 | new TBinaryProtocol.Factory(), |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 57 | new TBinaryProtocol.Factory()); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | protected TServer(TProcessor processor, |
| 61 | TServerTransport serverTransport, |
| 62 | TTransportFactory transportFactory) { |
| 63 | this(processor, |
| 64 | serverTransport, |
| 65 | transportFactory, |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 66 | transportFactory, |
| 67 | new TBinaryProtocol.Factory(), |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 68 | new TBinaryProtocol.Factory()); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | protected TServer(TProcessor processor, |
| 72 | TServerTransport serverTransport, |
| 73 | TTransportFactory transportFactory, |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 74 | TProtocolFactory protocolFactory) { |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 75 | this(processor, |
| 76 | serverTransport, |
| 77 | transportFactory, |
| 78 | transportFactory, |
| 79 | protocolFactory, |
| 80 | protocolFactory); |
| 81 | } |
| 82 | |
| 83 | protected TServer(TProcessor processor, |
| 84 | TServerTransport serverTransport, |
| 85 | TTransportFactory inputTransportFactory, |
| 86 | TTransportFactory outputTransportFactory, |
| 87 | TProtocolFactory inputProtocolFactory, |
| 88 | TProtocolFactory outputProtocolFactory) { |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 89 | processor_ = processor; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 90 | serverTransport_ = serverTransport; |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 91 | inputTransportFactory_ = inputTransportFactory; |
| 92 | outputTransportFactory_ = outputTransportFactory; |
| 93 | inputProtocolFactory_ = inputProtocolFactory; |
| 94 | outputProtocolFactory_ = outputProtocolFactory; |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /** |
| 98 | * The run method fires up the server and gets things going. |
| 99 | */ |
Mark Slee | 4e755ca | 2006-09-12 00:46:08 +0000 | [diff] [blame] | 100 | public abstract void serve(); |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 101 | |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 102 | } |