Kevin Clark | ab4460d | 2009-03-20 02:28:41 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
Todd Lipcon | 53ae9f3 | 2009-12-07 00:42:38 +0000 | [diff] [blame] | 18 | * |
| 19 | * Contains some contributions under the Thrift Software License. |
| 20 | * Please see doc/old-thrift-license.txt in the Thrift distribution for |
| 21 | * details. |
Kevin Clark | ab4460d | 2009-03-20 02:28:41 +0000 | [diff] [blame] | 22 | */ |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 23 | |
| 24 | using System; |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 25 | using Thrift.Protocol; |
| 26 | using Thrift.Transport; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 27 | using System.IO; |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 28 | |
| 29 | namespace Thrift.Server |
| 30 | { |
| 31 | public abstract class TServer |
| 32 | { |
| 33 | /** |
| 34 | * Core processor |
| 35 | */ |
| 36 | protected TProcessor processor; |
| 37 | |
| 38 | /** |
| 39 | * Server transport |
| 40 | */ |
| 41 | protected TServerTransport serverTransport; |
| 42 | |
| 43 | /** |
| 44 | * Input Transport Factory |
| 45 | */ |
| 46 | protected TTransportFactory inputTransportFactory; |
| 47 | |
| 48 | /** |
| 49 | * Output Transport Factory |
| 50 | */ |
| 51 | protected TTransportFactory outputTransportFactory; |
| 52 | |
| 53 | /** |
| 54 | * Input Protocol Factory |
| 55 | */ |
| 56 | protected TProtocolFactory inputProtocolFactory; |
| 57 | |
| 58 | /** |
| 59 | * Output Protocol Factory |
| 60 | */ |
| 61 | protected TProtocolFactory outputProtocolFactory; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 62 | public delegate void LogDelegate(string str); |
| 63 | protected LogDelegate logDelegate; |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * Default constructors. |
| 67 | */ |
| 68 | |
| 69 | public TServer(TProcessor processor, |
| 70 | TServerTransport serverTransport) |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 71 | :this(processor, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), DefaultLogDelegate) |
| 72 | { |
| 73 | } |
| 74 | |
| 75 | public TServer(TProcessor processor, |
| 76 | TServerTransport serverTransport, |
| 77 | LogDelegate logDelegate) |
| 78 | : 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] | 79 | { |
| 80 | } |
| 81 | |
| 82 | public TServer(TProcessor processor, |
| 83 | TServerTransport serverTransport, |
| 84 | TTransportFactory transportFactory) |
| 85 | :this(processor, |
| 86 | serverTransport, |
| 87 | transportFactory, |
| 88 | transportFactory, |
| 89 | new TBinaryProtocol.Factory(), |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 90 | new TBinaryProtocol.Factory(), |
| 91 | DefaultLogDelegate) |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 92 | { |
| 93 | } |
| 94 | |
| 95 | public TServer(TProcessor processor, |
| 96 | TServerTransport serverTransport, |
| 97 | TTransportFactory transportFactory, |
| 98 | TProtocolFactory protocolFactory) |
| 99 | :this(processor, |
| 100 | serverTransport, |
| 101 | transportFactory, |
| 102 | transportFactory, |
| 103 | protocolFactory, |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 104 | protocolFactory, |
| 105 | DefaultLogDelegate) |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 106 | { |
| 107 | } |
| 108 | |
| 109 | public TServer(TProcessor processor, |
| 110 | TServerTransport serverTransport, |
| 111 | TTransportFactory inputTransportFactory, |
| 112 | TTransportFactory outputTransportFactory, |
| 113 | TProtocolFactory inputProtocolFactory, |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 114 | TProtocolFactory outputProtocolFactory, |
| 115 | LogDelegate logDelegate) |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 116 | { |
| 117 | this.processor = processor; |
| 118 | this.serverTransport = serverTransport; |
| 119 | this.inputTransportFactory = inputTransportFactory; |
| 120 | this.outputTransportFactory = outputTransportFactory; |
| 121 | this.inputProtocolFactory = inputProtocolFactory; |
| 122 | this.outputProtocolFactory = outputProtocolFactory; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 123 | this.logDelegate = logDelegate; |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /** |
| 127 | * The run method fires up the server and gets things going. |
| 128 | */ |
| 129 | public abstract void Serve(); |
David Reiss | dc815f5 | 2008-03-02 00:58:04 +0000 | [diff] [blame] | 130 | |
| 131 | public abstract void Stop(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 132 | |
| 133 | protected static void DefaultLogDelegate(string s) |
| 134 | { |
| 135 | Console.Error.WriteLine(s); |
| 136 | } |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | |