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; |
| 14 | using System.Collections.Generic; |
| 15 | using Thrift.Protocol; |
| 16 | using Thrift.Transport; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame^] | 17 | using System.IO; |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 18 | |
| 19 | namespace Thrift.Server |
| 20 | { |
| 21 | public abstract class TServer |
| 22 | { |
| 23 | /** |
| 24 | * Core processor |
| 25 | */ |
| 26 | protected TProcessor processor; |
| 27 | |
| 28 | /** |
| 29 | * Server transport |
| 30 | */ |
| 31 | protected TServerTransport serverTransport; |
| 32 | |
| 33 | /** |
| 34 | * Input Transport Factory |
| 35 | */ |
| 36 | protected TTransportFactory inputTransportFactory; |
| 37 | |
| 38 | /** |
| 39 | * Output Transport Factory |
| 40 | */ |
| 41 | protected TTransportFactory outputTransportFactory; |
| 42 | |
| 43 | /** |
| 44 | * Input Protocol Factory |
| 45 | */ |
| 46 | protected TProtocolFactory inputProtocolFactory; |
| 47 | |
| 48 | /** |
| 49 | * Output Protocol Factory |
| 50 | */ |
| 51 | protected TProtocolFactory outputProtocolFactory; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame^] | 52 | public delegate void LogDelegate(string str); |
| 53 | protected LogDelegate logDelegate; |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * Default constructors. |
| 57 | */ |
| 58 | |
| 59 | public TServer(TProcessor processor, |
| 60 | TServerTransport serverTransport) |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame^] | 61 | :this(processor, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), DefaultLogDelegate) |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | public TServer(TProcessor processor, |
| 66 | TServerTransport serverTransport, |
| 67 | LogDelegate logDelegate) |
| 68 | : 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] | 69 | { |
| 70 | } |
| 71 | |
| 72 | public TServer(TProcessor processor, |
| 73 | TServerTransport serverTransport, |
| 74 | TTransportFactory transportFactory) |
| 75 | :this(processor, |
| 76 | serverTransport, |
| 77 | transportFactory, |
| 78 | transportFactory, |
| 79 | new TBinaryProtocol.Factory(), |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame^] | 80 | new TBinaryProtocol.Factory(), |
| 81 | DefaultLogDelegate) |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 82 | { |
| 83 | } |
| 84 | |
| 85 | public TServer(TProcessor processor, |
| 86 | TServerTransport serverTransport, |
| 87 | TTransportFactory transportFactory, |
| 88 | TProtocolFactory protocolFactory) |
| 89 | :this(processor, |
| 90 | serverTransport, |
| 91 | transportFactory, |
| 92 | transportFactory, |
| 93 | protocolFactory, |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame^] | 94 | protocolFactory, |
| 95 | DefaultLogDelegate) |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 96 | { |
| 97 | } |
| 98 | |
| 99 | public TServer(TProcessor processor, |
| 100 | TServerTransport serverTransport, |
| 101 | TTransportFactory inputTransportFactory, |
| 102 | TTransportFactory outputTransportFactory, |
| 103 | TProtocolFactory inputProtocolFactory, |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame^] | 104 | TProtocolFactory outputProtocolFactory, |
| 105 | LogDelegate logDelegate) |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 106 | { |
| 107 | this.processor = processor; |
| 108 | this.serverTransport = serverTransport; |
| 109 | this.inputTransportFactory = inputTransportFactory; |
| 110 | this.outputTransportFactory = outputTransportFactory; |
| 111 | this.inputProtocolFactory = inputProtocolFactory; |
| 112 | this.outputProtocolFactory = outputProtocolFactory; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame^] | 113 | this.logDelegate = logDelegate; |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /** |
| 117 | * The run method fires up the server and gets things going. |
| 118 | */ |
| 119 | public abstract void Serve(); |
David Reiss | dc815f5 | 2008-03-02 00:58:04 +0000 | [diff] [blame] | 120 | |
| 121 | public abstract void Stop(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame^] | 122 | |
| 123 | protected static void DefaultLogDelegate(string s) |
| 124 | { |
| 125 | Console.Error.WriteLine(s); |
| 126 | } |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |