From: Mark Slee Date: Thu, 7 Sep 2006 21:31:12 +0000 (+0000) Subject: Thrift: generate Processors not Servers X-Git-Tag: 0.2.0~1678 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=018b6998d61fa77aa6f7fb9a73c7e6a2360782f2;p=common%2Fthrift.git Thrift: generate Processors not Servers Summary: Because the gen'd code isn't actually a server Reviewed By: aditya git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664794 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc index ce93926b..095dc475 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.cc +++ b/compiler/cpp/src/generate/t_cpp_generator.cc @@ -834,7 +834,7 @@ void t_cpp_generator::generate_service_server(t_service* tservice) { // Generate the header portion f_header_ << - "class " << service_name_ << "Server : " << + "class " << service_name_ << "Processor : " << "public facebook::thrift::TProcessor {" << endl; // Protected data members @@ -845,7 +845,7 @@ void t_cpp_generator::generate_service_server(t_service* tservice) { indent() << "boost::shared_ptr<" << service_name_ << "If> _iface;" << endl << indent() << "boost::shared_ptr _iprot;" << endl << indent() << "boost::shared_ptr _oprot;" << endl << - indent() << "std::map, boost::shared_ptr)> _processMap;" << endl; + indent() << "std::map, boost::shared_ptr)> _processMap;" << endl; indent_down(); // Process function declarations @@ -868,7 +868,7 @@ void t_cpp_generator::generate_service_server(t_service* tservice) { declare_map += (*f_iter)->get_name(); declare_map += "\"] = &"; declare_map += service_name_; - declare_map += "Server::process_"; + declare_map += "Processor::process_"; declare_map += (*f_iter)->get_name(); declare_map += ";\n"; } @@ -876,17 +876,17 @@ void t_cpp_generator::generate_service_server(t_service* tservice) { f_header_ << " public: " << endl << - indent() << service_name_ << "Server(boost::shared_ptr<" << service_name_ << "If> iface, boost::shared_ptr prot) : " << + indent() << service_name_ << "Processor(boost::shared_ptr<" << service_name_ << "If> iface, boost::shared_ptr prot) : " << "_iface(iface), _iprot(prot), _oprot(prot) {" << endl << declare_map << indent() << "}" << endl << - indent() << service_name_ << "Server(boost::shared_ptr<" << service_name_ << "If> iface, boost::shared_ptr iprot, boost::shared_ptr oprot) : " << + indent() << service_name_ << "Processor(boost::shared_ptr<" << service_name_ << "If> iface, boost::shared_ptr iprot, boost::shared_ptr oprot) : " << "_iface(iface), _iprot(iprot), _oprot(oprot) {" << endl << declare_map << indent() << "}" << endl << endl << indent() << "bool process(boost::shared_ptr _itrans, boost::shared_ptr _otrans);" << endl << - indent() << "virtual ~" << service_name_ << "Server() {}" << endl; + indent() << "virtual ~" << service_name_ << "Processor() {}" << endl; indent_down(); f_header_ << "};" << endl << endl; @@ -894,7 +894,7 @@ void t_cpp_generator::generate_service_server(t_service* tservice) { // Generate the server implementation f_service_ << - "bool " << service_name_ << "Server::" << + "bool " << service_name_ << "Processor::" << "process(boost::shared_ptr itrans, boost::shared_ptr otrans) {" << endl; indent_up(); @@ -913,7 +913,7 @@ void t_cpp_generator::generate_service_server(t_service* tservice) { // HOT: member function pointer map f_service_ << - indent() << "std::map, boost::shared_ptr)>::iterator pfn;" << endl << + indent() << "std::map, boost::shared_ptr)>::iterator pfn;" << endl << indent() << "pfn = _processMap.find(fname);" << endl << indent() << "if (pfn == _processMap.end()) {" << endl << indent() << " throw facebook::thrift::Exception(\"Unknown function name: '\"+fname+\"'\");" << endl << @@ -1003,7 +1003,7 @@ void t_cpp_generator::generate_process_function(t_service* tservice, t_function* tfunction) { // Open function f_service_ << - "void " << tservice->get_name() << "Server::" << + "void " << tservice->get_name() << "Processor::" << "process_" << tfunction->get_name() << "(int32_t seqid, boost::shared_ptr itrans, boost::shared_ptr otrans)" << endl; scope_up(f_service_); diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc index 6d12dcec..987a7557 100644 --- a/compiler/cpp/src/generate/t_java_generator.cc +++ b/compiler/cpp/src/generate/t_java_generator.cc @@ -599,11 +599,11 @@ void t_java_generator::generate_service_server(t_service* tservice) { // Generate the header portion f_service_ << - "public static class Server implements TProcessor {" << endl; + "public static class Processor implements TProcessor {" << endl; indent_up(); indent(f_service_) << - "public Server(Iface iface, TProtocol prot)" << endl; + "public Processor(Iface iface, TProtocol prot)" << endl; scope_up(f_service_); indent(f_service_) << "this(iface, prot, prot);" << endl; @@ -611,7 +611,7 @@ void t_java_generator::generate_service_server(t_service* tservice) { f_service_ << endl; indent(f_service_) << - "public Server(Iface iface, TProtocol iprot, TProtocol oprot)" << endl; + "public Processor(Iface iface, TProtocol iprot, TProtocol oprot)" << endl; scope_up(f_service_); f_service_ << indent() << "_iface = iface;" << endl << diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc index a8f66ad5..f07af33e 100644 --- a/compiler/cpp/src/generate/t_py_generator.cc +++ b/compiler/cpp/src/generate/t_py_generator.cc @@ -571,7 +571,7 @@ void t_py_generator::generate_service_server(t_service* tservice) { // Generate the header portion f_service_ << - "class Server(Iface, TProcessor):" << endl; + "class Processor(Iface, TProcessor):" << endl; indent_up(); indent(f_service_) << @@ -587,7 +587,7 @@ void t_py_generator::generate_service_server(t_service* tservice) { indent() << "self.__processMap = {" << endl; for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) { f_service_ << - indent() << " \"" << (*f_iter)->get_name() << "\" : Server.process_" << (*f_iter)->get_name() << "," << endl; + indent() << " \"" << (*f_iter)->get_name() << "\" : Processor.process_" << (*f_iter)->get_name() << "," << endl; } f_service_ << indent() << "}" << endl; diff --git a/test/cpp/src/TestServer.cc b/test/cpp/src/TestServer.cc index f743aea0..f2f9eca5 100644 --- a/test/cpp/src/TestServer.cc +++ b/test/cpp/src/TestServer.cc @@ -332,7 +332,7 @@ int main(int argc, char **argv) { shared_ptr testHandler(new TestHandler()); - shared_ptr testServer(new ThriftTestServer(testHandler, binaryProtocol)); + shared_ptr testProcessor(new ThriftTestProcessor(testHandler, binaryProtocol)); // Transport shared_ptr serverSocket(new TServerSocket(port)); @@ -346,7 +346,7 @@ int main(int argc, char **argv) { if (serverType == "simple") { // Server - TSimpleServer simpleServer(testServer, + TSimpleServer simpleServer(testProcessor, serverSocket, transportFactory, serverOptions @@ -367,7 +367,7 @@ int main(int argc, char **argv) { threadManager->start(); - TThreadPoolServer threadPoolServer(testServer, + TThreadPoolServer threadPoolServer(testProcessor, serverSocket, transportFactory, threadManager, diff --git a/test/java/src/TestServer.java b/test/java/src/TestServer.java index b5277770..ab8603af 100644 --- a/test/java/src/TestServer.java +++ b/test/java/src/TestServer.java @@ -241,8 +241,8 @@ public class TestServer { new TBinaryProtocol(); TestHandler testHandler = new TestHandler(); - ThriftTest.Server testServer = - new ThriftTest.Server(testHandler, binaryProtocol); + ThriftTest.Processor testProcessor = + new ThriftTest.Processor(testHandler, binaryProtocol); // Transport TServerSocket tServerSocket = @@ -251,10 +251,10 @@ public class TestServer { TServer serverEngine; // Simple Server - // serverEngine = new TSimpleServer(testServer, tServerSocket); + // serverEngine = new TSimpleServer(testProcessor, tServerSocket); // ThreadPool Server - serverEngine = new TThreadPoolServer(testServer, tServerSocket); + serverEngine = new TThreadPoolServer(testProcessor, tServerSocket); // Run it System.out.println("Starting the server on port " + port + "..."); diff --git a/test/php/TestClient.php b/test/php/TestClient.php index a92adcca..27a66eac 100644 --- a/test/php/TestClient.php +++ b/test/php/TestClient.php @@ -7,8 +7,11 @@ if (!isset($MODE)) { $MODE = 'normal'; } +/** Set the Thrift root */ +$GLOBALS['THRIFT_ROOT'] = '../../lib/php/src'; + /** Include the Thrift base */ -require_once '/home/mcslee/code/projects/thrift/lib/php/src/Thrift.php'; +require_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php'; /** Include the binary protocol */ require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php'; diff --git a/test/py/TestServer.py b/test/py/TestServer.py index db2ad81b..f0f9ba11 100755 --- a/test/py/TestServer.py +++ b/test/py/TestServer.py @@ -54,7 +54,7 @@ class TestHandler: transport = TSocket.TServerSocket(9090) protocol = TBinaryProtocol.TBinaryProtocol() handler = TestHandler() -iface = ThriftTest.Server(handler, protocol) +processor = ThriftTest.Processor(handler, protocol) factory = TTransport.TBufferedTransportFactory() -server = TServer.TSimpleServer(iface, transport, factory) +server = TServer.TSimpleServer(processor, transport, factory) server.run()