blob: afb2b9f38e33121a8e4090a45159522d08c3c762 [file] [log] [blame]
David Reiss7f42bcf2008-01-11 20:59:12 +00001//
2// TServer.cs
3//
4// Begin: Dec 3, 2007
David Reiss0c90f6f2008-02-06 22:18:40 +00005// Authors:
David Reiss7f42bcf2008-01-11 20:59:12 +00006// Will Palmeri <wpalmeri@imeem.com>
7//
8// Distributed under the Thrift Software License
9//
10// See accompanying file LICENSE or visit the Thrift site at:
11// http://developers.facebook.com/thrift/using
12
13using System;
14using System.Collections.Generic;
15using Thrift.Protocol;
16using Thrift.Transport;
David Reiss63191332009-01-06 19:49:22 +000017using System.IO;
David Reiss7f42bcf2008-01-11 20:59:12 +000018
19namespace Thrift.Server
20{
21 public abstract class TServer
22 {
23 /**
24 * Core processor
25 */
26 protected TProcessor processor;
27
28 /**
29 * Server transport
30 */
31 protected TServerTransport serverTransport;
32
33 /**
34 * Input Transport Factory
35 */
36 protected TTransportFactory inputTransportFactory;
37
38 /**
39 * Output Transport Factory
40 */
41 protected TTransportFactory outputTransportFactory;
42
43 /**
44 * Input Protocol Factory
45 */
46 protected TProtocolFactory inputProtocolFactory;
47
48 /**
49 * Output Protocol Factory
50 */
51 protected TProtocolFactory outputProtocolFactory;
David Reiss63191332009-01-06 19:49:22 +000052 public delegate void LogDelegate(string str);
53 protected LogDelegate logDelegate;
David Reiss7f42bcf2008-01-11 20:59:12 +000054
55 /**
56 * Default constructors.
57 */
58
59 public TServer(TProcessor processor,
60 TServerTransport serverTransport)
David Reiss63191332009-01-06 19:49:22 +000061 :this(processor, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), DefaultLogDelegate)
62 {
63 }
64
65 public TServer(TProcessor processor,
66 TServerTransport serverTransport,
67 LogDelegate logDelegate)
68 : this(processor, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), DefaultLogDelegate)
David Reiss7f42bcf2008-01-11 20:59:12 +000069 {
70 }
71
72 public TServer(TProcessor processor,
73 TServerTransport serverTransport,
74 TTransportFactory transportFactory)
75 :this(processor,
76 serverTransport,
77 transportFactory,
78 transportFactory,
79 new TBinaryProtocol.Factory(),
David Reiss63191332009-01-06 19:49:22 +000080 new TBinaryProtocol.Factory(),
81 DefaultLogDelegate)
David Reiss7f42bcf2008-01-11 20:59:12 +000082 {
83 }
84
85 public TServer(TProcessor processor,
86 TServerTransport serverTransport,
87 TTransportFactory transportFactory,
88 TProtocolFactory protocolFactory)
89 :this(processor,
90 serverTransport,
91 transportFactory,
92 transportFactory,
93 protocolFactory,
David Reiss63191332009-01-06 19:49:22 +000094 protocolFactory,
95 DefaultLogDelegate)
David Reiss7f42bcf2008-01-11 20:59:12 +000096 {
97 }
98
99 public TServer(TProcessor processor,
100 TServerTransport serverTransport,
101 TTransportFactory inputTransportFactory,
102 TTransportFactory outputTransportFactory,
103 TProtocolFactory inputProtocolFactory,
David Reiss63191332009-01-06 19:49:22 +0000104 TProtocolFactory outputProtocolFactory,
105 LogDelegate logDelegate)
David Reiss7f42bcf2008-01-11 20:59:12 +0000106 {
107 this.processor = processor;
108 this.serverTransport = serverTransport;
109 this.inputTransportFactory = inputTransportFactory;
110 this.outputTransportFactory = outputTransportFactory;
111 this.inputProtocolFactory = inputProtocolFactory;
112 this.outputProtocolFactory = outputProtocolFactory;
David Reiss63191332009-01-06 19:49:22 +0000113 this.logDelegate = logDelegate;
David Reiss7f42bcf2008-01-11 20:59:12 +0000114 }
115
116 /**
117 * The run method fires up the server and gets things going.
118 */
119 public abstract void Serve();
David Reissdc815f52008-03-02 00:58:04 +0000120
121 public abstract void Stop();
David Reiss63191332009-01-06 19:49:22 +0000122
123 protected static void DefaultLogDelegate(string s)
124 {
125 Console.Error.WriteLine(s);
126 }
David Reiss7f42bcf2008-01-11 20:59:12 +0000127 }
128}
129