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