Mark Slee | 7eb0d63 | 2007-03-01 00:00:27 +0000 | [diff] [blame] | 1 | // Copyright (c) 2006- Facebook |
| 2 | // Distributed under the Thrift Software License |
| 3 | // |
| 4 | // See accompanying file LICENSE or visit the Thrift site at: |
| 5 | // http://developers.facebook.com/thrift/ |
| 6 | |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 7 | package com.facebook.thrift.server; |
| 8 | |
Mark Slee | 448849d | 2007-05-31 01:30:22 +0000 | [diff] [blame] | 9 | import com.facebook.thrift.TProcessorFactory; |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 10 | import com.facebook.thrift.protocol.TBinaryProtocol; |
| 11 | import com.facebook.thrift.protocol.TProtocolFactory; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 12 | import com.facebook.thrift.transport.TServerTransport; |
| 13 | import com.facebook.thrift.transport.TTransportFactory; |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 14 | |
| 15 | /** |
| 16 | * Generic interface for a Thrift server. |
| 17 | * |
| 18 | * @author Mark Slee <mcslee@facebook.com> |
| 19 | */ |
| 20 | public abstract class TServer { |
| 21 | |
| 22 | /** |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 23 | * Core processor |
| 24 | */ |
Mark Slee | 448849d | 2007-05-31 01:30:22 +0000 | [diff] [blame] | 25 | protected TProcessorFactory processorFactory_; |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 26 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 27 | /** |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 28 | * Server transport |
Mark Slee | ffcddd6 | 2006-09-06 20:37:03 +0000 | [diff] [blame] | 29 | */ |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 30 | protected TServerTransport serverTransport_; |
Mark Slee | ffcddd6 | 2006-09-06 20:37:03 +0000 | [diff] [blame] | 31 | |
| 32 | /** |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 33 | * Input Transport Factory |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 34 | */ |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 35 | protected TTransportFactory inputTransportFactory_; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 36 | |
| 37 | /** |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 38 | * Output Transport Factory |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 39 | */ |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 40 | protected TTransportFactory outputTransportFactory_; |
| 41 | |
| 42 | /** |
| 43 | * Input Protocol Factory |
| 44 | */ |
| 45 | protected TProtocolFactory inputProtocolFactory_; |
| 46 | |
| 47 | /** |
| 48 | * Output Protocol Factory |
| 49 | */ |
| 50 | protected TProtocolFactory outputProtocolFactory_; |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 51 | |
| 52 | /** |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 53 | * Default constructors. |
| 54 | */ |
| 55 | |
Mark Slee | 448849d | 2007-05-31 01:30:22 +0000 | [diff] [blame] | 56 | protected TServer(TProcessorFactory processorFactory, |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 57 | TServerTransport serverTransport) { |
Mark Slee | 448849d | 2007-05-31 01:30:22 +0000 | [diff] [blame] | 58 | this(processorFactory, |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 59 | serverTransport, |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 60 | new TTransportFactory(), |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 61 | new TTransportFactory(), |
| 62 | new TBinaryProtocol.Factory(), |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 63 | new TBinaryProtocol.Factory()); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Mark Slee | 448849d | 2007-05-31 01:30:22 +0000 | [diff] [blame] | 66 | protected TServer(TProcessorFactory processorFactory, |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 67 | TServerTransport serverTransport, |
| 68 | TTransportFactory transportFactory) { |
Mark Slee | 448849d | 2007-05-31 01:30:22 +0000 | [diff] [blame] | 69 | this(processorFactory, |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 70 | serverTransport, |
| 71 | transportFactory, |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 72 | transportFactory, |
| 73 | new TBinaryProtocol.Factory(), |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 74 | new TBinaryProtocol.Factory()); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Mark Slee | 448849d | 2007-05-31 01:30:22 +0000 | [diff] [blame] | 77 | protected TServer(TProcessorFactory processorFactory, |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 78 | TServerTransport serverTransport, |
| 79 | TTransportFactory transportFactory, |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 80 | TProtocolFactory protocolFactory) { |
Mark Slee | 448849d | 2007-05-31 01:30:22 +0000 | [diff] [blame] | 81 | this(processorFactory, |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 82 | serverTransport, |
| 83 | transportFactory, |
| 84 | transportFactory, |
| 85 | protocolFactory, |
| 86 | protocolFactory); |
| 87 | } |
| 88 | |
Mark Slee | 448849d | 2007-05-31 01:30:22 +0000 | [diff] [blame] | 89 | protected TServer(TProcessorFactory processorFactory, |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 90 | TServerTransport serverTransport, |
| 91 | TTransportFactory inputTransportFactory, |
| 92 | TTransportFactory outputTransportFactory, |
| 93 | TProtocolFactory inputProtocolFactory, |
| 94 | TProtocolFactory outputProtocolFactory) { |
Mark Slee | 448849d | 2007-05-31 01:30:22 +0000 | [diff] [blame] | 95 | processorFactory_ = processorFactory; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 96 | serverTransport_ = serverTransport; |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 97 | inputTransportFactory_ = inputTransportFactory; |
| 98 | outputTransportFactory_ = outputTransportFactory; |
| 99 | inputProtocolFactory_ = inputProtocolFactory; |
| 100 | outputProtocolFactory_ = outputProtocolFactory; |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /** |
| 104 | * The run method fires up the server and gets things going. |
| 105 | */ |
Mark Slee | 4e755ca | 2006-09-12 00:46:08 +0000 | [diff] [blame] | 106 | public abstract void serve(); |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 107 | |
Mark Slee | 0502e61 | 2007-11-03 05:30:32 +0000 | [diff] [blame^] | 108 | /** |
| 109 | * Stop the server. This is optional on a per-implementation basis. Not |
| 110 | * all servers are required to be cleanly stoppable. |
| 111 | */ |
| 112 | public void stop() {} |
| 113 | |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 114 | } |