THRIFT-1316. cpp: update server classes to accept
TProcessorFactory objects
Patch: Adam Simpkins
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1164201 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/Thrift.h b/lib/cpp/src/Thrift.h
index c6b31a8..df52dab 100644
--- a/lib/cpp/src/Thrift.h
+++ b/lib/cpp/src/Thrift.h
@@ -39,8 +39,33 @@
#include <exception>
#include <typeinfo>
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_convertible.hpp>
+
#include "TLogging.h"
+/**
+ * Helper macros to allow function overloading even when using
+ * boost::shared_ptr.
+ *
+ * shared_ptr makes overloading really annoying, since shared_ptr defines
+ * constructor methods to allow one shared_ptr type to be constructed from any
+ * other shared_ptr type. (Even if it would be a compile error to actually try
+ * to instantiate the constructor.) These macros add an extra argument to the
+ * function to cause it to only be instantiated if a pointer of type T is
+ * convertible to a pointer of type U.
+ *
+ * THRIFT_OVERLOAD_IF should be used in function declarations.
+ * THRIFT_OVERLOAD_IF_DEFN should be used in the function definition, if it is
+ * defined separately from where it is declared.
+ */
+#define THRIFT_OVERLOAD_IF_DEFN(T, Y) \
+ typename ::boost::enable_if<typename ::boost::is_convertible<T*, Y*>::type, \
+ void*>::type
+
+#define THRIFT_OVERLOAD_IF(T, Y) \
+ THRIFT_OVERLOAD_IF_DEFN(T, Y) = NULL
+
namespace apache { namespace thrift {
class TEnumIterator : public std::iterator<std::forward_iterator_tag, std::pair<int, const char*> > {
diff --git a/lib/cpp/src/server/TNonblockingServer.h b/lib/cpp/src/server/TNonblockingServer.h
index 5cda2c5..a26fcc5 100644
--- a/lib/cpp/src/server/TNonblockingServer.h
+++ b/lib/cpp/src/server/TNonblockingServer.h
@@ -252,18 +252,48 @@
}
public:
- TNonblockingServer(const boost::shared_ptr<TProcessor>& processor,
- int port) :
+ template<typename ProcessorFactory>
+ TNonblockingServer(
+ const boost::shared_ptr<ProcessorFactory>& processorFactory,
+ int port,
+ THRIFT_OVERLOAD_IF(ProcessorFactory, TProcessorFactory)) :
+ TServer(processorFactory) {
+ init(port);
+ }
+
+ template<typename Processor>
+ TNonblockingServer(const boost::shared_ptr<Processor>& processor,
+ int port,
+ THRIFT_OVERLOAD_IF(Processor, TProcessor)) :
TServer(processor) {
init(port);
}
+ template<typename ProcessorFactory>
TNonblockingServer(
- const boost::shared_ptr<TProcessor>& processor,
+ const boost::shared_ptr<ProcessorFactory>& processorFactory,
const boost::shared_ptr<TProtocolFactory>& protocolFactory,
int port,
const boost::shared_ptr<ThreadManager>& threadManager =
- boost::shared_ptr<ThreadManager>()) :
+ boost::shared_ptr<ThreadManager>(),
+ THRIFT_OVERLOAD_IF(ProcessorFactory, TProcessorFactory)) :
+ TServer(processorFactory) {
+
+ init(port);
+
+ setInputProtocolFactory(protocolFactory);
+ setOutputProtocolFactory(protocolFactory);
+ setThreadManager(threadManager);
+ }
+
+ template<typename Processor>
+ TNonblockingServer(
+ const boost::shared_ptr<Processor>& processor,
+ const boost::shared_ptr<TProtocolFactory>& protocolFactory,
+ int port,
+ const boost::shared_ptr<ThreadManager>& threadManager =
+ boost::shared_ptr<ThreadManager>(),
+ THRIFT_OVERLOAD_IF(Processor, TProcessor)) :
TServer(processor) {
init(port);
@@ -273,15 +303,39 @@
setThreadManager(threadManager);
}
+ template<typename ProcessorFactory>
TNonblockingServer(
- const boost::shared_ptr<TProcessor>& processor,
+ const boost::shared_ptr<ProcessorFactory>& processorFactory,
const boost::shared_ptr<TTransportFactory>& inputTransportFactory,
const boost::shared_ptr<TTransportFactory>& outputTransportFactory,
const boost::shared_ptr<TProtocolFactory>& inputProtocolFactory,
const boost::shared_ptr<TProtocolFactory>& outputProtocolFactory,
int port,
const boost::shared_ptr<ThreadManager>& threadManager =
- boost::shared_ptr<ThreadManager>()) :
+ boost::shared_ptr<ThreadManager>(),
+ THRIFT_OVERLOAD_IF(ProcessorFactory, TProcessorFactory)) :
+ TServer(processorFactory) {
+
+ init(port);
+
+ setInputTransportFactory(inputTransportFactory);
+ setOutputTransportFactory(outputTransportFactory);
+ setInputProtocolFactory(inputProtocolFactory);
+ setOutputProtocolFactory(outputProtocolFactory);
+ setThreadManager(threadManager);
+ }
+
+ template<typename Processor>
+ TNonblockingServer(
+ const boost::shared_ptr<Processor>& processor,
+ const boost::shared_ptr<TTransportFactory>& inputTransportFactory,
+ const boost::shared_ptr<TTransportFactory>& outputTransportFactory,
+ const boost::shared_ptr<TProtocolFactory>& inputProtocolFactory,
+ const boost::shared_ptr<TProtocolFactory>& outputProtocolFactory,
+ int port,
+ const boost::shared_ptr<ThreadManager>& threadManager =
+ boost::shared_ptr<ThreadManager>(),
+ THRIFT_OVERLOAD_IF(Processor, TProcessor)) :
TServer(processor) {
init(port);
diff --git a/lib/cpp/src/server/TServer.h b/lib/cpp/src/server/TServer.h
index 6bd1398..99e2205 100644
--- a/lib/cpp/src/server/TServer.h
+++ b/lib/cpp/src/server/TServer.h
@@ -141,7 +141,23 @@
}
protected:
- TServer(boost::shared_ptr<TProcessor> processor):
+ template<typename ProcessorFactory>
+ TServer(const boost::shared_ptr<TProcessorFactory>& processorFactory,
+ THRIFT_OVERLOAD_IF(ProcessorFactory, TProcessorFactory)):
+ processorFactory_(processorFactory_) {
+ setInputTransportFactory(boost::shared_ptr<TTransportFactory>(
+ new TTransportFactory()));
+ setOutputTransportFactory(boost::shared_ptr<TTransportFactory>(
+ new TTransportFactory()));
+ setInputProtocolFactory(boost::shared_ptr<TProtocolFactory>(
+ new TBinaryProtocolFactory()));
+ setOutputProtocolFactory(boost::shared_ptr<TProtocolFactory>(
+ new TBinaryProtocolFactory()));
+ }
+
+ template<typename Processor>
+ TServer(const boost::shared_ptr<Processor>& processor,
+ THRIFT_OVERLOAD_IF(Processor, TProcessor)):
processorFactory_(new TSingletonProcessorFactory(processor)) {
setInputTransportFactory(boost::shared_ptr<TTransportFactory>(new TTransportFactory()));
setOutputTransportFactory(boost::shared_ptr<TTransportFactory>(new TTransportFactory()));
@@ -149,8 +165,26 @@
setOutputProtocolFactory(boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()));
}
- TServer(boost::shared_ptr<TProcessor> processor,
- boost::shared_ptr<TServerTransport> serverTransport):
+ template<typename ProcessorFactory>
+ TServer(const boost::shared_ptr<TProcessorFactory>& processorFactory,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ THRIFT_OVERLOAD_IF(ProcessorFactory, TProcessorFactory)):
+ processorFactory_(processorFactory),
+ serverTransport_(serverTransport) {
+ setInputTransportFactory(boost::shared_ptr<TTransportFactory>(
+ new TTransportFactory()));
+ setOutputTransportFactory(boost::shared_ptr<TTransportFactory>(
+ new TTransportFactory()));
+ setInputProtocolFactory(boost::shared_ptr<TProtocolFactory>(
+ new TBinaryProtocolFactory()));
+ setOutputProtocolFactory(boost::shared_ptr<TProtocolFactory>(
+ new TBinaryProtocolFactory()));
+ }
+
+ template<typename Processor>
+ TServer(const boost::shared_ptr<Processor>& processor,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ THRIFT_OVERLOAD_IF(Processor, TProcessor)):
processorFactory_(new TSingletonProcessorFactory(processor)),
serverTransport_(serverTransport) {
setInputTransportFactory(boost::shared_ptr<TTransportFactory>(new TTransportFactory()));
@@ -159,10 +193,25 @@
setOutputProtocolFactory(boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()));
}
- TServer(boost::shared_ptr<TProcessor> processor,
- boost::shared_ptr<TServerTransport> serverTransport,
- boost::shared_ptr<TTransportFactory> transportFactory,
- boost::shared_ptr<TProtocolFactory> protocolFactory):
+ template<typename ProcessorFactory>
+ TServer(const boost::shared_ptr<ProcessorFactory>& processorFactory,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& transportFactory,
+ const boost::shared_ptr<TProtocolFactory>& protocolFactory,
+ THRIFT_OVERLOAD_IF(ProcessorFactory, TProcessorFactory)):
+ processorFactory_(processorFactory),
+ serverTransport_(serverTransport),
+ inputTransportFactory_(transportFactory),
+ outputTransportFactory_(transportFactory),
+ inputProtocolFactory_(protocolFactory),
+ outputProtocolFactory_(protocolFactory) {}
+
+ template<typename Processor>
+ TServer(const boost::shared_ptr<Processor>& processor,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& transportFactory,
+ const boost::shared_ptr<TProtocolFactory>& protocolFactory,
+ THRIFT_OVERLOAD_IF(Processor, TProcessor)):
processorFactory_(new TSingletonProcessorFactory(processor)),
serverTransport_(serverTransport),
inputTransportFactory_(transportFactory),
@@ -170,12 +219,29 @@
inputProtocolFactory_(protocolFactory),
outputProtocolFactory_(protocolFactory) {}
- TServer(boost::shared_ptr<TProcessor> processor,
- boost::shared_ptr<TServerTransport> serverTransport,
- boost::shared_ptr<TTransportFactory> inputTransportFactory,
- boost::shared_ptr<TTransportFactory> outputTransportFactory,
- boost::shared_ptr<TProtocolFactory> inputProtocolFactory,
- boost::shared_ptr<TProtocolFactory> outputProtocolFactory):
+ template<typename ProcessorFactory>
+ TServer(const boost::shared_ptr<ProcessorFactory>& processorFactory,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& inputTransportFactory,
+ const boost::shared_ptr<TTransportFactory>& outputTransportFactory,
+ const boost::shared_ptr<TProtocolFactory>& inputProtocolFactory,
+ const boost::shared_ptr<TProtocolFactory>& outputProtocolFactory,
+ THRIFT_OVERLOAD_IF(ProcessorFactory, TProcessorFactory)):
+ processorFactory_(processorFactory_),
+ serverTransport_(serverTransport),
+ inputTransportFactory_(inputTransportFactory),
+ outputTransportFactory_(outputTransportFactory),
+ inputProtocolFactory_(inputProtocolFactory),
+ outputProtocolFactory_(outputProtocolFactory) {}
+
+ template<typename Processor>
+ TServer(const boost::shared_ptr<Processor>& processor,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& inputTransportFactory,
+ const boost::shared_ptr<TTransportFactory>& outputTransportFactory,
+ const boost::shared_ptr<TProtocolFactory>& inputProtocolFactory,
+ const boost::shared_ptr<TProtocolFactory>& outputProtocolFactory,
+ THRIFT_OVERLOAD_IF(Processor, TProcessor)):
processorFactory_(new TSingletonProcessorFactory(processor)),
serverTransport_(serverTransport),
inputTransportFactory_(inputTransportFactory),
diff --git a/lib/cpp/src/server/TSimpleServer.h b/lib/cpp/src/server/TSimpleServer.h
index 29e120e..ea40ab0 100644
--- a/lib/cpp/src/server/TSimpleServer.h
+++ b/lib/cpp/src/server/TSimpleServer.h
@@ -34,19 +34,50 @@
*/
class TSimpleServer : public TServer {
public:
- TSimpleServer(boost::shared_ptr<TProcessor> processor,
- boost::shared_ptr<TServerTransport> serverTransport,
- boost::shared_ptr<TTransportFactory> transportFactory,
- boost::shared_ptr<TProtocolFactory> protocolFactory) :
+ template<typename ProcessorFactory>
+ TSimpleServer(
+ const boost::shared_ptr<ProcessorFactory>& processorFactory,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& transportFactory,
+ const boost::shared_ptr<TProtocolFactory>& protocolFactory,
+ THRIFT_OVERLOAD_IF(ProcessorFactory, TProcessorFactory)) :
+ TServer(processorFactory, serverTransport, transportFactory,
+ protocolFactory),
+ stop_(false) {}
+
+ template<typename Processor>
+ TSimpleServer(
+ const boost::shared_ptr<Processor>& processor,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& transportFactory,
+ const boost::shared_ptr<TProtocolFactory>& protocolFactory,
+ THRIFT_OVERLOAD_IF(Processor, TProcessor)) :
TServer(processor, serverTransport, transportFactory, protocolFactory),
stop_(false) {}
- TSimpleServer(boost::shared_ptr<TProcessor> processor,
- boost::shared_ptr<TServerTransport> serverTransport,
- boost::shared_ptr<TTransportFactory> inputTransportFactory,
- boost::shared_ptr<TTransportFactory> outputTransportFactory,
- boost::shared_ptr<TProtocolFactory> inputProtocolFactory,
- boost::shared_ptr<TProtocolFactory> outputProtocolFactory):
+ template<typename ProcessorFactory>
+ TSimpleServer(
+ const boost::shared_ptr<ProcessorFactory>& processorFactory,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& inputTransportFactory,
+ const boost::shared_ptr<TTransportFactory>& outputTransportFactory,
+ const boost::shared_ptr<TProtocolFactory>& inputProtocolFactory,
+ const boost::shared_ptr<TProtocolFactory>& outputProtocolFactory,
+ THRIFT_OVERLOAD_IF(ProcessorFactory, TProcessorFactory)) :
+ TServer(processorFactory, serverTransport,
+ inputTransportFactory, outputTransportFactory,
+ inputProtocolFactory, outputProtocolFactory),
+ stop_(false) {}
+
+ template<typename Processor>
+ TSimpleServer(
+ const boost::shared_ptr<Processor>& processor,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& inputTransportFactory,
+ const boost::shared_ptr<TTransportFactory>& outputTransportFactory,
+ const boost::shared_ptr<TProtocolFactory>& inputProtocolFactory,
+ const boost::shared_ptr<TProtocolFactory>& outputProtocolFactory,
+ THRIFT_OVERLOAD_IF(Processor, TProcessor)) :
TServer(processor, serverTransport,
inputTransportFactory, outputTransportFactory,
inputProtocolFactory, outputProtocolFactory),
diff --git a/lib/cpp/src/server/TThreadPoolServer.cpp b/lib/cpp/src/server/TThreadPoolServer.cpp
index 20183f1..c16e32f 100644
--- a/lib/cpp/src/server/TThreadPoolServer.cpp
+++ b/lib/cpp/src/server/TThreadPoolServer.cpp
@@ -108,28 +108,6 @@
shared_ptr<TTransport> transport_;
};
-TThreadPoolServer::TThreadPoolServer(shared_ptr<TProcessor> processor,
- shared_ptr<TServerTransport> serverTransport,
- shared_ptr<TTransportFactory> transportFactory,
- shared_ptr<TProtocolFactory> protocolFactory,
- shared_ptr<ThreadManager> threadManager) :
- TServer(processor, serverTransport, transportFactory, protocolFactory),
- threadManager_(threadManager),
- stop_(false), timeout_(0) {}
-
-TThreadPoolServer::TThreadPoolServer(shared_ptr<TProcessor> processor,
- shared_ptr<TServerTransport> serverTransport,
- shared_ptr<TTransportFactory> inputTransportFactory,
- shared_ptr<TTransportFactory> outputTransportFactory,
- shared_ptr<TProtocolFactory> inputProtocolFactory,
- shared_ptr<TProtocolFactory> outputProtocolFactory,
- shared_ptr<ThreadManager> threadManager) :
- TServer(processor, serverTransport, inputTransportFactory, outputTransportFactory,
- inputProtocolFactory, outputProtocolFactory),
- threadManager_(threadManager),
- stop_(false), timeout_(0) {}
-
-
TThreadPoolServer::~TThreadPoolServer() {}
void TThreadPoolServer::serve() {
diff --git a/lib/cpp/src/server/TThreadPoolServer.h b/lib/cpp/src/server/TThreadPoolServer.h
index 7b7e906..b860ae2 100644
--- a/lib/cpp/src/server/TThreadPoolServer.h
+++ b/lib/cpp/src/server/TThreadPoolServer.h
@@ -37,19 +37,66 @@
public:
class Task;
- TThreadPoolServer(boost::shared_ptr<TProcessor> processor,
- boost::shared_ptr<TServerTransport> serverTransport,
- boost::shared_ptr<TTransportFactory> transportFactory,
- boost::shared_ptr<TProtocolFactory> protocolFactory,
- boost::shared_ptr<ThreadManager> threadManager);
+ template<typename ProcessorFactory>
+ TThreadPoolServer(
+ const boost::shared_ptr<ProcessorFactory>& processorFactory,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& transportFactory,
+ const boost::shared_ptr<TProtocolFactory>& protocolFactory,
+ const boost::shared_ptr<ThreadManager>& threadManager,
+ THRIFT_OVERLOAD_IF(ProcessorFactory, TProtocolFactory)) :
+ TServer(processorFactory, serverTransport, transportFactory,
+ protocolFactory),
+ threadManager_(threadManager),
+ stop_(false),
+ timeout_(0) {}
- TThreadPoolServer(boost::shared_ptr<TProcessor> processor,
- boost::shared_ptr<TServerTransport> serverTransport,
- boost::shared_ptr<TTransportFactory> inputTransportFactory,
- boost::shared_ptr<TTransportFactory> outputTransportFactory,
- boost::shared_ptr<TProtocolFactory> inputProtocolFactory,
- boost::shared_ptr<TProtocolFactory> outputProtocolFactory,
- boost::shared_ptr<ThreadManager> threadManager);
+ template<typename Processor>
+ TThreadPoolServer(
+ const boost::shared_ptr<Processor>& processor,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& transportFactory,
+ const boost::shared_ptr<TProtocolFactory>& protocolFactory,
+ const boost::shared_ptr<ThreadManager>& threadManager,
+ THRIFT_OVERLOAD_IF(Processor, TProcessor)) :
+ TServer(processor, serverTransport, transportFactory, protocolFactory),
+ threadManager_(threadManager),
+ stop_(false),
+ timeout_(0) {}
+
+ template<typename ProcessorFactory>
+ TThreadPoolServer(
+ const boost::shared_ptr<ProcessorFactory>& processorFactory,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& inputTransportFactory,
+ const boost::shared_ptr<TTransportFactory>& outputTransportFactory,
+ const boost::shared_ptr<TProtocolFactory>& inputProtocolFactory,
+ const boost::shared_ptr<TProtocolFactory>& outputProtocolFactory,
+ const boost::shared_ptr<ThreadManager>& threadManager,
+ THRIFT_OVERLOAD_IF(ProcessorFactory, TProcessorFactory)) :
+ TServer(processorFactory, serverTransport,
+ inputTransportFactory, outputTransportFactory,
+ inputProtocolFactory, outputProtocolFactory),
+ threadManager_(threadManager),
+ stop_(false),
+ timeout_(0) {}
+
+ template<typename Processor>
+ TThreadPoolServer(
+ const boost::shared_ptr<Processor>& processor,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& inputTransportFactory,
+ const boost::shared_ptr<TTransportFactory>& outputTransportFactory,
+ const boost::shared_ptr<TProtocolFactory>& inputProtocolFactory,
+ const boost::shared_ptr<TProtocolFactory>& outputProtocolFactory,
+ const boost::shared_ptr<ThreadManager>& threadManager,
+ THRIFT_OVERLOAD_IF(Processor, TProcessor)) :
+ TServer(processor, serverTransport,
+ inputTransportFactory, outputTransportFactory,
+ inputProtocolFactory, outputProtocolFactory),
+ threadManager_(threadManager),
+ stop_(false),
+ timeout_(0) {}
virtual ~TThreadPoolServer();
diff --git a/lib/cpp/src/server/TThreadedServer.cpp b/lib/cpp/src/server/TThreadedServer.cpp
index 43d1df2..f40135c 100644
--- a/lib/cpp/src/server/TThreadedServer.cpp
+++ b/lib/cpp/src/server/TThreadedServer.cpp
@@ -119,24 +119,12 @@
shared_ptr<TTransport> transport_;
};
+void TThreadedServer::init() {
+ stop_ = false;
-TThreadedServer::TThreadedServer(shared_ptr<TProcessor> processor,
- shared_ptr<TServerTransport> serverTransport,
- shared_ptr<TTransportFactory> transportFactory,
- shared_ptr<TProtocolFactory> protocolFactory):
- TServer(processor, serverTransport, transportFactory, protocolFactory),
- stop_(false) {
- threadFactory_ = shared_ptr<PosixThreadFactory>(new PosixThreadFactory());
-}
-
-TThreadedServer::TThreadedServer(boost::shared_ptr<TProcessor> processor,
- boost::shared_ptr<TServerTransport> serverTransport,
- boost::shared_ptr<TTransportFactory> transportFactory,
- boost::shared_ptr<TProtocolFactory> protocolFactory,
- boost::shared_ptr<ThreadFactory> threadFactory):
- TServer(processor, serverTransport, transportFactory, protocolFactory),
- threadFactory_(threadFactory),
- stop_(false) {
+ if (!threadFactory_) {
+ threadFactory_.reset(new PosixThreadFactory);
+ }
}
TThreadedServer::~TThreadedServer() {}
diff --git a/lib/cpp/src/server/TThreadedServer.h b/lib/cpp/src/server/TThreadedServer.h
index 4d0811a..2db3fac 100644
--- a/lib/cpp/src/server/TThreadedServer.h
+++ b/lib/cpp/src/server/TThreadedServer.h
@@ -40,16 +40,35 @@
public:
class Task;
- TThreadedServer(boost::shared_ptr<TProcessor> processor,
- boost::shared_ptr<TServerTransport> serverTransport,
- boost::shared_ptr<TTransportFactory> transportFactory,
- boost::shared_ptr<TProtocolFactory> protocolFactory);
+ template<typename ProcessorFactory>
+ TThreadedServer(const boost::shared_ptr<ProcessorFactory>& processorFactory,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& transportFactory,
+ const boost::shared_ptr<TProtocolFactory>& protocolFactory,
+ THRIFT_OVERLOAD_IF(ProcessorFactory, TProcessorFactory));
- TThreadedServer(boost::shared_ptr<TProcessor> processor,
- boost::shared_ptr<TServerTransport> serverTransport,
- boost::shared_ptr<TTransportFactory> transportFactory,
- boost::shared_ptr<TProtocolFactory> protocolFactory,
- boost::shared_ptr<ThreadFactory> threadFactory);
+ template<typename ProcessorFactory>
+ TThreadedServer(const boost::shared_ptr<ProcessorFactory>& processorFactory,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& transportFactory,
+ const boost::shared_ptr<TProtocolFactory>& protocolFactory,
+ const boost::shared_ptr<ThreadFactory>& threadFactory,
+ THRIFT_OVERLOAD_IF(ProcessorFactory, TProtocolFactory));
+
+ template<typename Processor>
+ TThreadedServer(const boost::shared_ptr<Processor>& processor,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& transportFactory,
+ const boost::shared_ptr<TProtocolFactory>& protocolFactory,
+ THRIFT_OVERLOAD_IF(Processor, TProcessor));
+
+ template<typename Processor>
+ TThreadedServer(const boost::shared_ptr<Processor>& processor,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& transportFactory,
+ const boost::shared_ptr<TProtocolFactory>& protocolFactory,
+ const boost::shared_ptr<ThreadFactory>& threadFactory,
+ THRIFT_OVERLOAD_IF(Processor, TProcessor));
virtual ~TThreadedServer();
@@ -61,6 +80,8 @@
}
protected:
+ void init();
+
boost::shared_ptr<ThreadFactory> threadFactory_;
volatile bool stop_;
@@ -69,6 +90,56 @@
};
+template<typename ProcessorFactory>
+TThreadedServer::TThreadedServer(
+ const boost::shared_ptr<ProcessorFactory>& processorFactory,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& transportFactory,
+ const boost::shared_ptr<TProtocolFactory>& protocolFactory,
+ THRIFT_OVERLOAD_IF_DEFN(ProcessorFactory, TProcessorFactory)) :
+ TServer(processorFactory, serverTransport, transportFactory,
+ protocolFactory) {
+ init();
+}
+
+template<typename ProcessorFactory>
+TThreadedServer::TThreadedServer(
+ const boost::shared_ptr<ProcessorFactory>& processorFactory,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& transportFactory,
+ const boost::shared_ptr<TProtocolFactory>& protocolFactory,
+ const boost::shared_ptr<ThreadFactory>& threadFactory,
+ THRIFT_OVERLOAD_IF_DEFN(ProcessorFactory, TProtocolFactory)) :
+ TServer(processorFactory, serverTransport, transportFactory,
+ protocolFactory),
+ threadFactory_(threadFactory) {
+ init();
+}
+
+template<typename Processor>
+TThreadedServer::TThreadedServer(
+ const boost::shared_ptr<Processor>& processor,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& transportFactory,
+ const boost::shared_ptr<TProtocolFactory>& protocolFactory,
+ THRIFT_OVERLOAD_IF_DEFN(Processor, TProcessor)) :
+ TServer(processor, serverTransport, transportFactory, protocolFactory) {
+ init();
+}
+
+template<typename Processor>
+TThreadedServer::TThreadedServer(
+ const boost::shared_ptr<Processor>& processor,
+ const boost::shared_ptr<TServerTransport>& serverTransport,
+ const boost::shared_ptr<TTransportFactory>& transportFactory,
+ const boost::shared_ptr<TProtocolFactory>& protocolFactory,
+ const boost::shared_ptr<ThreadFactory>& threadFactory,
+ THRIFT_OVERLOAD_IF_DEFN(Processor, TProcessor)) :
+ TServer(processor, serverTransport, transportFactory, protocolFactory),
+ threadFactory_(threadFactory) {
+ init();
+}
+
}}} // apache::thrift::server
#endif // #ifndef _THRIFT_SERVER_TTHREADEDSERVER_H_