You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by br...@apache.org on 2011/09/01 20:31:54 UTC

svn commit: r1164201 - in /thrift/trunk/lib/cpp/src: Thrift.h server/TNonblockingServer.h server/TServer.h server/TSimpleServer.h server/TThreadPoolServer.cpp server/TThreadPoolServer.h server/TThreadedServer.cpp server/TThreadedServer.h

Author: bryanduxbury
Date: Thu Sep  1 18:31:53 2011
New Revision: 1164201

URL: http://svn.apache.org/viewvc?rev=1164201&view=rev
Log:
THRIFT-1316. cpp: update server classes to accept
TProcessorFactory objects

Patch: Adam Simpkins

Modified:
    thrift/trunk/lib/cpp/src/Thrift.h
    thrift/trunk/lib/cpp/src/server/TNonblockingServer.h
    thrift/trunk/lib/cpp/src/server/TServer.h
    thrift/trunk/lib/cpp/src/server/TSimpleServer.h
    thrift/trunk/lib/cpp/src/server/TThreadPoolServer.cpp
    thrift/trunk/lib/cpp/src/server/TThreadPoolServer.h
    thrift/trunk/lib/cpp/src/server/TThreadedServer.cpp
    thrift/trunk/lib/cpp/src/server/TThreadedServer.h

Modified: thrift/trunk/lib/cpp/src/Thrift.h
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/Thrift.h?rev=1164201&r1=1164200&r2=1164201&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/Thrift.h (original)
+++ thrift/trunk/lib/cpp/src/Thrift.h Thu Sep  1 18:31:53 2011
@@ -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*> > {

Modified: thrift/trunk/lib/cpp/src/server/TNonblockingServer.h
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/server/TNonblockingServer.h?rev=1164201&r1=1164200&r2=1164201&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/server/TNonblockingServer.h (original)
+++ thrift/trunk/lib/cpp/src/server/TNonblockingServer.h Thu Sep  1 18:31:53 2011
@@ -252,18 +252,48 @@ class TNonblockingServer : public TServe
   }
 
  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<ProcessorFactory>& processorFactory,
+      const boost::shared_ptr<TProtocolFactory>& protocolFactory,
+      int port,
+      const boost::shared_ptr<ThreadManager>& 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<TProcessor>& processor,
+      const boost::shared_ptr<Processor>& processor,
       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(Processor, TProcessor)) :
     TServer(processor) {
 
     init(port);
@@ -273,15 +303,39 @@ class TNonblockingServer : public TServe
     setThreadManager(threadManager);
   }
 
+  template<typename ProcessorFactory>
+  TNonblockingServer(
+      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>(),
+      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<TProcessor>& processor,
+      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>()) :
+        boost::shared_ptr<ThreadManager>(),
+      THRIFT_OVERLOAD_IF(Processor, TProcessor)) :
     TServer(processor) {
 
     init(port);

Modified: thrift/trunk/lib/cpp/src/server/TServer.h
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/server/TServer.h?rev=1164201&r1=1164200&r2=1164201&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/server/TServer.h (original)
+++ thrift/trunk/lib/cpp/src/server/TServer.h Thu Sep  1 18:31:53 2011
@@ -141,7 +141,23 @@ class TServer : public concurrency::Runn
   }
 
 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 @@ protected:
     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 @@ protected:
     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 @@ protected:
     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),

Modified: thrift/trunk/lib/cpp/src/server/TSimpleServer.h
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/server/TSimpleServer.h?rev=1164201&r1=1164200&r2=1164201&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/server/TSimpleServer.h (original)
+++ thrift/trunk/lib/cpp/src/server/TSimpleServer.h Thu Sep  1 18:31:53 2011
@@ -34,19 +34,50 @@ namespace apache { namespace thrift { na
  */
 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),

Modified: thrift/trunk/lib/cpp/src/server/TThreadPoolServer.cpp
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/server/TThreadPoolServer.cpp?rev=1164201&r1=1164200&r2=1164201&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/server/TThreadPoolServer.cpp (original)
+++ thrift/trunk/lib/cpp/src/server/TThreadPoolServer.cpp Thu Sep  1 18:31:53 2011
@@ -108,28 +108,6 @@ public:
   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() {

Modified: thrift/trunk/lib/cpp/src/server/TThreadPoolServer.h
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/server/TThreadPoolServer.h?rev=1164201&r1=1164200&r2=1164201&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/server/TThreadPoolServer.h (original)
+++ thrift/trunk/lib/cpp/src/server/TThreadPoolServer.h Thu Sep  1 18:31:53 2011
@@ -37,19 +37,66 @@ class TThreadPoolServer : public TServer
  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);
-
-  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 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) {}
+
+  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();
 

Modified: thrift/trunk/lib/cpp/src/server/TThreadedServer.cpp
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/server/TThreadedServer.cpp?rev=1164201&r1=1164200&r2=1164201&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/server/TThreadedServer.cpp (original)
+++ thrift/trunk/lib/cpp/src/server/TThreadedServer.cpp Thu Sep  1 18:31:53 2011
@@ -119,24 +119,12 @@ public:
   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() {}

Modified: thrift/trunk/lib/cpp/src/server/TThreadedServer.h
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/server/TThreadedServer.h?rev=1164201&r1=1164200&r2=1164201&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/server/TThreadedServer.h (original)
+++ thrift/trunk/lib/cpp/src/server/TThreadedServer.h Thu Sep  1 18:31:53 2011
@@ -40,16 +40,35 @@ class TThreadedServer : public TServer {
  public:
   class Task;
 
-  TThreadedServer(boost::shared_ptr<TProcessor> processor,
-                  boost::shared_ptr<TServerTransport> serverTransport,
-                  boost::shared_ptr<TTransportFactory> transportFactory,
-                  boost::shared_ptr<TProtocolFactory> protocolFactory);
-
-  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,
+                  THRIFT_OVERLOAD_IF(ProcessorFactory, TProcessorFactory));
+
+  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 @@ class TThreadedServer : public TServer {
   }
 
  protected:
+  void init();
+
   boost::shared_ptr<ThreadFactory> threadFactory_;
   volatile bool stop_;
 
@@ -69,6 +90,56 @@ class TThreadedServer : public TServer {
 
 };
 
+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_