Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This autogenerated skeleton file illustrates how to build a server.
- // You should copy it to another filename to avoid overwriting it.
- #include "tagger.h"
- #include <thrift/protocol/TBinaryProtocol.h>
- #include <thrift/server/TSimpleServer.h>
- #include <thrift/transport/TServerSocket.h>
- #include <thrift/transport/TBufferTransports.h>
- #include <thrift/concurrency/ThreadManager.h>
- #include <thrift/concurrency/PosixThreadFactory.h>
- #include <thrift/server/TThreadPoolServer.h>
- #include <thrift/server/TNonblockingServer.h>
- using namespace ::apache::thrift;
- using namespace ::apache::thrift::protocol;
- using namespace ::apache::thrift::transport;
- using namespace ::apache::thrift::server;
- using namespace ::apache::thrift::concurrency;
- using boost::shared_ptr;
- class taggerHandler : virtual public taggerIf {
- public:
- taggerHandler() {
- this->loadRes();
- printf("server loaded\n");
- // Your initialization goes here
- }
- void tagText(std::string& _return, const std::string& text, const std::string& language) {
- // Your implementation goes here
- printf("tagText\n");
- _return = "as";
- }
- void manage(std::string& _return, const std::string& parmeters) {
- // Your implementation goes here
- printf("reload\n");
- delete[] this->data;
- this->loadRes();
- }
- private:
- void loadRes() {
- this->data = new char[10240000];
- }
- char *data;
- };
- int main(int argc, char **argv) {
- int port = 9091;
- shared_ptr<taggerHandler> handler(new taggerHandler());
- shared_ptr<TProcessor> processor(new taggerProcessor(handler));
- shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
- shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
- //shared_ptr<TProtocolFactory> protocolFactory(new TBufferedTransportFactory());
- shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
- shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(15);
- shared_ptr<PosixThreadFactory> threadFactory = shared_ptr<PosixThreadFactory>(new PosixThreadFactory());
- threadManager->threadFactory(threadFactory);
- threadManager->start();
- //TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
- //TThreadPoolServer server(processor, serverTransport, transportFactory, protocolFactory, threadManager);//, port, threadManager);
- TNonblockingServer server(processor, protocolFactory, port, threadManager);
- server.serve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment