Thrift TTransportFactory model for servers

Summary: Servers need to create bufferedtransports etc. around the transports they get in a user-definable way. So use a factory pattern to allow the user to supply an object to the server that defines this behavior.


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664792 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/test/cpp/src/TestServer.cc b/test/cpp/src/TestServer.cc
index 97d3440..f743aea 100644
--- a/test/cpp/src/TestServer.cc
+++ b/test/cpp/src/TestServer.cc
@@ -4,6 +4,7 @@
 #include <server/TSimpleServer.h>
 #include <server/TThreadPoolServer.h>
 #include <transport/TServerSocket.h>
+#include <transport/TBufferedTransportFactory.h>
 #include "ThriftTest.h"
 
 #include <iostream>
@@ -53,23 +54,13 @@
   }
 
   Xtruct testStruct(Xtruct thing) {
-    printf("testStruct({\"%s\", %d, %d, %ld})\n",
-           thing.string_thing.c_str(),
-           (int)thing.byte_thing,
-           thing.i32_thing,
-           thing.i64_thing);
+    printf("testStruct({\"%s\", %d, %d, %ld})\n", thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing);
     return thing;
   }
 
   Xtruct2 testNest(Xtruct2 nest) {
     Xtruct thing = nest.struct_thing;
-    printf("testNest({%d, {\"%s\", %d, %d, %ld}, %d})\n",
-           (int)nest.byte_thing,
-           thing.string_thing.c_str(),
-           (int)thing.byte_thing,
-           thing.i32_thing,
-           thing.i64_thing,
-           nest.i32_thing);
+    printf("testNest({%d, {\"%s\", %d, %d, %ld}, %d})\n", (int)nest.byte_thing, thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing, nest.i32_thing);
     return nest;
   }
 
@@ -205,11 +196,7 @@
         list<Xtruct>::const_iterator x;
         printf("{");
         for (x = xtructs.begin(); x != xtructs.end(); ++x) {
-          printf("{\"%s\", %d, %d, %ld}, ",
-                 x->string_thing.c_str(),
-                 (int)x->byte_thing,
-                 x->i32_thing,
-                 x->i64_thing);
+          printf("{\"%s\", %d, %d, %ld}, ", x->string_thing.c_str(), (int)x->byte_thing, x->i32_thing, x->i64_thing);
         }
         printf("}");
 
@@ -347,18 +334,23 @@
 
   shared_ptr<ThriftTestServer> testServer(new ThriftTestServer(testHandler, binaryProtocol));
 
-  // Options
-  shared_ptr<TServerOptions> serverOptions(new TServerOptions());
-
   // Transport
   shared_ptr<TServerSocket> serverSocket(new TServerSocket(port));
 
+  // Factory
+  shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
+
+  // Options
+  shared_ptr<TServerOptions> serverOptions(new TServerOptions());
+
   if (serverType == "simple") {
 
     // Server
     TSimpleServer simpleServer(testServer,
-			       serverOptions,
-			       serverSocket);
+			       serverSocket,
+                               transportFactory,
+			       serverOptions
+                               );
 
     printf("Starting the server on port %d...\n", port);
     simpleServer.run();
@@ -376,9 +368,10 @@
     threadManager->start();
 
     TThreadPoolServer threadPoolServer(testServer,
-				       serverOptions,
 				       serverSocket,
-				       threadManager);
+                                       transportFactory,
+				       threadManager,
+				       serverOptions);
 
     printf("Starting the server on port %d...\n", port);
     threadPoolServer.run();