CMSDK  2.0.1
RequestExecutor.h
1 #if !defined(_REQUESTEXECUTOR_H_)
2 #define _REQUESTEXECUTOR_H_
3 
4 #pragma once
5 
6 #include "NetworkManager.h"
7 #include "RequestClient.h"
8 
9 
10 namespace cmlabs{
11 
13 // Request Executor
15 
16 class RequestExecutor : public Runnable, public NetworkReceiver {
17 public:
18  friend THREAD_RET THREAD_FUNCTION_CALL RequestExecutorRun(THREAD_ARG arg);
19 
20  RequestExecutor(uint32 id = 0, const char* name = NULL);
21  virtual ~RequestExecutor();
22  bool shutdownNetwork();
23 
24  bool addLongRequestName(const char* name);
25  bool addGateway(uint32 id, std::string addr, uint16 port, uint8 encryption = NOENC);
26  bool setLongRequestLimit(uint32 limit);
27 
28  bool receiveNetworkEvent(NetworkEvent* evt, NetworkChannel* channel, uint64 conid);
29  bool receiveMessage(DataMessage* msg, NetworkChannel* channel, uint64 conid);
30  bool receiveHTTPRequest(HTTPRequest* req, NetworkChannel* channel, uint64 conid) {return false;}
31 
32  DataMessage* waitForLongRequest(uint32 timeoutMS);
33  DataMessage* waitForShortRequest(uint32 timeoutMS);
34  bool replyToQuery(DataMessage* msg);
35 
36 protected:
37  bool run();
38  uint32 sendStatusNow();
39  bool sendMessageToGateway(DataMessage* msg, RequestGatewayConnection& con);
40 
41  std::list<RequestGatewayConnection> connections;
42  //std::map<uint64, RequestGatewayConnection> gateways;
43 
44  bool replyToGateway(DataMessage* msg);
45 
46  uint32 executorID;
47  std::string executorName;
48  NetworkManager* manager;
49  NetworkChannel* channel;
53  std::map<uint64,RequestReply*> requestMap;
54  std::vector<std::string> longReqNames;
55  utils::Mutex mutex;
56  utils::Mutex conMutex;
57  utils::Semaphore shortExecQSemaphore;
58  utils::Semaphore longExecQSemaphore;
59  uint32 threadID;
60  uint64 lastRefID;
61  uint64 repliedCount;
62  uint64 sentCount;
63  uint64 shortReceivedCount;
64  uint64 longReceivedCount;
65  int32 heartbeatIntervalMS;
66  uint64 lastHeartbeat;
67  uint32 longReqLimit;
68  //MovingAverage shortAvgStats;
69  //MovingAverage longAvgStats;
70 };
71 
72 THREAD_RET THREAD_FUNCTION_CALL RequestExecutorRun(THREAD_ARG arg);
73 
75 public:
76  friend THREAD_RET THREAD_FUNCTION_CALL ShortExecutorRun(THREAD_ARG arg);
77  friend THREAD_RET THREAD_FUNCTION_CALL LongExecutorRun(THREAD_ARG arg);
78  TestRequestExecutor(uint32 id);
79 protected:
80  bool shortRequestRun();
81  bool longRequestRun();
82  uint32 id;
83 };
84 
85 THREAD_RET THREAD_FUNCTION_CALL ShortExecutorRun(THREAD_ARG arg);
86 THREAD_RET THREAD_FUNCTION_CALL LongExecutorRun(THREAD_ARG arg);
87 
88 }
89 
90 #endif // _REQUESTEXECUTOR_H_
Definition: NetworkManager.h:47
Definition: Bitmap.h:7
Definition: NetworkManager.h:136
Definition: RequestExecutor.h:74
Definition: ThreadManager.h:33
Definition: RequestClient.h:127
Definition: Utils.h:299
Definition: RequestExecutor.h:16
Definition: NetworkManager.h:25
Definition: NetworkProtocols.h:81
Definition: Utils.h:529
Definition: NetworkManager.h:12
Definition: Utils.h:276
Definition: DataMessage.h:95