| 30 |
ashish |
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 |
/**
|
|
|
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;
|
|
|
62 |
public delegate void LogDelegate(string str);
|
|
|
63 |
protected LogDelegate logDelegate;
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* Default constructors.
|
|
|
67 |
*/
|
|
|
68 |
|
|
|
69 |
public TServer(TProcessor processor,
|
|
|
70 |
TServerTransport serverTransport)
|
|
|
71 |
: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)
|
|
|
79 |
{
|
|
|
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(),
|
|
|
90 |
new TBinaryProtocol.Factory(),
|
|
|
91 |
DefaultLogDelegate)
|
|
|
92 |
{
|
|
|
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,
|
|
|
104 |
protocolFactory,
|
|
|
105 |
DefaultLogDelegate)
|
|
|
106 |
{
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
public TServer(TProcessor processor,
|
|
|
110 |
TServerTransport serverTransport,
|
|
|
111 |
TTransportFactory inputTransportFactory,
|
|
|
112 |
TTransportFactory outputTransportFactory,
|
|
|
113 |
TProtocolFactory inputProtocolFactory,
|
|
|
114 |
TProtocolFactory outputProtocolFactory,
|
|
|
115 |
LogDelegate logDelegate)
|
|
|
116 |
{
|
|
|
117 |
this.processor = processor;
|
|
|
118 |
this.serverTransport = serverTransport;
|
|
|
119 |
this.inputTransportFactory = inputTransportFactory;
|
|
|
120 |
this.outputTransportFactory = outputTransportFactory;
|
|
|
121 |
this.inputProtocolFactory = inputProtocolFactory;
|
|
|
122 |
this.outputProtocolFactory = outputProtocolFactory;
|
|
|
123 |
this.logDelegate = logDelegate;
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
/**
|
|
|
127 |
* The run method fires up the server and gets things going.
|
|
|
128 |
*/
|
|
|
129 |
public abstract void Serve();
|
|
|
130 |
|
|
|
131 |
public abstract void Stop();
|
|
|
132 |
|
|
|
133 |
protected static void DefaultLogDelegate(string s)
|
|
|
134 |
{
|
|
|
135 |
Console.Error.WriteLine(s);
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
}
|
|
|
139 |
|