NRP Core  1.4.1
EngineJSONRegistrationServer Class Reference

Singleton. Creates an HTTP REST server to register newly created EngineJSONServers and store their addresses. More...

#include <engine_json_registration_server.h>

Public Member Functions

 EngineJSONRegistrationServer (const EngineJSONRegistrationServer &)=delete
 
 EngineJSONRegistrationServer (EngineJSONRegistrationServer &&)=delete
 
EngineJSONRegistrationServeroperator= (const EngineJSONRegistrationServer &)=delete
 
EngineJSONRegistrationServeroperator= (EngineJSONRegistrationServer &&)=delete
 
 ~EngineJSONRegistrationServer ()
 
void startServerAsync ()
 Start the server if it's not already running. More...
 
void shutdownServer ()
 Stop the Server. More...
 
const std::string serverAddress () const
 Get server address. More...
 
bool isRunning () const
 Returns true when server is running, false otherwise. More...
 
size_t getNumWaitingEngines ()
 Get the number of engines that are still waiting for registration. More...
 
std::string retrieveEngineAddress (const engine_name_t &engineName)
 Retrieve a registered engine address. If available and non-empty, erase it from _registeredAddresses. More...
 
std::string requestEngine (const engine_name_t &engineName)
 Request an engine's address. If available, erases entry from _registeredAddresses. More...
 
void registerEngineAddress (const engine_name_t &engineName, const std::string &address)
 Register an engine's address. More...
 

Static Public Member Functions

static EngineJSONRegistrationServergetInstance ()
 Get Instance of EngineJSONRegistrationServer. More...
 
static EngineJSONRegistrationServerresetInstance (const std::string &serverAddress)
 Reset EngineJSONRegistrationServer with the given address. More...
 
static void clearInstance ()
 Delete Instance. More...
 
static std::string tryInstantiate (const std::string &initialAddress, const unsigned numRetries)
 Attempts to instantiate and start the registration server. More...
 
static bool sendClientEngineRequest (const std::string &address, const engine_name_t &engineName, const std::string &engineAddress, const unsigned int numTries=1, const unsigned int waitTime=0)
 Send Engine Name and address to specified address. More...
 

Static Public Attributes

static constexpr std::string_view JSONEngineName = "engine_name"
 JSON Engine Name locator used during registration. More...
 
static constexpr std::string_view JSONAddress = "address"
 JSON Engine Address locator used during registration. More...
 

Friends

struct EngineJSONRegistrationServer::RequestHandler
 

Detailed Description

Singleton. Creates an HTTP REST server to register newly created EngineJSONServers and store their addresses.

Constructor & Destructor Documentation

◆ EngineJSONRegistrationServer() [1/2]

EngineJSONRegistrationServer::EngineJSONRegistrationServer ( const EngineJSONRegistrationServer )
delete

◆ EngineJSONRegistrationServer() [2/2]

EngineJSONRegistrationServer::EngineJSONRegistrationServer ( EngineJSONRegistrationServer &&  )
delete

◆ ~EngineJSONRegistrationServer()

EngineJSONRegistrationServer::~EngineJSONRegistrationServer ( )

Member Function Documentation

◆ clearInstance()

void EngineJSONRegistrationServer::clearInstance ( )
static

Delete Instance.

◆ getInstance()

EngineJSONRegistrationServer * EngineJSONRegistrationServer::getInstance ( )
static

Get Instance of EngineJSONRegistrationServer.

Returns
Returns ptr to EngineJSONRegistrationServer if it exists, nullptr otherwise

◆ getNumWaitingEngines()

size_t EngineJSONRegistrationServer::getNumWaitingEngines ( )

Get the number of engines that are still waiting for registration.

◆ isRunning()

bool EngineJSONRegistrationServer::isRunning ( ) const

Returns true when server is running, false otherwise.

◆ operator=() [1/2]

EngineJSONRegistrationServer& EngineJSONRegistrationServer::operator= ( const EngineJSONRegistrationServer )
delete

◆ operator=() [2/2]

EngineJSONRegistrationServer& EngineJSONRegistrationServer::operator= ( EngineJSONRegistrationServer &&  )
delete

◆ registerEngineAddress()

void EngineJSONRegistrationServer::registerEngineAddress ( const engine_name_t &  engineName,
const std::string &  address 
)

Register an engine's address.

Parameters
engineNameName of engine
addressAddress of engine

◆ requestEngine()

std::string EngineJSONRegistrationServer::requestEngine ( const engine_name_t &  engineName)

Request an engine's address. If available, erases entry from _registeredAddresses.

Parameters
engineNameName of engine to wait for
Returns
If available, returns name of engine. Else, returns empty string

◆ resetInstance()

EngineJSONRegistrationServer * EngineJSONRegistrationServer::resetInstance ( const std::string &  serverAddress)
static

Reset EngineJSONRegistrationServer with the given address.

Parameters
serverAddressServer Address to bind to
Returns
Returns pointer to created instance

◆ retrieveEngineAddress()

std::string EngineJSONRegistrationServer::retrieveEngineAddress ( const engine_name_t &  engineName)

Retrieve a registered engine address. If available and non-empty, erase it from _registeredAddresses.

Parameters
engineNameEngine Name for which to find the address
Returns
If address available, return it. Otherwise return empty string

◆ sendClientEngineRequest()

bool EngineJSONRegistrationServer::sendClientEngineRequest ( const std::string &  address,
const engine_name_t &  engineName,
const std::string &  engineAddress,
const unsigned int  numTries = 1,
const unsigned int  waitTime = 0 
)
static

Send Engine Name and address to specified address.

Parameters
addressAddress to send data to
engineNameName of engine
engineAddressAddress of engine
numTriesNumber of times to try and contact the registration server
waitTimeTime (in seconds) to wait between contact attempts
Returns
Returns true on success, false otherwise

◆ serverAddress()

const std::string EngineJSONRegistrationServer::serverAddress ( ) const

Get server address.

◆ shutdownServer()

void EngineJSONRegistrationServer::shutdownServer ( )

Stop the Server.

◆ startServerAsync()

void EngineJSONRegistrationServer::startServerAsync ( )

Start the server if it's not already running.

◆ tryInstantiate()

std::string EngineJSONRegistrationServer::tryInstantiate ( const std::string &  initialAddress,
const unsigned  numRetries = 0 
)
static

Attempts to instantiate and start the registration server.

Parameters
initialAddressInitial address that the server will try to use
numRetriesMaximum number of attempts to start the server
Returns
The actual address of the server. If the first attempt to start was successful, then it will be the initialAddress. Otherwise, the address will consist of the hostname from the initialAddress and a random port.
Exceptions
WhennumRetires has been exceeded.

The function will try to start the registration server at the given address. If the initial attempt fails, then the function will try again, until numRetries limit is exceeded. On every attempt, except for the first one, the address will be modified. The host will be taken from the initialAddress argument, but the port will be changed - the function will ask the OS to provide an unused port for the server.

Friends And Related Function Documentation

◆ EngineJSONRegistrationServer::RequestHandler

friend struct EngineJSONRegistrationServer::RequestHandler
friend

Member Data Documentation

◆ JSONAddress

constexpr std::string_view EngineJSONRegistrationServer::JSONAddress = "address"
staticconstexpr

JSON Engine Address locator used during registration.

◆ JSONEngineName

constexpr std::string_view EngineJSONRegistrationServer::JSONEngineName = "engine_name"
staticconstexpr

JSON Engine Name locator used during registration.


The documentation for this class was generated from the following files: