CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
RequestExecutor.h
Go to the documentation of this file.
1
23#if !defined(_REQUESTEXECUTOR_H_)
24#define _REQUESTEXECUTOR_H_
25
26#pragma once
27
28#include "NetworkManager.h"
29#include "RequestClient.h"
30
31
32namespace cmlabs{
33
35// Request Executor
37
74public:
76
79 RequestExecutor(uint32 id = 0, const char* name = NULL);
80 virtual ~RequestExecutor();
82 bool shutdownNetwork();
83
86 bool addLongRequestName(const char* name);
90 bool addGateway(uint32 id, std::string addr, uint16 port, uint8 encryption = NOENC);
93 bool setLongRequestLimit(uint32 limit);
94
96 bool receiveNetworkEvent(NetworkEvent* evt, NetworkChannel* channel, uint64 conid);
98 bool receiveMessage(DataMessage* msg, NetworkChannel* channel, uint64 conid);
100 bool receiveHTTPRequest(HTTPRequest* req, NetworkChannel* channel, uint64 conid) {return false;}
101
107 DataMessage* waitForLongRequest(uint32 timeoutMS);
113 DataMessage* waitForShortRequest(uint32 timeoutMS);
119 bool replyToQuery(DataMessage* msg);
120
121protected:
123 bool run();
125 uint32 sendStatusNow();
128
129 std::list<RequestGatewayConnection> connections;
130 //std::map<uint64, RequestGatewayConnection> gateways;
131
133 bool replyToGateway(DataMessage* msg);
134
135 uint32 executorID;
136 std::string executorName;
142 std::map<uint64,RequestReply*> requestMap;
143 std::vector<std::string> longReqNames;
148 uint32 threadID;
149 uint64 lastRefID;
151 uint64 sentCount;
157 //MovingAverage shortAvgStats;
158 //MovingAverage longAvgStats;
159};
160
163
168public:
171 TestRequestExecutor(uint32 id, uint32 processTimeMS);
172protected:
173 bool shortRequestRun();
174 bool longRequestRun();
175 uint32 id;
177};
178
181
182}
183
184#endif // _REQUESTEXECUTOR_H_
#define NOENC
Plain, unencrypted transport.
Connection/channel management layer: multi-protocol listeners, typed dispatch, HTTP client — and the ...
Request-system client side: RequestReply futures, RequestQueue, gateway connection records and the Re...
#define THREAD_RET
Definition Utils.h:127
#define THREAD_FUNCTION_CALL
Definition Utils.h:129
#define THREAD_ARG
Definition Utils.h:130
The central Psyclone data container: a self-contained binary message with typed, named user entries.
A parsed or generated HTTP request (also used for WebSocket upgrade handshakes).
One logical network interface: a group of listeners/connections with shared dispatch.
Central owner of all channels, listeners and connections in a process.
uint64 lastHeartbeat
Time of last heartbeat (ms epoch).
uint64 longReceivedCount
Total long requests received.
uint32 sendStatusNow()
Send a status heartbeat (queue sizes) to all gateways.
bool replyToQuery(DataMessage *msg)
Send a reply for a previously pulled request back to its gateway.
bool shutdownNetwork()
Disconnect from all gateways and stop the network stack.
utils::WaitQueuePointer< DataMessage * > replyQ
Outgoing replies awaiting dispatch.
utils::Semaphore shortExecQSemaphore
Signals short-queue arrivals.
DataMessage * waitForShortRequest(uint32 timeoutMS)
Pull the next short request (worker thread API).
utils::Mutex mutex
Guards request bookkeeping.
NetworkManager * manager
Owned network stack.
bool replyToGateway(DataMessage *msg)
Route a finished reply to the gateway that sent the request.
std::string executorName
Display name for logging.
bool run()
Worker loop: gateway upkeep, heartbeats, reply dispatch.
uint32 threadID
Worker thread id.
uint64 shortReceivedCount
Total short requests received.
utils::WaitQueuePointer< DataMessage * > shortExecQ
Pending short requests.
int32 heartbeatIntervalMS
Interval between status heartbeats (ms).
std::map< uint64, RequestReply * > requestMap
In-flight request bookkeeping by ref id.
bool receiveMessage(DataMessage *msg, NetworkChannel *channel, uint64 conid)
NetworkReceiver hook: incoming request messages, routed to the short/long queue.
uint64 sentCount
Total messages sent to gateways.
bool receiveHTTPRequest(HTTPRequest *req, NetworkChannel *channel, uint64 conid)
HTTP is not served by executors; always returns false.
bool addGateway(uint32 id, std::string addr, uint16 port, uint8 encryption=NOENC)
Register a gateway to connect to (repeatable for redundancy).
DataMessage * waitForLongRequest(uint32 timeoutMS)
Pull the next long request (worker thread API).
bool setLongRequestLimit(uint32 limit)
Cap the number of long requests processed concurrently.
utils::Mutex conMutex
Guards connections.
std::vector< std::string > longReqNames
Request names classified as long.
bool receiveNetworkEvent(NetworkEvent *evt, NetworkChannel *channel, uint64 conid)
NetworkReceiver hook: gateway connect/disconnect events (drives reconnection).
bool sendMessageToGateway(DataMessage *msg, RequestGatewayConnection &con)
Send a message on one gateway link.
NetworkChannel * channel
Channel carrying the gateway links.
uint32 executorID
Numeric id reported to gateways.
utils::Semaphore longExecQSemaphore
Signals long-queue arrivals.
utils::WaitQueuePointer< DataMessage * > longExecQ
Pending long requests.
std::list< RequestGatewayConnection > connections
Configured gateways and their state.
uint32 longReqLimit
Max concurrent long requests (see setLongRequestLimit()).
uint64 lastRefID
Last issued executor reference id.
bool addLongRequestName(const char *name)
Register a request name to be treated as a long-running request.
friend THREAD_RET THREAD_FUNCTION_CALL RequestExecutorRun(THREAD_ARG arg)
Thread entry point for the RequestExecutor worker loop.
RequestExecutor(uint32 id=0, const char *name=NULL)
uint64 repliedCount
Total replies sent.
Runnable()
Initialise flags: not running, allowed to continue.
friend THREAD_RET THREAD_FUNCTION_CALL ShortExecutorRun(THREAD_ARG arg)
TestRequestExecutor(uint32 id, uint32 processTimeMS)
friend THREAD_RET THREAD_FUNCTION_CALL LongExecutorRun(THREAD_ARG arg)
Recursive mutual-exclusion lock, optionally named for cross-process use.
Definition Utils.h:463
Counting semaphore, optionally named for cross-process use.
Definition Utils.h:502
WaitQueue specialization for owned heap pointers: clear()/destructor delete remaining entries.
Definition Utils.h:823
THREAD_RET THREAD_FUNCTION_CALL RequestExecutorRun(THREAD_ARG arg)
Thread entry point for the RequestExecutor worker loop.
THREAD_RET THREAD_FUNCTION_CALL ShortExecutorRun(THREAD_ARG arg)
THREAD_RET THREAD_FUNCTION_CALL LongExecutorRun(THREAD_ARG arg)
Notification of a connection lifecycle change (connect, disconnect, buffer state.....
Client/executor-side record of one gateway it connects to.