Converted concurrency classes to use boost::shared_ptr and boost::weak_ptr:

Wrapped all thrift code in facebook::thrift:: namespace


	


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664736 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/server/TThreadPoolServer.cc b/lib/cpp/src/server/TThreadPoolServer.cc
new file mode 100644
index 0000000..2d6290c
--- /dev/null
+++ b/lib/cpp/src/server/TThreadPoolServer.cc
@@ -0,0 +1,98 @@
+#include "server/TThreadPoolServer.h"
+#include "transport/TBufferedTransport.h"
+#include "transport/TTransportException.h"
+#include "concurrency/Thread.h"
+#include "concurrency/ThreadManager.h"
+#include <string>
+#include <iostream>
+
+namespace facebook { namespace thrift { namespace server { 
+
+using namespace std;
+using namespace facebook::thrift::concurrency;
+using namespace facebook::thrift::transport;
+
+class TThreadPoolServer : public TServer {
+
+  class Task: public Runnable {
+    
+    TProcessor* _processor;
+    TTransport* _transport;
+    TBufferedTransport _bufferedTransport;
+    
+  public:
+    
+    Task(TProcessor* processor,
+	 TTransport* transport) :
+      _processor(processor),
+      _transport(transport),
+      _bufferedTransport(_transport) {
+    }
+    
+    ~Task() {
+      delete _transport;
+    }
+    
+    void run() {
+      
+      while(true) {
+	
+	try {
+	  _processor->process(&_bufferedTransport);
+
+	} catch (TTransportException& ttx) {
+
+	  break;
+
+	} catch(...) {
+
+	  break;
+	}
+      }
+      
+      _bufferedTransport.close();
+    }
+  };
+  
+  TThreadPoolServer(TProcessor* processor,
+		    TServerOptions* options,
+		    TServerTransport* serverTransport,
+		    ThreadManager* threadManager) :
+    TServer(processor, options), 
+    serverTransport_(serverTransport), 
+    threadManager_(threadManager) {
+  }
+    
+  ~TThreadPoolServer() {}
+
+ protected:
+
+  TServerTransport* serverTransport_;
+  ThreadManager* threadManager_;
+  
+  void run() {
+
+    try {
+      // Start the server listening
+      serverTransport_->listen();
+    } catch (TTransportException& ttx) {
+      cerr << "TThreadPoolServer::run() listen(): " << ttx.getMessage() << endl;
+      return;
+    }
+
+    // Fetch client from server
+
+    while (true) {
+
+      try {
+
+	threadManager_->add(shared_ptr<Task>(new TThreadPoolServer::Task(processor_, serverTransport_->accept())));;
+
+      } catch (TTransportException& ttx) {
+	break;
+      }
+    }
+  }
+};
+
+}}} // facebook::thrift::server