David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 1 | // |
| 2 | // TServer.cs |
| 3 | // |
| 4 | // Begin: Dec 3, 2007 |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 5 | // Authors: |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 6 | // Will Palmeri <wpalmeri@imeem.com> |
| 7 | // |
| 8 | // Distributed under the Thrift Software License |
| 9 | // |
| 10 | // See accompanying file LICENSE or visit the Thrift site at: |
| 11 | // http://developers.facebook.com/thrift/using |
| 12 | |
| 13 | using System; |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 14 | using Thrift.Protocol; |
| 15 | using Thrift.Transport; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 16 | using System.IO; |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 17 | |
| 18 | namespace Thrift.Server |
| 19 | { |
| 20 | public abstract class TServer |
| 21 | { |
| 22 | /** |
| 23 | * Core processor |
| 24 | */ |
| 25 | protected TProcessor processor; |
| 26 | |
| 27 | /** |
| 28 | * Server transport |
| 29 | */ |
| 30 | protected TServerTransport serverTransport; |
| 31 | |
| 32 | /** |
| 33 | * Input Transport Factory |
| 34 | */ |
| 35 | protected TTransportFactory inputTransportFactory; |
| 36 | |
| 37 | /** |
| 38 | * Output Transport Factory |
| 39 | */ |
| 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; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 51 | public delegate void LogDelegate(string str); |
| 52 | protected LogDelegate logDelegate; |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * Default constructors. |
| 56 | */ |
| 57 | |
| 58 | public TServer(TProcessor processor, |
| 59 | TServerTransport serverTransport) |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 60 | :this(processor, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), DefaultLogDelegate) |
| 61 | { |
| 62 | } |
| 63 | |
| 64 | public TServer(TProcessor processor, |
| 65 | TServerTransport serverTransport, |
| 66 | LogDelegate logDelegate) |
| 67 | : this(processor, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), DefaultLogDelegate) |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 68 | { |
| 69 | } |
| 70 | |
| 71 | public TServer(TProcessor processor, |
| 72 | TServerTransport serverTransport, |
| 73 | TTransportFactory transportFactory) |
| 74 | :this(processor, |
| 75 | serverTransport, |
| 76 | transportFactory, |
| 77 | transportFactory, |
| 78 | new TBinaryProtocol.Factory(), |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 79 | new TBinaryProtocol.Factory(), |
| 80 | DefaultLogDelegate) |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 81 | { |
| 82 | } |
| 83 | |
| 84 | public TServer(TProcessor processor, |
| 85 | TServerTransport serverTransport, |
| 86 | TTransportFactory transportFactory, |
| 87 | TProtocolFactory protocolFactory) |
| 88 | :this(processor, |
| 89 | serverTransport, |
| 90 | transportFactory, |
| 91 | transportFactory, |
| 92 | protocolFactory, |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 93 | protocolFactory, |
| 94 | DefaultLogDelegate) |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 95 | { |
| 96 | } |
| 97 | |
| 98 | public TServer(TProcessor processor, |
| 99 | TServerTransport serverTransport, |
| 100 | TTransportFactory inputTransportFactory, |
| 101 | TTransportFactory outputTransportFactory, |
| 102 | TProtocolFactory inputProtocolFactory, |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 103 | TProtocolFactory outputProtocolFactory, |
| 104 | LogDelegate logDelegate) |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 105 | { |
| 106 | this.processor = processor; |
| 107 | this.serverTransport = serverTransport; |
| 108 | this.inputTransportFactory = inputTransportFactory; |
| 109 | this.outputTransportFactory = outputTransportFactory; |
| 110 | this.inputProtocolFactory = inputProtocolFactory; |
| 111 | this.outputProtocolFactory = outputProtocolFactory; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 112 | this.logDelegate = logDelegate; |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /** |
| 116 | * The run method fires up the server and gets things going. |
| 117 | */ |
| 118 | public abstract void Serve(); |
David Reiss | dc815f5 | 2008-03-02 00:58:04 +0000 | [diff] [blame] | 119 | |
| 120 | public abstract void Stop(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 121 | |
| 122 | protected static void DefaultLogDelegate(string s) |
| 123 | { |
| 124 | Console.Error.WriteLine(s); |
| 125 | } |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |