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 | { |
Randy Abernethy | 0e86f1f | 2014-07-13 09:50:19 -0700 | [diff] [blame] | 31 | public abstract class TServer |
| 32 | { |
| 33 | //Attributes |
| 34 | protected TProcessor processor; |
| 35 | protected TServerTransport serverTransport; |
| 36 | protected TTransportFactory inputTransportFactory; |
| 37 | protected TTransportFactory outputTransportFactory; |
| 38 | protected TProtocolFactory inputProtocolFactory; |
| 39 | protected TProtocolFactory outputProtocolFactory; |
| 40 | protected TServerEventHandler serverEventHandler = null; |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 41 | |
Randy Abernethy | 0e86f1f | 2014-07-13 09:50:19 -0700 | [diff] [blame] | 42 | //Methods |
| 43 | public void setEventHandler(TServerEventHandler seh) |
| 44 | { |
| 45 | serverEventHandler = seh; |
| 46 | } |
| 47 | public TServerEventHandler getEventHandler() |
| 48 | { |
| 49 | return serverEventHandler; |
| 50 | } |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 51 | |
Randy Abernethy | 0e86f1f | 2014-07-13 09:50:19 -0700 | [diff] [blame] | 52 | //Log delegation |
| 53 | public delegate void LogDelegate(string str); |
| 54 | private LogDelegate _logDelegate; |
| 55 | protected LogDelegate logDelegate |
| 56 | { |
| 57 | get { return _logDelegate; } |
| 58 | set { _logDelegate = (value != null) ? value : DefaultLogDelegate; } |
| 59 | } |
| 60 | protected static void DefaultLogDelegate(string s) |
| 61 | { |
| 62 | Console.Error.WriteLine(s); |
| 63 | } |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 64 | |
Randy Abernethy | 0e86f1f | 2014-07-13 09:50:19 -0700 | [diff] [blame] | 65 | //Construction |
| 66 | public TServer(TProcessor processor, |
| 67 | TServerTransport serverTransport) |
| 68 | : this(processor, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), DefaultLogDelegate) |
| 69 | { |
| 70 | } |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 71 | |
Randy Abernethy | 0e86f1f | 2014-07-13 09:50:19 -0700 | [diff] [blame] | 72 | public TServer(TProcessor processor, |
| 73 | TServerTransport serverTransport, |
| 74 | LogDelegate logDelegate) |
| 75 | : this(processor, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), DefaultLogDelegate) |
| 76 | { |
| 77 | } |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 78 | |
Randy Abernethy | 0e86f1f | 2014-07-13 09:50:19 -0700 | [diff] [blame] | 79 | public TServer(TProcessor processor, |
| 80 | TServerTransport serverTransport, |
| 81 | TTransportFactory transportFactory) |
| 82 | : this(processor, |
| 83 | serverTransport, |
| 84 | transportFactory, |
| 85 | transportFactory, |
| 86 | new TBinaryProtocol.Factory(), |
| 87 | new TBinaryProtocol.Factory(), |
| 88 | DefaultLogDelegate) |
| 89 | { |
| 90 | } |
Jens Geyer | d335acd | 2013-11-11 21:33:54 +0100 | [diff] [blame] | 91 | |
Randy Abernethy | 0e86f1f | 2014-07-13 09:50:19 -0700 | [diff] [blame] | 92 | public TServer(TProcessor processor, |
| 93 | TServerTransport serverTransport, |
| 94 | TTransportFactory transportFactory, |
| 95 | TProtocolFactory protocolFactory) |
| 96 | : this(processor, |
| 97 | serverTransport, |
| 98 | transportFactory, |
| 99 | transportFactory, |
| 100 | protocolFactory, |
| 101 | protocolFactory, |
| 102 | DefaultLogDelegate) |
| 103 | { |
| 104 | } |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 105 | |
Randy Abernethy | 0e86f1f | 2014-07-13 09:50:19 -0700 | [diff] [blame] | 106 | public TServer(TProcessor processor, |
| 107 | TServerTransport serverTransport, |
| 108 | TTransportFactory inputTransportFactory, |
| 109 | TTransportFactory outputTransportFactory, |
| 110 | TProtocolFactory inputProtocolFactory, |
| 111 | TProtocolFactory outputProtocolFactory, |
| 112 | LogDelegate logDelegate) |
| 113 | { |
| 114 | this.processor = processor; |
| 115 | this.serverTransport = serverTransport; |
| 116 | this.inputTransportFactory = inputTransportFactory; |
| 117 | this.outputTransportFactory = outputTransportFactory; |
| 118 | this.inputProtocolFactory = inputProtocolFactory; |
| 119 | this.outputProtocolFactory = outputProtocolFactory; |
| 120 | this.logDelegate = (logDelegate != null) ? logDelegate : DefaultLogDelegate; |
| 121 | } |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 122 | |
Randy Abernethy | 0e86f1f | 2014-07-13 09:50:19 -0700 | [diff] [blame] | 123 | //Abstract Interface |
| 124 | public abstract void Serve(); |
| 125 | public abstract void Stop(); |
| 126 | } |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 127 | } |