blob: a2631a96bda579d82223afeee2f640485497a7c4 [file] [log] [blame]
Kevin Clarkab4460d2009-03-20 02:28:41 +00001/**
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 Lipcon53ae9f32009-12-07 00:42:38 +000018 *
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 Clarkab4460d2009-03-20 02:28:41 +000022 */
David Reiss7f42bcf2008-01-11 20:59:12 +000023
24using System;
David Reiss7f42bcf2008-01-11 20:59:12 +000025using Thrift.Protocol;
26using Thrift.Transport;
David Reiss63191332009-01-06 19:49:22 +000027using System.IO;
David Reiss7f42bcf2008-01-11 20:59:12 +000028
29namespace Thrift.Server
30{
Randy Abernethy0e86f1f2014-07-13 09:50:19 -070031 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 Reiss7f42bcf2008-01-11 20:59:12 +000041
Randy Abernethy0e86f1f2014-07-13 09:50:19 -070042 //Methods
43 public void setEventHandler(TServerEventHandler seh)
44 {
45 serverEventHandler = seh;
46 }
47 public TServerEventHandler getEventHandler()
48 {
49 return serverEventHandler;
50 }
David Reiss7f42bcf2008-01-11 20:59:12 +000051
Randy Abernethy0e86f1f2014-07-13 09:50:19 -070052 //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 Reiss7f42bcf2008-01-11 20:59:12 +000064
Randy Abernethy0e86f1f2014-07-13 09:50:19 -070065 //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 Reiss7f42bcf2008-01-11 20:59:12 +000071
Randy Abernethy0e86f1f2014-07-13 09:50:19 -070072 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 Reiss7f42bcf2008-01-11 20:59:12 +000078
Randy Abernethy0e86f1f2014-07-13 09:50:19 -070079 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 Geyerd335acd2013-11-11 21:33:54 +010091
Randy Abernethy0e86f1f2014-07-13 09:50:19 -070092 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 Reiss7f42bcf2008-01-11 20:59:12 +0000105
Randy Abernethy0e86f1f2014-07-13 09:50:19 -0700106 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 Reiss7f42bcf2008-01-11 20:59:12 +0000122
Randy Abernethy0e86f1f2014-07-13 09:50:19 -0700123 //Abstract Interface
124 public abstract void Serve();
125 public abstract void Stop();
126 }
David Reiss7f42bcf2008-01-11 20:59:12 +0000127}