blob: 271b0c4c4298c0e662fc7e2ae122d51ce5de67fe [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{
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;
Jens Geyerd335acd2013-11-11 21:33:54 +010062
Jens Geyer1c99e702014-03-17 22:50:39 +020063 public delegate void LogDelegate(string str);
64 private LogDelegate _logDelegate;
65 protected LogDelegate logDelegate
66 {
67 get { return _logDelegate; }
Jens Geyerd335acd2013-11-11 21:33:54 +010068 set { _logDelegate = (value != null) ? value : DefaultLogDelegate; }
69 }
David Reiss7f42bcf2008-01-11 20:59:12 +000070
71 /**
72 * Default constructors.
73 */
74
75 public TServer(TProcessor processor,
76 TServerTransport serverTransport)
David Reiss63191332009-01-06 19:49:22 +000077 :this(processor, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), DefaultLogDelegate)
78 {
79 }
80
81 public TServer(TProcessor processor,
82 TServerTransport serverTransport,
83 LogDelegate logDelegate)
84 : this(processor, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), DefaultLogDelegate)
David Reiss7f42bcf2008-01-11 20:59:12 +000085 {
86 }
87
88 public TServer(TProcessor processor,
89 TServerTransport serverTransport,
90 TTransportFactory transportFactory)
91 :this(processor,
92 serverTransport,
93 transportFactory,
94 transportFactory,
95 new TBinaryProtocol.Factory(),
David Reiss63191332009-01-06 19:49:22 +000096 new TBinaryProtocol.Factory(),
97 DefaultLogDelegate)
David Reiss7f42bcf2008-01-11 20:59:12 +000098 {
99 }
100
101 public TServer(TProcessor processor,
102 TServerTransport serverTransport,
103 TTransportFactory transportFactory,
104 TProtocolFactory protocolFactory)
105 :this(processor,
106 serverTransport,
107 transportFactory,
108 transportFactory,
109 protocolFactory,
David Reiss63191332009-01-06 19:49:22 +0000110 protocolFactory,
111 DefaultLogDelegate)
David Reiss7f42bcf2008-01-11 20:59:12 +0000112 {
113 }
114
115 public TServer(TProcessor processor,
116 TServerTransport serverTransport,
117 TTransportFactory inputTransportFactory,
118 TTransportFactory outputTransportFactory,
119 TProtocolFactory inputProtocolFactory,
David Reiss63191332009-01-06 19:49:22 +0000120 TProtocolFactory outputProtocolFactory,
121 LogDelegate logDelegate)
David Reiss7f42bcf2008-01-11 20:59:12 +0000122 {
123 this.processor = processor;
124 this.serverTransport = serverTransport;
125 this.inputTransportFactory = inputTransportFactory;
126 this.outputTransportFactory = outputTransportFactory;
127 this.inputProtocolFactory = inputProtocolFactory;
128 this.outputProtocolFactory = outputProtocolFactory;
Jens Geyerd335acd2013-11-11 21:33:54 +0100129 this.logDelegate = (logDelegate != null) ? logDelegate : DefaultLogDelegate;
David Reiss7f42bcf2008-01-11 20:59:12 +0000130 }
131
132 /**
133 * The run method fires up the server and gets things going.
134 */
135 public abstract void Serve();
David Reissdc815f52008-03-02 00:58:04 +0000136
137 public abstract void Stop();
David Reiss63191332009-01-06 19:49:22 +0000138
139 protected static void DefaultLogDelegate(string s)
140 {
141 Console.Error.WriteLine(s);
142 }
David Reiss7f42bcf2008-01-11 20:59:12 +0000143 }
144}
145