// Generate the header portion
f_header_ <<
- "class " << service_name_ << "Server : " <<
+ "class " << service_name_ << "Processor : " <<
"public facebook::thrift::TProcessor {" << endl;
// Protected data members
indent() << "boost::shared_ptr<" << service_name_ << "If> _iface;" << endl <<
indent() << "boost::shared_ptr<const facebook::thrift::protocol::TProtocol> _iprot;" << endl <<
indent() << "boost::shared_ptr<const facebook::thrift::protocol::TProtocol> _oprot;" << endl <<
- indent() << "std::map<std::string, void (" << service_name_ << "Server::*)(int32_t, boost::shared_ptr<facebook::thrift::transport::TTransport>, boost::shared_ptr<facebook::thrift::transport::TTransport>)> _processMap;" << endl;
+ indent() << "std::map<std::string, void (" << service_name_ << "Processor::*)(int32_t, boost::shared_ptr<facebook::thrift::transport::TTransport>, boost::shared_ptr<facebook::thrift::transport::TTransport>)> _processMap;" << endl;
indent_down();
// Process function declarations
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";
}
f_header_ <<
" public: " << endl <<
- indent() << service_name_ << "Server(boost::shared_ptr<" << service_name_ << "If> iface, boost::shared_ptr<const facebook::thrift::protocol::TProtocol> prot) : " <<
+ indent() << service_name_ << "Processor(boost::shared_ptr<" << service_name_ << "If> iface, boost::shared_ptr<const facebook::thrift::protocol::TProtocol> 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<const facebook::thrift::protocol::TProtocol> iprot, boost::shared_ptr<const facebook::thrift::protocol::TProtocol> oprot) : " <<
+ indent() << service_name_ << "Processor(boost::shared_ptr<" << service_name_ << "If> iface, boost::shared_ptr<const facebook::thrift::protocol::TProtocol> iprot, boost::shared_ptr<const facebook::thrift::protocol::TProtocol> oprot) : " <<
"_iface(iface), _iprot(iprot), _oprot(oprot) {" << endl <<
declare_map <<
indent() << "}" << endl <<
endl <<
indent() << "bool process(boost::shared_ptr<facebook::thrift::transport::TTransport> _itrans, boost::shared_ptr<facebook::thrift::transport::TTransport> _otrans);" << endl <<
- indent() << "virtual ~" << service_name_ << "Server() {}" << endl;
+ indent() << "virtual ~" << service_name_ << "Processor() {}" << endl;
indent_down();
f_header_ <<
"};" << endl << endl;
// Generate the server implementation
f_service_ <<
- "bool " << service_name_ << "Server::" <<
+ "bool " << service_name_ << "Processor::" <<
"process(boost::shared_ptr<facebook::thrift::transport::TTransport> itrans, boost::shared_ptr<facebook::thrift::transport::TTransport> otrans) {" << endl;
indent_up();
// HOT: member function pointer map
f_service_ <<
- indent() << "std::map<std::string, void (" << service_name_ << "Server::*)(int32_t, boost::shared_ptr<facebook::thrift::transport::TTransport>, boost::shared_ptr<facebook::thrift::transport::TTransport>)>::iterator pfn;" << endl <<
+ indent() << "std::map<std::string, void (" << service_name_ << "Processor::*)(int32_t, boost::shared_ptr<facebook::thrift::transport::TTransport>, boost::shared_ptr<facebook::thrift::transport::TTransport>)>::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 <<
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<facebook::thrift::transport::TTransport> itrans, boost::shared_ptr<facebook::thrift::transport::TTransport> otrans)" << endl;
scope_up(f_service_);
// 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;
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 <<
shared_ptr<TestHandler> testHandler(new TestHandler());
- shared_ptr<ThriftTestServer> testServer(new ThriftTestServer(testHandler, binaryProtocol));
+ shared_ptr<ThriftTestProcessor> testProcessor(new ThriftTestProcessor(testHandler, binaryProtocol));
// Transport
shared_ptr<TServerSocket> serverSocket(new TServerSocket(port));
if (serverType == "simple") {
// Server
- TSimpleServer simpleServer(testServer,
+ TSimpleServer simpleServer(testProcessor,
serverSocket,
transportFactory,
serverOptions
threadManager->start();
- TThreadPoolServer threadPoolServer(testServer,
+ TThreadPoolServer threadPoolServer(testProcessor,
serverSocket,
transportFactory,
threadManager,
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 =
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 + "...");