-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathidlhandller.h
More file actions
92 lines (82 loc) · 3.41 KB
/
Copy pathidlhandller.h
File metadata and controls
92 lines (82 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include <sys/time.h>
#include "base/thread.h"
#include <stdio.h>
#include "global_server.h"
#include "common_utils.h"
#include "globalServiceHandle.h"
#include <protocol/TBinaryProtocol.h>
#include <server/TThreadPoolServer.h>
#include <transport/TServerSocket.h>
#include <server/TSimpleServer.h>
#include <transport/TBufferTransports.h>
#include "processor/TMultiplexedProcessor.h"
#include "server/TNonblockingServer.h"
#include "concurrency/PosixThreadFactory.h"
#include "concurrency/ThreadManager.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 namespace base;
using namespace std;
using boost::shared_ptr;
class GlobalServer;
class IDLHandller : public base::Thread
{
public:
IDLHandller(GlobalServer* proxy){m_pSproxy = proxy;};
~IDLHandller(){};
private:
GlobalServer* m_pSproxy;
protected:
virtual int run()
{
while(1)
{
if(m_threadstate == 0)
{
return 0;
}
try
{
int nPort = base::s2i(m_pSproxy->m_confMgr["globalserver\\thrift\\port"]);
string strIp = m_pSproxy->m_confMgr["globalserver\\thrift\\ip"];
int nThreadNum = base::s2i(m_pSproxy->m_confMgr["globalserver\\thrift\\threadnum"]);
shared_ptr<GlobalServiceHandler> handler(new GlobalServiceHandler(m_pSproxy));
shared_ptr<TProcessor> spMsgProcessor(new GlobalServiceProcessor(handler));
//shared_ptr<TServerTransport> serverTransport(new TServerSocket(strIp, nPort));
shared_ptr<TServerTransport> serverTransport(new TServerSocket(nPort));
shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
//shared_ptr<TMultiplexedProcessor> cMultiProcessor(new TMultiplexedProcessor());
// cMultiProcessor->registerProcessor("LoginService", spLoginProcessor);
shared_ptr<ThreadManager> spThreadManager(ThreadManager::newSimpleThreadManager(nThreadNum));
shared_ptr<ThreadFactory> spPthreadFactory(new PosixThreadFactory());
spThreadManager->threadFactory(spPthreadFactory);
spThreadManager->start();
//TThreadPoolServer server(cMultiProcessor, serverTransport, transportFactory, protocolFactory, spThreadManager);
TNonblockingServer server(spMsgProcessor,protocolFactory,nPort,spThreadManager);
server.setTaskExpireTime(3000);
server.serve();
}
catch(conf_load_error &ex)
{
cout<<"IDLHandller::run failed:"<<ex.what()<<endl;
throw ex;
}
catch(conf_not_find &ex)
{
cout<<"IDLHandller::run conf_not_find:"<<ex.what()<<endl;
throw ex;
}
catch (...)
{
//m_pSproxy->m_pRollLog->error("IDLHandller:except,exit");
cout<<"IDLHandller:except,exit"<<endl;
throw "IDLHandller:except,exit";
}
}
};
};