blob: 61a9416fc9a0146689cedeb1f7b6ac038e286945 [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.
18 */
David Reiss7f42bcf2008-01-11 20:59:12 +000019
20using System;
David Reiss7f42bcf2008-01-11 20:59:12 +000021using Thrift.Protocol;
22using Thrift.Transport;
David Reiss63191332009-01-06 19:49:22 +000023using System.IO;
David Reiss7f42bcf2008-01-11 20:59:12 +000024
25namespace Thrift.Server
26{
27 public abstract class TServer
28 {
29 /**
30 * Core processor
31 */
32 protected TProcessor processor;
33
34 /**
35 * Server transport
36 */
37 protected TServerTransport serverTransport;
38
39 /**
40 * Input Transport Factory
41 */
42 protected TTransportFactory inputTransportFactory;
43
44 /**
45 * Output Transport Factory
46 */
47 protected TTransportFactory outputTransportFactory;
48
49 /**
50 * Input Protocol Factory
51 */
52 protected TProtocolFactory inputProtocolFactory;
53
54 /**
55 * Output Protocol Factory
56 */
57 protected TProtocolFactory outputProtocolFactory;
David Reiss63191332009-01-06 19:49:22 +000058 public delegate void LogDelegate(string str);
59 protected LogDelegate logDelegate;
David Reiss7f42bcf2008-01-11 20:59:12 +000060
61 /**
62 * Default constructors.
63 */
64
65 public TServer(TProcessor processor,
66 TServerTransport serverTransport)
David Reiss63191332009-01-06 19:49:22 +000067 :this(processor, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), DefaultLogDelegate)
68 {
69 }
70
71 public TServer(TProcessor processor,
72 TServerTransport serverTransport,
73 LogDelegate logDelegate)
74 : this(processor, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), DefaultLogDelegate)
David Reiss7f42bcf2008-01-11 20:59:12 +000075 {
76 }
77
78 public TServer(TProcessor processor,
79 TServerTransport serverTransport,
80 TTransportFactory transportFactory)
81 :this(processor,
82 serverTransport,
83 transportFactory,
84 transportFactory,
85 new TBinaryProtocol.Factory(),
David Reiss63191332009-01-06 19:49:22 +000086 new TBinaryProtocol.Factory(),
87 DefaultLogDelegate)
David Reiss7f42bcf2008-01-11 20:59:12 +000088 {
89 }
90
91 public TServer(TProcessor processor,
92 TServerTransport serverTransport,
93 TTransportFactory transportFactory,
94 TProtocolFactory protocolFactory)
95 :this(processor,
96 serverTransport,
97 transportFactory,
98 transportFactory,
99 protocolFactory,
David Reiss63191332009-01-06 19:49:22 +0000100 protocolFactory,
101 DefaultLogDelegate)
David Reiss7f42bcf2008-01-11 20:59:12 +0000102 {
103 }
104
105 public TServer(TProcessor processor,
106 TServerTransport serverTransport,
107 TTransportFactory inputTransportFactory,
108 TTransportFactory outputTransportFactory,
109 TProtocolFactory inputProtocolFactory,
David Reiss63191332009-01-06 19:49:22 +0000110 TProtocolFactory outputProtocolFactory,
111 LogDelegate logDelegate)
David Reiss7f42bcf2008-01-11 20:59:12 +0000112 {
113 this.processor = processor;
114 this.serverTransport = serverTransport;
115 this.inputTransportFactory = inputTransportFactory;
116 this.outputTransportFactory = outputTransportFactory;
117 this.inputProtocolFactory = inputProtocolFactory;
118 this.outputProtocolFactory = outputProtocolFactory;
David Reiss63191332009-01-06 19:49:22 +0000119 this.logDelegate = logDelegate;
David Reiss7f42bcf2008-01-11 20:59:12 +0000120 }
121
122 /**
123 * The run method fires up the server and gets things going.
124 */
125 public abstract void Serve();
David Reissdc815f52008-03-02 00:58:04 +0000126
127 public abstract void Stop();
David Reiss63191332009-01-06 19:49:22 +0000128
129 protected static void DefaultLogDelegate(string s)
130 {
131 Console.Error.WriteLine(s);
132 }
David Reiss7f42bcf2008-01-11 20:59:12 +0000133 }
134}
135