CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
RequestClient.h File Reference

Request-system client side: RequestReply futures, RequestQueue, gateway connection records and the RequestClient itself. More...

#include "NetworkManager.h"
#include "MovingAverage.h"
#include "jsmn.h"
Include dependency graph for RequestClient.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  cmlabs::RequestReply
 Future/handle for one in-flight request: holds the request message, the eventual reply, status, timing and routing references. More...
class  cmlabs::RequestQueue
 Priority-ordered queue of pending RequestReply objects (per executor connection). More...
struct  cmlabs::RequestConnection
 Gateway-side record of one connected client or executor. More...
struct  cmlabs::RequestGatewayConnection
 Client/executor-side record of one gateway it connects to. More...
class  cmlabs::RequestClient
 Application-facing client of the request system: posts DataMessage requests to one or more RequestGateways and delivers replies. More...
class  cmlabs::TestRequestClient
 Load-test client driving a RequestGateway with binary-protocol requests at a configurable frequency/payload (used by RequestGateway::UnitTest()). More...
class  cmlabs::TestWebRequestClient
 Load-test client driving a RequestGateway over plain HTTP web requests. More...
class  cmlabs::TestWebSocketRequestClient
 Load-test client driving a RequestGateway over WebSocket connections. More...

Namespaces

namespace  cmlabs

Typedefs

typedef void(* cmlabs::RequestCallbackFunction) (RequestReply &reply)
 Signature for asynchronous completion callbacks registered on a RequestReply.

Enumerations

enum  cmlabs::RequestStatus {
  cmlabs::NONE = 0 , cmlabs::IDLE = 1 , cmlabs::QUEUED = 2 , cmlabs::PROCESSING = 3 ,
  cmlabs::SENT = 4 , cmlabs::SUCCESS = 5 , cmlabs::FAILED = 6 , cmlabs::TIMEOUT = 7 ,
  cmlabs::TOOBUSY = 8 , cmlabs::LOCALERROR = 9 , cmlabs::NETWORKERROR = 10 , cmlabs::SERVERERROR = 11
}
 Lifecycle states of a request as it moves through client, gateway and executor. More...

Functions

THREAD_RET THREAD_FUNCTION_CALL cmlabs::RequestClientRun (THREAD_ARG arg)
 Thread entry point for the RequestClient worker loop.
THREAD_RET THREAD_FUNCTION_CALL cmlabs::TestRequestClientRun (THREAD_ARG arg)
THREAD_RET THREAD_FUNCTION_CALL cmlabs::TestWebRequestClientRun (THREAD_ARG arg)
THREAD_RET THREAD_FUNCTION_CALL cmlabs::TestWebSocketRequestClientRun (THREAD_ARG arg)

Detailed Description

Request-system client side: RequestReply futures, RequestQueue, gateway connection records and the RequestClient itself.

The CMSDK request system is a distributed request/response fabric built on the message protocol of NetworkManager. Three roles cooperate:

  • RequestClient (this file): application-facing. Wraps each outgoing DataMessage in a RequestReply "future", sends it to a RequestGateway and lets the caller either block on waitForResult() or register a callback.
  • RequestGateway (RequestGateway.h): the router/load balancer. Accepts requests from many clients (binary, HTTP or WebSocket), queues them, picks the best RequestExecutor (short vs long requests, queue sizes, heartbeats) and routes replies back to the originating client.
  • RequestExecutor (RequestExecutor.h): the worker/server. Pulls requests from its gateway connection, processes them and replies.

A request round-trip looks like this:

RequestClient client;
client.addGateway(1, "gateway.host", 9000); // connect to a gateway
client.waitForConnection(5000);
DataMessage* msg = RequestClient::CreateRequestMessage(
HTTP_GET, "status", "detail", "full"); // build the request
RequestReply* reply = client.postRequest(msg); // async send
if (reply->waitForResult(3000) == SUCCESS) { // block for the answer
DataMessage* answer = reply->peekReplyMessage(); // owned by reply
// ... use answer ...
}
client.finishRequest(reply); // release the slot
#define HTTP_GET
GET.

Clients keep a list of gateways (RequestGatewayConnection) and reconnect automatically; requests survive brief gateway outages by re-queuing.

Definition in file RequestClient.h.