blob: 7bf274725eda948f3fc018d6c34c60d484174583 [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;
David Reiss63191332009-01-06 19:49:22 +000062 public delegate void LogDelegate(string str);
63 protected LogDelegate logDelegate;
David Reiss7f42bcf2008-01-11 20:59:12 +000064
65 /**
66 * Default constructors.
67 */
68
69 public TServer(TProcessor processor,
70 TServerTransport serverTransport)
David Reiss63191332009-01-06 19:49:22 +000071 :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 Reiss7f42bcf2008-01-11 20:59:12 +000079 {
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 Reiss63191332009-01-06 19:49:22 +000090 new TBinaryProtocol.Factory(),
91 DefaultLogDelegate)
David Reiss7f42bcf2008-01-11 20:59:12 +000092 {
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 Reiss63191332009-01-06 19:49:22 +0000104 protocolFactory,
105 DefaultLogDelegate)
David Reiss7f42bcf2008-01-11 20:59:12 +0000106 {
107 }
108
109 public TServer(TProcessor processor,
110 TServerTransport serverTransport,
111 TTransportFactory inputTransportFactory,
112 TTransportFactory outputTransportFactory,
113 TProtocolFactory inputProtocolFactory,
David Reiss63191332009-01-06 19:49:22 +0000114 TProtocolFactory outputProtocolFactory,
115 LogDelegate logDelegate)
David Reiss7f42bcf2008-01-11 20:59:12 +0000116 {
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 Reiss63191332009-01-06 19:49:22 +0000123 this.logDelegate = logDelegate;
David Reiss7f42bcf2008-01-11 20:59:12 +0000124 }
125
126 /**
127 * The run method fires up the server and gets things going.
128 */
129 public abstract void Serve();
David Reissdc815f52008-03-02 00:58:04 +0000130
131 public abstract void Stop();
David Reiss63191332009-01-06 19:49:22 +0000132
133 protected static void DefaultLogDelegate(string s)
134 {
135 Console.Error.WriteLine(s);
136 }
David Reiss7f42bcf2008-01-11 20:59:12 +0000137 }
138}
139