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 | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 4 | import com.facebook.thrift.transport.TServerTransport; |
| 5 | import com.facebook.thrift.transport.TTransportFactory; |
| 6 | import com.facebook.thrift.transport.TBaseTransportFactory; |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 7 | |
| 8 | /** |
| 9 | * Generic interface for a Thrift server. |
| 10 | * |
| 11 | * @author Mark Slee <mcslee@facebook.com> |
| 12 | */ |
| 13 | public abstract class TServer { |
| 14 | |
| 15 | /** |
| 16 | * The options class should be subclassed by particular servers which have |
| 17 | * specific options needs, while the general options should live here. |
| 18 | */ |
| 19 | public static class Options { |
| 20 | public Options() {} |
| 21 | } |
| 22 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 23 | /** |
| 24 | * Core processor |
| 25 | */ |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 26 | protected TProcessor processor_; |
| 27 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 28 | /** |
| 29 | * Server options |
| 30 | */ |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 31 | protected Options options_; |
| 32 | |
| 33 | /** |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 34 | * Server transport |
Mark Slee | ffcddd6 | 2006-09-06 20:37:03 +0000 | [diff] [blame] | 35 | */ |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 36 | protected TServerTransport serverTransport_; |
Mark Slee | ffcddd6 | 2006-09-06 20:37:03 +0000 | [diff] [blame] | 37 | |
| 38 | /** |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 39 | * Transport Factory |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 40 | */ |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 41 | protected TTransportFactory transportFactory_; |
| 42 | |
| 43 | /** |
| 44 | * Default constructors. |
| 45 | */ |
| 46 | |
| 47 | protected TServer(TProcessor processor, |
| 48 | TServerTransport serverTransport) { |
| 49 | this(processor, |
| 50 | serverTransport, |
| 51 | new TBaseTransportFactory(), |
| 52 | new Options()); |
| 53 | } |
| 54 | |
| 55 | protected TServer(TProcessor processor, |
| 56 | TServerTransport serverTransport, |
| 57 | TTransportFactory transportFactory) { |
| 58 | this(processor, |
| 59 | serverTransport, |
| 60 | transportFactory, |
| 61 | new Options()); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | protected TServer(TProcessor processor, |
| 66 | TServerTransport serverTransport, |
| 67 | Options options) { |
| 68 | this(processor, |
| 69 | serverTransport, |
| 70 | new TBaseTransportFactory(), |
| 71 | options); |
| 72 | } |
| 73 | |
| 74 | protected TServer(TProcessor processor, |
| 75 | TServerTransport serverTransport, |
| 76 | TTransportFactory transportFactory, |
| 77 | Options options) { |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 78 | processor_ = processor; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 79 | serverTransport_ = serverTransport; |
| 80 | transportFactory_ = transportFactory; |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 81 | options_ = options; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * The run method fires up the server and gets things going. |
| 86 | */ |
Mark Slee | 4e755ca | 2006-09-12 00:46:08 +0000 | [diff] [blame] | 87 | public abstract void serve(); |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 88 | } |