Author: dreiss
Date: Tue Oct  7 14:39:19 2008
New Revision: 702644

URL: http://svn.apache.org/viewvc?rev=702644&view=rev
Log:
THRIFT-149. cpp: Make TNonblockingServer handle a shut-down ThreadManager

This is a step toward implementing a graceful shutdown.

Modified:
    incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp

Modified: incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp?rev=702644&r1=702643&r2=702644&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp (original)
+++ incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp Tue Oct  7 
14:39:19 2008
@@ -5,6 +5,7 @@
 // http://developers.facebook.com/thrift/
 
 #include "TNonblockingServer.h"
+#include <concurrency/Exception.h>
 
 #include <iostream>
 #include <sys/socket.h>
@@ -19,6 +20,7 @@
 
 using namespace facebook::thrift::protocol;
 using namespace facebook::thrift::transport;
+using namespace facebook::thrift::concurrency;
 using namespace std;
 
 class TConnection::Task: public Runnable {
@@ -252,7 +254,13 @@
           GlobalOutput("TNonblockingServer::serve(): coult not event_add");
           return;
         }
-        server_->addTask(task);
+        try {
+          server_->addTask(task);
+        } catch (IllegalStateException & ise) {
+          // The ThreadManager is not ready to handle any more tasks (it's 
probably shutting down).
+          GlobalOutput.printf(stderr, "IllegalStateException: 
Server::process() %s", ise.what());
+          close();
+        }
 
         // Set this connection idle so that libevent doesn't process more
         // data on it while we're still waiting for the threadmanager to


Reply via email to