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

Request-system router: RequestGateway accepts client requests (binary/HTTP/WebSocket), load-balances them across RequestExecutors and routes replies back; includes a call log and an embedded web server. More...

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

Go to the source code of this file.

Classes

class  cmlabs::CallLogEntry
 One entry of the gateway's call log: who called what, how it was routed, how long each stage took, and the outcome. More...
class  cmlabs::RequestGateway
 The request-fabric router/load-balancer (see the file header for the full role description). More...

Namespaces

namespace  cmlabs

Functions

THREAD_RET THREAD_FUNCTION_CALL cmlabs::RequestGatewayExecRun (THREAD_ARG arg)
 Thread entry point for the gateway's executor-side loop.
THREAD_RET THREAD_FUNCTION_CALL cmlabs::RequestGatewayClientRun (THREAD_ARG arg)
 Thread entry point for the gateway's client-side loop.

Detailed Description

Request-system router: RequestGateway accepts client requests (binary/HTTP/WebSocket), load-balances them across RequestExecutors and routes replies back; includes a call log and an embedded web server.

The gateway is the hub of the request fabric (see RequestClient.h for the conceptual overview and a round-trip example). One process typically runs one RequestGateway listening on one or more ports (addPort()); clients and executors connect in to it (a gateway may additionally link to other gateways via addGateway(), but it never dials out to clients or executors), which simplifies firewalling.

Responsibilities:

  • Ingress: accepts requests over the binary message protocol (RequestClient), plain HTTP(S) and WebSocket — all on the same ports via protocol auto-detection. HTTP requests are converted to DataMessages and travel the same internal path.
  • Routing / load balancing: getBestExecutorID() picks an executor per request based on reported queue sizes, latency stats and the short/long classification; queuing behaviour is tuned with setQueuingParameters() (max queue size, max processing set, priority threshold).
  • Liveness: executors heartbeat periodically; one missing beyond setExecutorHeartbeatTimeout() is declared dead, its queued requests are redistributed (distributeDeadExecutorRequests()) and it may be asked to restart (sendRestartToExecutor()).
  • Web serving + APIs: a built-in file web server (rootdir/index via setWebServerInfo()) plus internal/external HTTP API surfaces and optional basic-auth users (addAuthUser()).
  • Audit: every call is recorded as a CallLogEntry for diagnostics.

A minimal gateway serving binary clients, web traffic and executors on one port looks like this:

RequestGateway gw;
gw.setWebServerInfo("MyGateway", "./wwwroot", "index.html"); // name + static files
gw.setExecutorHeartbeatTimeout(5000); // declare dead after 5s silence
gw.addPort(9000, NOENC, true); // clients + executors + HTTP on one port
// ... RequestExecutors addGateway(id, host, 9000) and start pulling work;
// ... RequestClients addGateway(id, host, 9000) and postRequest().
#define NOENC
Plain, unencrypted transport.

Definition in file RequestGateway.h.