]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
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 | * | |
19 | * Contains some contributions under the Thrift Software License. | |
20 | * Please see doc/old-thrift-license.txt in the Thrift distribution for | |
21 | * details. | |
22 | */ | |
23 | ||
24 | using System; | |
25 | using Thrift.Protocol; | |
26 | using Thrift.Transport; | |
27 | using System.IO; | |
28 | ||
29 | namespace Thrift.Server | |
30 | { | |
31 | public abstract class TServer | |
32 | { | |
33 | //Attributes | |
34 | protected TProcessorFactory processorFactory; | |
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; | |
41 | ||
42 | //Methods | |
43 | public void setEventHandler(TServerEventHandler seh) | |
44 | { | |
45 | serverEventHandler = seh; | |
46 | } | |
47 | public TServerEventHandler getEventHandler() | |
48 | { | |
49 | return serverEventHandler; | |
50 | } | |
51 | ||
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 | } | |
64 | ||
65 | //Construction | |
66 | public TServer(TProcessor processor, | |
67 | TServerTransport serverTransport) | |
68 | : this(processor, serverTransport, | |
69 | new TTransportFactory(), | |
70 | new TTransportFactory(), | |
71 | new TBinaryProtocol.Factory(), | |
72 | new TBinaryProtocol.Factory(), | |
73 | DefaultLogDelegate) | |
74 | { | |
75 | } | |
76 | ||
77 | public TServer(TProcessor processor, | |
78 | TServerTransport serverTransport, | |
79 | LogDelegate logDelegate) | |
80 | : this(processor, | |
81 | serverTransport, | |
82 | new TTransportFactory(), | |
83 | new TTransportFactory(), | |
84 | new TBinaryProtocol.Factory(), | |
85 | new TBinaryProtocol.Factory(), | |
86 | logDelegate) | |
87 | { | |
88 | } | |
89 | ||
90 | public TServer(TProcessor processor, | |
91 | TServerTransport serverTransport, | |
92 | TTransportFactory transportFactory) | |
93 | : this(processor, | |
94 | serverTransport, | |
95 | transportFactory, | |
96 | transportFactory, | |
97 | new TBinaryProtocol.Factory(), | |
98 | new TBinaryProtocol.Factory(), | |
99 | DefaultLogDelegate) | |
100 | { | |
101 | } | |
102 | ||
103 | public TServer(TProcessor processor, | |
104 | TServerTransport serverTransport, | |
105 | TTransportFactory transportFactory, | |
106 | TProtocolFactory protocolFactory) | |
107 | : this(processor, | |
108 | serverTransport, | |
109 | transportFactory, | |
110 | transportFactory, | |
111 | protocolFactory, | |
112 | protocolFactory, | |
113 | DefaultLogDelegate) | |
114 | { | |
115 | } | |
116 | ||
117 | public TServer(TProcessor processor, | |
118 | TServerTransport serverTransport, | |
119 | TTransportFactory inputTransportFactory, | |
120 | TTransportFactory outputTransportFactory, | |
121 | TProtocolFactory inputProtocolFactory, | |
122 | TProtocolFactory outputProtocolFactory, | |
123 | LogDelegate logDelegate) | |
124 | { | |
125 | this.processorFactory = new TSingletonProcessorFactory(processor); | |
126 | this.serverTransport = serverTransport; | |
127 | this.inputTransportFactory = inputTransportFactory; | |
128 | this.outputTransportFactory = outputTransportFactory; | |
129 | this.inputProtocolFactory = inputProtocolFactory; | |
130 | this.outputProtocolFactory = outputProtocolFactory; | |
131 | this.logDelegate = (logDelegate != null) ? logDelegate : DefaultLogDelegate; | |
132 | } | |
133 | ||
134 | public TServer(TProcessorFactory processorFactory, | |
135 | TServerTransport serverTransport, | |
136 | TTransportFactory inputTransportFactory, | |
137 | TTransportFactory outputTransportFactory, | |
138 | TProtocolFactory inputProtocolFactory, | |
139 | TProtocolFactory outputProtocolFactory, | |
140 | LogDelegate logDelegate) | |
141 | { | |
142 | this.processorFactory = processorFactory; | |
143 | this.serverTransport = serverTransport; | |
144 | this.inputTransportFactory = inputTransportFactory; | |
145 | this.outputTransportFactory = outputTransportFactory; | |
146 | this.inputProtocolFactory = inputProtocolFactory; | |
147 | this.outputProtocolFactory = outputProtocolFactory; | |
148 | this.logDelegate = (logDelegate != null) ? logDelegate : DefaultLogDelegate; | |
149 | } | |
150 | ||
151 | //Abstract Interface | |
152 | public abstract void Serve(); | |
153 | public abstract void Stop(); | |
154 | } | |
155 | } |