blob: d6063ac3290b8b4a4423bae77e5b5eb7b5f6d02d [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +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 */
19
Marc Slemko6be374b2006-08-04 03:16:25 +000020#include <concurrency/ThreadManager.h>
21#include <concurrency/PosixThreadFactory.h>
22#include <protocol/TBinaryProtocol.h>
23#include <server/TSimpleServer.h>
Mark Slee0c2dff32007-03-09 19:26:57 +000024#include <server/TThreadedServer.h>
Marc Slemko6be374b2006-08-04 03:16:25 +000025#include <server/TThreadPoolServer.h>
Mark Sleeb9acf982006-10-10 01:57:32 +000026#include <server/TNonblockingServer.h>
Marc Slemko6be374b2006-08-04 03:16:25 +000027#include <transport/TServerSocket.h>
Mark Sleea3302652006-10-25 19:03:32 +000028#include <transport/TTransportUtils.h>
Mark Slee95771002006-06-07 06:53:25 +000029#include "ThriftTest.h"
Marc Slemko6be374b2006-08-04 03:16:25 +000030
31#include <iostream>
32#include <stdexcept>
33#include <sstream>
34
David Reissbc3dddb2007-08-22 23:20:24 +000035#define __STDC_FORMAT_MACROS
36#include <inttypes.h>
37
Mark Sleee8540632006-05-30 09:24:40 +000038using namespace std;
Mark Slee0c2dff32007-03-09 19:26:57 +000039using namespace boost;
Mark Sleee8540632006-05-30 09:24:40 +000040
T Jake Lucianib5e62212009-01-31 22:36:20 +000041using namespace apache::thrift;
42using namespace apache::thrift::concurrency;
43using namespace apache::thrift::protocol;
44using namespace apache::thrift::transport;
45using namespace apache::thrift::server;
Marc Slemko6be374b2006-08-04 03:16:25 +000046
Marc Slemkobf4fd192006-08-15 21:29:39 +000047using namespace thrift::test;
48
Mark Sleed2655522006-09-05 22:09:57 +000049class TestHandler : public ThriftTestIf {
Mark Sleee8540632006-05-30 09:24:40 +000050 public:
Mark Sleed2655522006-09-05 22:09:57 +000051 TestHandler() {}
Mark Sleee8540632006-05-30 09:24:40 +000052
53 void testVoid() {
54 printf("testVoid()\n");
55 }
56
Mark Slee1921d202007-01-24 19:43:06 +000057 void testString(string& out, const string &thing) {
Mark Sleee8540632006-05-30 09:24:40 +000058 printf("testString(\"%s\")\n", thing.c_str());
Mark Slee1921d202007-01-24 19:43:06 +000059 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +000060 }
61
Mark Slee1921d202007-01-24 19:43:06 +000062 int8_t testByte(const int8_t thing) {
Mark Sleee8540632006-05-30 09:24:40 +000063 printf("testByte(%d)\n", (int)thing);
64 return thing;
65 }
66
Mark Slee1921d202007-01-24 19:43:06 +000067 int32_t testI32(const int32_t thing) {
Mark Sleee8540632006-05-30 09:24:40 +000068 printf("testI32(%d)\n", thing);
69 return thing;
70 }
71
Mark Slee1921d202007-01-24 19:43:06 +000072 int64_t testI64(const int64_t thing) {
David Reissbc3dddb2007-08-22 23:20:24 +000073 printf("testI64(%"PRId64")\n", thing);
Mark Sleee8540632006-05-30 09:24:40 +000074 return thing;
75 }
76
Mark Slee1921d202007-01-24 19:43:06 +000077 double testDouble(const double thing) {
Mark Sleec98d0502006-09-06 02:42:25 +000078 printf("testDouble(%lf)\n", thing);
79 return thing;
80 }
81
Mark Slee1921d202007-01-24 19:43:06 +000082 void testStruct(Xtruct& out, const Xtruct &thing) {
David Reissbc3dddb2007-08-22 23:20:24 +000083 printf("testStruct({\"%s\", %d, %d, %"PRId64"})\n", thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing);
Mark Slee1921d202007-01-24 19:43:06 +000084 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +000085 }
86
Mark Slee1921d202007-01-24 19:43:06 +000087 void testNest(Xtruct2& out, const Xtruct2& nest) {
88 const Xtruct &thing = nest.struct_thing;
David Reissbc3dddb2007-08-22 23:20:24 +000089 printf("testNest({%d, {\"%s\", %d, %d, %"PRId64"}, %d})\n", (int)nest.byte_thing, thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing, nest.i32_thing);
Mark Slee1921d202007-01-24 19:43:06 +000090 out = nest;
Mark Sleee8540632006-05-30 09:24:40 +000091 }
92
Mark Slee1921d202007-01-24 19:43:06 +000093 void testMap(map<int32_t, int32_t> &out, const map<int32_t, int32_t> &thing) {
Mark Sleee8540632006-05-30 09:24:40 +000094 printf("testMap({");
95 map<int32_t, int32_t>::const_iterator m_iter;
96 bool first = true;
97 for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) {
98 if (first) {
99 first = false;
100 } else {
101 printf(", ");
102 }
103 printf("%d => %d", m_iter->first, m_iter->second);
104 }
105 printf("})\n");
Mark Slee1921d202007-01-24 19:43:06 +0000106 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +0000107 }
108
Mark Slee1921d202007-01-24 19:43:06 +0000109 void testSet(set<int32_t> &out, const set<int32_t> &thing) {
Mark Sleee8540632006-05-30 09:24:40 +0000110 printf("testSet({");
111 set<int32_t>::const_iterator s_iter;
112 bool first = true;
113 for (s_iter = thing.begin(); s_iter != thing.end(); ++s_iter) {
114 if (first) {
115 first = false;
116 } else {
117 printf(", ");
118 }
119 printf("%d", *s_iter);
120 }
121 printf("})\n");
Mark Slee1921d202007-01-24 19:43:06 +0000122 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +0000123 }
124
Mark Slee1921d202007-01-24 19:43:06 +0000125 void testList(vector<int32_t> &out, const vector<int32_t> &thing) {
Mark Sleee8540632006-05-30 09:24:40 +0000126 printf("testList({");
Mark Sleeb9acf982006-10-10 01:57:32 +0000127 vector<int32_t>::const_iterator l_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000128 bool first = true;
129 for (l_iter = thing.begin(); l_iter != thing.end(); ++l_iter) {
130 if (first) {
131 first = false;
132 } else {
133 printf(", ");
134 }
135 printf("%d", *l_iter);
136 }
137 printf("})\n");
Mark Slee1921d202007-01-24 19:43:06 +0000138 out = thing;
Mark Sleee8540632006-05-30 09:24:40 +0000139 }
140
Bryan Duxbury833ae492010-09-27 17:26:02 +0000141 Numberz::type testEnum(const Numberz::type thing) {
Mark Sleee8540632006-05-30 09:24:40 +0000142 printf("testEnum(%d)\n", thing);
143 return thing;
144 }
145
Mark Slee1921d202007-01-24 19:43:06 +0000146 UserId testTypedef(const UserId thing) {
David Reissbc3dddb2007-08-22 23:20:24 +0000147 printf("testTypedef(%"PRId64")\n", thing);
Mark Sleee8540632006-05-30 09:24:40 +0000148 return thing;
149 }
150
Mark Slee1921d202007-01-24 19:43:06 +0000151 void testMapMap(map<int32_t, map<int32_t,int32_t> > &mapmap, const int32_t hello) {
Mark Sleee8540632006-05-30 09:24:40 +0000152 printf("testMapMap(%d)\n", hello);
Mark Sleee8540632006-05-30 09:24:40 +0000153
154 map<int32_t,int32_t> pos;
155 map<int32_t,int32_t> neg;
156 for (int i = 1; i < 5; i++) {
157 pos.insert(make_pair(i,i));
158 neg.insert(make_pair(-i,-i));
159 }
160
161 mapmap.insert(make_pair(4, pos));
162 mapmap.insert(make_pair(-4, neg));
163
Mark Sleee8540632006-05-30 09:24:40 +0000164 }
165
Bryan Duxbury833ae492010-09-27 17:26:02 +0000166 void testInsanity(map<UserId, map<Numberz::type,Insanity> > &insane, const Insanity &argument) {
Mark Sleee8540632006-05-30 09:24:40 +0000167 printf("testInsanity()\n");
David Reiss0c90f6f2008-02-06 22:18:40 +0000168
Mark Sleee8540632006-05-30 09:24:40 +0000169 Xtruct hello;
170 hello.string_thing = "Hello2";
171 hello.byte_thing = 2;
Mark Sleee8540632006-05-30 09:24:40 +0000172 hello.i32_thing = 2;
Mark Sleee8540632006-05-30 09:24:40 +0000173 hello.i64_thing = 2;
174
175 Xtruct goodbye;
176 goodbye.string_thing = "Goodbye4";
177 goodbye.byte_thing = 4;
Mark Sleee8540632006-05-30 09:24:40 +0000178 goodbye.i32_thing = 4;
Mark Sleee8540632006-05-30 09:24:40 +0000179 goodbye.i64_thing = 4;
180
181 Insanity crazy;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000182 crazy.userMap.insert(make_pair(Numberz::EIGHT, 8));
Mark Sleee8540632006-05-30 09:24:40 +0000183 crazy.xtructs.push_back(goodbye);
184
185 Insanity looney;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000186 crazy.userMap.insert(make_pair(Numberz::FIVE, 5));
Mark Sleee8540632006-05-30 09:24:40 +0000187 crazy.xtructs.push_back(hello);
188
Bryan Duxbury833ae492010-09-27 17:26:02 +0000189 map<Numberz::type, Insanity> first_map;
190 map<Numberz::type, Insanity> second_map;
Mark Sleee8540632006-05-30 09:24:40 +0000191
Bryan Duxbury833ae492010-09-27 17:26:02 +0000192 first_map.insert(make_pair(Numberz::TWO, crazy));
193 first_map.insert(make_pair(Numberz::THREE, crazy));
Mark Sleee8540632006-05-30 09:24:40 +0000194
Bryan Duxbury833ae492010-09-27 17:26:02 +0000195 second_map.insert(make_pair(Numberz::SIX, looney));
Mark Sleee8540632006-05-30 09:24:40 +0000196
Mark Sleee8540632006-05-30 09:24:40 +0000197 insane.insert(make_pair(1, first_map));
198 insane.insert(make_pair(2, second_map));
199
200 printf("return");
201 printf(" = {");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000202 map<UserId, map<Numberz::type,Insanity> >::const_iterator i_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000203 for (i_iter = insane.begin(); i_iter != insane.end(); ++i_iter) {
David Reissbc3dddb2007-08-22 23:20:24 +0000204 printf("%"PRId64" => {", i_iter->first);
Bryan Duxbury833ae492010-09-27 17:26:02 +0000205 map<Numberz::type,Insanity>::const_iterator i2_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000206 for (i2_iter = i_iter->second.begin();
207 i2_iter != i_iter->second.end();
208 ++i2_iter) {
209 printf("%d => {", i2_iter->first);
Bryan Duxbury833ae492010-09-27 17:26:02 +0000210 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
211 map<Numberz::type, UserId>::const_iterator um;
Mark Sleee8540632006-05-30 09:24:40 +0000212 printf("{");
213 for (um = userMap.begin(); um != userMap.end(); ++um) {
David Reissbc3dddb2007-08-22 23:20:24 +0000214 printf("%d => %"PRId64", ", um->first, um->second);
Mark Sleee8540632006-05-30 09:24:40 +0000215 }
216 printf("}, ");
217
Mark Sleeb9acf982006-10-10 01:57:32 +0000218 vector<Xtruct> xtructs = i2_iter->second.xtructs;
219 vector<Xtruct>::const_iterator x;
Mark Sleee8540632006-05-30 09:24:40 +0000220 printf("{");
221 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
David Reissbc3dddb2007-08-22 23:20:24 +0000222 printf("{\"%s\", %d, %d, %"PRId64"}, ", x->string_thing.c_str(), (int)x->byte_thing, x->i32_thing, x->i64_thing);
Mark Sleee8540632006-05-30 09:24:40 +0000223 }
224 printf("}");
225
226 printf("}, ");
227 }
228 printf("}, ");
229 }
230 printf("}\n");
231
David Reiss0c90f6f2008-02-06 22:18:40 +0000232
Mark Sleee8540632006-05-30 09:24:40 +0000233 }
Marc Slemkoe6889de2006-08-12 00:32:53 +0000234
Bryan Duxbury833ae492010-09-27 17:26:02 +0000235 void testMulti(Xtruct &hello, const int8_t arg0, const int32_t arg1, const int64_t arg2, const std::map<int16_t, std::string> &arg3, const Numberz::type arg4, const UserId arg5) {
Marc Slemkoe6889de2006-08-12 00:32:53 +0000236 printf("testMulti()\n");
David Reiss0c90f6f2008-02-06 22:18:40 +0000237
Marc Slemkoe6889de2006-08-12 00:32:53 +0000238 hello.string_thing = "Hello2";
239 hello.byte_thing = arg0;
240 hello.i32_thing = arg1;
241 hello.i64_thing = (int64_t)arg2;
Marc Slemkoe6889de2006-08-12 00:32:53 +0000242 }
Marc Slemkobf4fd192006-08-15 21:29:39 +0000243
David Reiss55ff70f2008-06-11 00:58:25 +0000244 void testException(const std::string &arg)
T Jake Lucianib5e62212009-01-31 22:36:20 +0000245 throw(Xception, apache::thrift::TException)
David Reiss55ff70f2008-06-11 00:58:25 +0000246 {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000247 printf("testException(%s)\n", arg.c_str());
Mark Sleed3d733a2006-09-01 22:19:06 +0000248 if (arg.compare("Xception") == 0) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000249 Xception e;
250 e.errorCode = 1001;
David Reiss9813cbe2009-01-31 21:39:11 +0000251 e.message = arg;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000252 throw e;
David Reiss55ff70f2008-06-11 00:58:25 +0000253 } else if (arg.compare("ApplicationException") == 0) {
T Jake Lucianib5e62212009-01-31 22:36:20 +0000254 apache::thrift::TException e;
David Reiss55ff70f2008-06-11 00:58:25 +0000255 throw e;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000256 } else {
257 Xtruct result;
258 result.string_thing = arg;
259 return;
260 }
261 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000262
Mark Slee1921d202007-01-24 19:43:06 +0000263 void testMultiException(Xtruct &result, const std::string &arg0, const std::string &arg1) throw(Xception, Xception2) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000264
Marc Slemko71d4e472006-08-15 22:34:04 +0000265 printf("testMultiException(%s, %s)\n", arg0.c_str(), arg1.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +0000266
Mark Sleef5f2be42006-09-05 21:05:31 +0000267 if (arg0.compare("Xception") == 0) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000268 Xception e;
269 e.errorCode = 1001;
270 e.message = "This is an Xception";
271 throw e;
Mark Sleef5f2be42006-09-05 21:05:31 +0000272 } else if (arg0.compare("Xception2") == 0) {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000273 Xception2 e;
274 e.errorCode = 2002;
275 e.struct_thing.string_thing = "This is an Xception2";
276 throw e;
277 } else {
Marc Slemkobf4fd192006-08-15 21:29:39 +0000278 result.string_thing = arg1;
Mark Slee1921d202007-01-24 19:43:06 +0000279 return;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000280 }
281 }
David Reiss2ab6fe82008-02-18 02:11:44 +0000282
David Reiss6ce401d2009-03-24 20:01:58 +0000283 void testOneway(int sleepFor) {
284 printf("testOneway(%d): Sleeping...\n", sleepFor);
David Reiss2ab6fe82008-02-18 02:11:44 +0000285 sleep(sleepFor);
David Reiss6ce401d2009-03-24 20:01:58 +0000286 printf("testOneway(%d): done sleeping!\n", sleepFor);
David Reiss2ab6fe82008-02-18 02:11:44 +0000287 }
Mark Sleee8540632006-05-30 09:24:40 +0000288};
289
290int main(int argc, char **argv) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000291
Mark Sleee8540632006-05-30 09:24:40 +0000292 int port = 9090;
Marc Slemko6be374b2006-08-04 03:16:25 +0000293 string serverType = "simple";
294 string protocolType = "binary";
295 size_t workerCount = 4;
296
297 ostringstream usage;
298
299 usage <<
300 argv[0] << " [--port=<port number>] [--server-type=<server-type>] [--protocol-type=<protocol-type>] [--workers=<worker-count>]" << endl <<
301
Mark Slee0c2dff32007-03-09 19:26:57 +0000302 "\t\tserver-type\t\ttype of server, \"simple\", \"thread-pool\", \"threaded\", or \"nonblocking\". Default is " << serverType << endl <<
Marc Slemko6be374b2006-08-04 03:16:25 +0000303
304 "\t\tprotocol-type\t\ttype of protocol, \"binary\", \"ascii\", or \"xml\". Default is " << protocolType << endl <<
305
306 "\t\tworkers\t\tNumber of thread pools workers. Only valid for thread-pool server type. Default is " << workerCount << endl;
David Reiss0c90f6f2008-02-06 22:18:40 +0000307
Marc Slemko6be374b2006-08-04 03:16:25 +0000308 map<string, string> args;
David Reiss0c90f6f2008-02-06 22:18:40 +0000309
Mark Sleef5f2be42006-09-05 21:05:31 +0000310 for (int ix = 1; ix < argc; ix++) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000311 string arg(argv[ix]);
Mark Sleef5f2be42006-09-05 21:05:31 +0000312 if (arg.compare(0,2, "--") == 0) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000313 size_t end = arg.find_first_of("=", 2);
Mark Sleef5f2be42006-09-05 21:05:31 +0000314 if (end != string::npos) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000315 args[string(arg, 2, end - 2)] = string(arg, end + 1);
316 } else {
Mark Sleea3302652006-10-25 19:03:32 +0000317 args[string(arg, 2)] = "true";
Marc Slemko6be374b2006-08-04 03:16:25 +0000318 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000319 } else {
320 throw invalid_argument("Unexcepted command line token: "+arg);
321 }
Mark Sleee8540632006-05-30 09:24:40 +0000322 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000323
324 try {
325
Mark Sleef5f2be42006-09-05 21:05:31 +0000326 if (!args["port"].empty()) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000327 port = atoi(args["port"].c_str());
328 }
329
Mark Sleef5f2be42006-09-05 21:05:31 +0000330 if (!args["server-type"].empty()) {
David Reiss0c90f6f2008-02-06 22:18:40 +0000331 serverType = args["server-type"];
Mark Sleef5f2be42006-09-05 21:05:31 +0000332 if (serverType == "simple") {
333 } else if (serverType == "thread-pool") {
Mark Slee0c2dff32007-03-09 19:26:57 +0000334 } else if (serverType == "threaded") {
Mark Sleeb9acf982006-10-10 01:57:32 +0000335 } else if (serverType == "nonblocking") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000336 } else {
Marc Slemko6be374b2006-08-04 03:16:25 +0000337 throw invalid_argument("Unknown server type "+serverType);
338 }
339 }
340
Mark Sleef5f2be42006-09-05 21:05:31 +0000341 if (!args["protocol-type"].empty()) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000342 protocolType = args["protocol-type"];
Mark Sleef5f2be42006-09-05 21:05:31 +0000343 if (protocolType == "binary") {
344 } else if (protocolType == "ascii") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000345 throw invalid_argument("ASCII protocol not supported");
Mark Sleef5f2be42006-09-05 21:05:31 +0000346 } else if (protocolType == "xml") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000347 throw invalid_argument("XML protocol not supported");
348 } else {
349 throw invalid_argument("Unknown protocol type "+protocolType);
350 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000351 }
Marc Slemko6be374b2006-08-04 03:16:25 +0000352
Mark Sleef5f2be42006-09-05 21:05:31 +0000353 if (!args["workers"].empty()) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000354 workerCount = atoi(args["workers"].c_str());
355 }
Bryan Duxbury833ae492010-09-27 17:26:02 +0000356 } catch (std::exception& e) {
Marc Slemko6be374b2006-08-04 03:16:25 +0000357 cerr << e.what() << endl;
358 cerr << usage;
359 }
360
Mark Sleee8540632006-05-30 09:24:40 +0000361 // Dispatcher
Mark Sleea3302652006-10-25 19:03:32 +0000362 shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
Marc Slemko6be374b2006-08-04 03:16:25 +0000363
Mark Sleed2655522006-09-05 22:09:57 +0000364 shared_ptr<TestHandler> testHandler(new TestHandler());
365
Mark Sleea3302652006-10-25 19:03:32 +0000366 shared_ptr<ThriftTestProcessor> testProcessor(new ThriftTestProcessor(testHandler));
Mark Sleee8540632006-05-30 09:24:40 +0000367
Mark Sleee8540632006-05-30 09:24:40 +0000368 // Transport
Marc Slemko6be374b2006-08-04 03:16:25 +0000369 shared_ptr<TServerSocket> serverSocket(new TServerSocket(port));
Mark Sleee8540632006-05-30 09:24:40 +0000370
Mark Sleed788b2e2006-09-07 01:26:35 +0000371 // Factory
372 shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
373
Mark Sleed3d733a2006-09-01 22:19:06 +0000374 if (serverType == "simple") {
Mark Sleee8540632006-05-30 09:24:40 +0000375
Marc Slemko6be374b2006-08-04 03:16:25 +0000376 // Server
Mark Slee018b6992006-09-07 21:31:12 +0000377 TSimpleServer simpleServer(testProcessor,
Mark Sleed788b2e2006-09-07 01:26:35 +0000378 serverSocket,
379 transportFactory,
Mark Sleea3302652006-10-25 19:03:32 +0000380 protocolFactory);
Marc Slemko6be374b2006-08-04 03:16:25 +0000381
382 printf("Starting the server on port %d...\n", port);
Mark Slee794993d2006-09-20 01:56:10 +0000383 simpleServer.serve();
Marc Slemko6be374b2006-08-04 03:16:25 +0000384
Mark Sleed3d733a2006-09-01 22:19:06 +0000385 } else if (serverType == "thread-pool") {
Marc Slemko6be374b2006-08-04 03:16:25 +0000386
Mark Sleef5f2be42006-09-05 21:05:31 +0000387 shared_ptr<ThreadManager> threadManager =
388 ThreadManager::newSimpleThreadManager(workerCount);
Marc Slemko6be374b2006-08-04 03:16:25 +0000389
Mark Sleef5f2be42006-09-05 21:05:31 +0000390 shared_ptr<PosixThreadFactory> threadFactory =
391 shared_ptr<PosixThreadFactory>(new PosixThreadFactory());
Marc Slemko6be374b2006-08-04 03:16:25 +0000392
393 threadManager->threadFactory(threadFactory);
394
395 threadManager->start();
396
Mark Slee018b6992006-09-07 21:31:12 +0000397 TThreadPoolServer threadPoolServer(testProcessor,
Marc Slemko6be374b2006-08-04 03:16:25 +0000398 serverSocket,
Mark Sleed788b2e2006-09-07 01:26:35 +0000399 transportFactory,
Mark Sleea3302652006-10-25 19:03:32 +0000400 protocolFactory,
401 threadManager);
Marc Slemko6be374b2006-08-04 03:16:25 +0000402
403 printf("Starting the server on port %d...\n", port);
Mark Slee794993d2006-09-20 01:56:10 +0000404 threadPoolServer.serve();
Mark Sleeb9acf982006-10-10 01:57:32 +0000405
Mark Slee0c2dff32007-03-09 19:26:57 +0000406 } else if (serverType == "threaded") {
David Reiss0c90f6f2008-02-06 22:18:40 +0000407
Mark Slee0c2dff32007-03-09 19:26:57 +0000408 TThreadedServer threadedServer(testProcessor,
409 serverSocket,
410 transportFactory,
411 protocolFactory);
412
413 printf("Starting the server on port %d...\n", port);
414 threadedServer.serve();
415
Mark Sleeb9acf982006-10-10 01:57:32 +0000416 } else if (serverType == "nonblocking") {
Mark Sleea3302652006-10-25 19:03:32 +0000417 TNonblockingServer nonblockingServer(testProcessor, port);
Mark Sleeb9acf982006-10-10 01:57:32 +0000418 printf("Starting the nonblocking server on port %d...\n", port);
419 nonblockingServer.serve();
Marc Slemko6be374b2006-08-04 03:16:25 +0000420 }
421
Mark Sleee8540632006-05-30 09:24:40 +0000422 printf("done.\n");
423 return 0;
424}