Classes | |
class | ClientHeartbeat |
Handles heartbeating on the client side. Client heartbeat assumes only one connection (to the server), so sends and receives to one source only. More... | |
class | Delegator |
Requester object that takes jobs and returns results. Communicates with a delegator living in a (possibly) different thread. More... | |
struct | JobData |
Abstraction of job specification. More... | |
class | Message |
Define valid messages to send on the GDFP-SW (GDF Server-Worker Protocol) More... | |
class | Minion |
Minion object that requests a job, computes the result, then submits that result to the connected worker. More... | |
class | Requester |
Requester object that takes jobs and returns results. Communicates with a delegator living in a (possibly) different thread. More... | |
struct | ResultData |
Abstraction of job results. More... | |
class | ServerHeartbeat |
Handles heartbeating on the server side. Server heartbeat assumes that it has multiple connections from different clients, so sends to all of them, and keeps track of who is connected. More... | |
struct | SocketHandler |
Represents the callback signals for a socket. More... | |
class | SocketRouter |
Implements polling and configurable routing between an arbitrary number of (pre-constructed) zeromq sockets. Functionality is attached through a signal interface. More... | |
class | Worker |
Worker object that takes jobs, forwards them to a minion then receives results from the minion and send them back to the delegator. More... | |
Typedefs | |
typedef boost::bimap< SocketID, uint > | IndexBiMap |
A type that maps between indices in an array, and SocketID objects. | |
typedef std::set< std::string > | HBClients |
A set of clients being monitored for heartbeating. | |
typedef std::map< std::string, hrc::time_point > | HBMap |
A map of clients to when the last heartbeat arrived from that client. | |
Enumerations | |
enum | Subject : uint { HELLO = 0, HEARTBEAT = 1, PROBLEMSPEC = 2, JOBREQUEST = 3, JOB = 4, JOBSWAP = 5, ALLDONE = 6, GOODBYE = 7 } |
Defines the bytes actually sent in the subject frame of GDF messages. Allows us to use a switch statement on the subject. | |
enum | SocketID { REQUESTER, MINION, WORKER, NETWORK, HEARTBEAT, ALPHA, BETA } |
Enums to give each type of socket an index. | |
Functions | |
void | failedSend (const Message &m) |
Stop the heartbeat thread. This is called when the thread can't send to the local socket. | |
void | monitorTimeout (hrc::time_point &lastReceivedTime, SocketRouter &router, uint msTimeout) |
Update book-keeping on server heartbeats. Called every time the socket is polled. More... | |
void | heartbeatArrived (hrc::time_point &lastReceivedTime) |
Update book-keeping on server heartbeats. Called when the socket receives a heartbeat from the server. More... | |
void | sendHeartbeat (hrc::time_point &lastSendTime, SocketRouter &router, uint msFrequency) |
Send a heartbeat to the server if necessary. More... | |
std::vector< uint > | stringToIDs (const std::string &s) |
Convert list of uints in string form to vector of uint. | |
std::string | idsToString (const std::vector< uint > &ids) |
Convert vector of uints to list of uints in string form seperated by space. | |
std::string | subjectString (Subject s) |
Convert a subject into a string. More... | |
std::string | addressAsString (const std::vector< std::string > &addr) |
Convert an address to a string. More... | |
std::ostream & | operator<< (std::ostream &os, const Message &m) |
Print a message for logging and debugging purposes. More... | |
void | print (const Message &m) |
Print a message for logging and debugging purposes. More... | |
void | sendJob (zmq::socket_t &socket, const JobData &job) |
Send a job over a ZMQ socket. More... | |
void | sendJob (zmq::socket_t &socket, const std::vector< uint > &ids, const JobData &job) |
Send a job over a ZMQ socket. More... | |
ResultData | receiveResult (zmq::socket_t &socket) |
Read a job result from a socket. More... | |
std::pair< std::vector< uint > , ResultData > | receiveResultAndIDs (zmq::socket_t &socket) |
Read a job result from a socket. More... | |
std::ostream & | operator<< (std::ostream &os, const SocketID &id) |
Print a socket ID for logging and debugging purposes. More... | |
void | insertClient (const Message &m, HBClients &clients, HBMap &lastHeartbeats) |
Add a new client to be monitored for heartbeating. More... | |
void | deleteClient (const Message &m, HBClients &clients, HBMap &lastHeartbeats) |
Remove a client from being monitored for heartbeating. More... | |
void | failedSendServer (const Message &m) |
Stop the heartbeat thread. This is called when the thread can't send to the local socket. | |
void | receiveHeartbeat (const Message &m, HBMap &lastHeartbeats) |
Update book-keeping on client heartbeats. Called when a heartbeat message arrives from a client. More... | |
void | monitorTimeouts (HBClients &clients, HBMap &lastHeartbeats, SocketRouter &router, uint msTimeout) |
Update book-keeping on client heartbeats. Called every time the socket is polled. More... | |
void | sendHeartbeats (HBClients &clients, hrc::time_point &lastHbTime, SocketRouter &router, uint msFrequency) |
Send heartbeats to all the clients if necessary. More... | |
std::string | receiveString (zmq::socket_t &socket) |
Read a string form a ZMQ socket. This is a blocking call. More... | |
bool | sendString (zmq::socket_t &socket, const std::string &string) |
Send a string over a ZMQ socket. More... | |
bool | sendStringPart (zmq::socket_t &socket, const std::string &string) |
Send a string over a ZMQ socket as a chunk of a multipart message. More... | |
Message | receive (zmq::socket_t &socket) |
Receive a (possibly multi-part) message conforming to GDFP-SW comms protocal and provide it as a stateline::comms::Message class. More... | |
void | send (zmq::socket_t &socket, const Message &message) |
Send a (possibly multi-part) message conforming to GDFP-SW comms protocol. More... | |
std::string | randomSocketID () |
Computes a random socket ID conforming to zeromq requirements for the string (not starting with a zero etc, see zeromq doco). More... | |
void | setSocketID (const std::string &id, zmq::socket_t &socket) |
Sets the ID of a socket. The socket must be a DEALER or A REQ. More... | |
void | forwardToNetwork (const Message &m, SocketRouter &router) |
Forward a message to the delegator. More... | |
void | forwardToMinion (const Message &m, SocketRouter &router) |
Forward a message to a minion. More... | |
void | disconnectFromServer (const Message &m) |
Disconnect from the server with a message. More... | |
std::string | serialise (uint id) |
void | unserialise (const std::string &s, uint &id) |
void | unserialise (const std::string &s, std::vector< uint > &ids) |
std::string | serialise (const std::vector< uint > &ids) |
std::string | serialise (const mcmc::State &s) |
void | unserialise (const std::string &s, mcmc::State &g) |
Namespace for all communications functionality.
std::string stateline::comms::addressAsString | ( | const std::vector< std::string > & | addr | ) |
Convert an address to a string.
addr | The address to convert. |
void stateline::comms::deleteClient | ( | const Message & | m, |
HBClients & | clients, | ||
HBMap & | lastHeartbeats | ||
) |
Remove a client from being monitored for heartbeating.
m | The GOODBYE message from the client. |
clients | List of clients being monitored. |
lastHeartbeats | Map containing when the last heartbeat arrived from each client. |
void stateline::comms::disconnectFromServer | ( | const Message & | m | ) |
Disconnect from the server with a message.
m | The message to send to the server. |
void stateline::comms::forwardToMinion | ( | const Message & | m, |
SocketRouter & | router | ||
) |
Forward a message to a minion.
m | The message to forward. |
router | The socket router. |
void stateline::comms::forwardToNetwork | ( | const Message & | m, |
SocketRouter & | router | ||
) |
Forward a message to the delegator.
m | The message to forward. |
router | The socket router. |
void stateline::comms::heartbeatArrived | ( | hrc::time_point & | lastReceivedTime | ) |
Update book-keeping on server heartbeats. Called when the socket receives a heartbeat from the server.
lastReceivedTime | The time that the client last received a heartbeat from the server. |
void stateline::comms::insertClient | ( | const Message & | m, |
HBClients & | clients, | ||
HBMap & | lastHeartbeats | ||
) |
Add a new client to be monitored for heartbeating.
m | The HELLO message from the client. |
clients | List of clients being monitored. |
lastHeartbeats | Map containing when the last heartbeat arrived from each client. |
void stateline::comms::monitorTimeout | ( | hrc::time_point & | lastReceivedTime, |
SocketRouter & | router, | ||
uint | msTimeout | ||
) |
Update book-keeping on server heartbeats. Called every time the socket is polled.
lastReceivedTime | The time that the client last received a heartbeat from the server. |
router | A reference to the socket router. |
msTimeout | The heartbeat timeout in milliseconds. |
void stateline::comms::monitorTimeouts | ( | HBClients & | clients, |
HBMap & | lastHeartbeats, | ||
SocketRouter & | router, | ||
uint | msTimeout | ||
) |
Update book-keeping on client heartbeats. Called every time the socket is polled.
clients | List of clients being monitored. |
lastHeartbeats | Map containing when the last heartbeat arrived from each client. |
router | A reference to the socket router. |
msTimeout | The heartbeat timeout in milliseconds. |
std::ostream & stateline::comms::operator<< | ( | std::ostream & | os, |
const SocketID & | id | ||
) |
Print a socket ID for logging and debugging purposes.
os | The output stream. |
id | The socket ID to print. |
std::ostream & stateline::comms::operator<< | ( | std::ostream & | os, |
const Message & | m | ||
) |
Print a message for logging and debugging purposes.
Allows a message to be printed with std::cout.
os | The output stream. |
m | The message to print. |
void stateline::comms::print | ( | const Message & | m | ) |
Print a message for logging and debugging purposes.
m | The message to print. |
std::string stateline::comms::randomSocketID | ( | ) |
Computes a random socket ID conforming to zeromq requirements for the string (not starting with a zero etc, see zeromq doco).
Message stateline::comms::receive | ( | zmq::socket_t & | socket | ) |
Receive a (possibly multi-part) message conforming to GDFP-SW comms protocal and provide it as a stateline::comms::Message class.
socket | The socket the message is coming into. |
void stateline::comms::receiveHeartbeat | ( | const Message & | m, |
HBMap & | lastHeartbeats | ||
) |
Update book-keeping on client heartbeats. Called when a heartbeat message arrives from a client.
m | The HEARTBEAT message from the client. |
lastHeartbeats | Map containing when the last heartbeat arrived from each client. |
ResultData stateline::comms::receiveResult | ( | zmq::socket_t & | socket | ) |
Read a job result from a socket.
socket | The socket to read from. |
std::pair<std::vector<uint>, ResultData> stateline::comms::receiveResultAndIDs | ( | zmq::socket_t & | socket | ) |
Read a job result from a socket.
socket | The socket to read from. |
std::string stateline::comms::receiveString | ( | zmq::socket_t & | socket | ) |
Read a string form a ZMQ socket. This is a blocking call.
socket | The socket to read from. |
void stateline::comms::send | ( | zmq::socket_t & | socket, |
const Message & | message | ||
) |
Send a (possibly multi-part) message conforming to GDFP-SW comms protocol.
socket | The socket the message is coming into. |
message | The stateline::comms::Message to send. |
void stateline::comms::sendHeartbeat | ( | hrc::time_point & | lastSendTime, |
SocketRouter & | router, | ||
uint | msFrequency | ||
) |
Send a heartbeat to the server if necessary.
lastSendTime | The last time this client sent a heartbeat. |
router | A reference to the socket router. |
msFrequency | The number of milliseconds between each heartbeat. |
void stateline::comms::sendHeartbeats | ( | HBClients & | clients, |
hrc::time_point & | lastHbTime, | ||
SocketRouter & | router, | ||
uint | msFrequency | ||
) |
Send heartbeats to all the clients if necessary.
clients | List of clients being monitored. |
lastHbTime | The last time this thread sent out heartbeats. |
router | A reference to the socket router. |
msFrequency | The number of milliseconds between each heartbeat. |
void stateline::comms::sendJob | ( | zmq::socket_t & | socket, |
const JobData & | job | ||
) |
Send a job over a ZMQ socket.
socket | The socket to send the job over. |
job | The job to send. |
void stateline::comms::sendJob | ( | zmq::socket_t & | socket, |
const std::vector< uint > & | ids, | ||
const JobData & | job | ||
) |
Send a job over a ZMQ socket.
socket | The socket to send the job over. |
job | The job to send. |
bool stateline::comms::sendString | ( | zmq::socket_t & | socket, |
const std::string & | string | ||
) |
Send a string over a ZMQ socket.
socket | The socket to send the string over. |
string | The string data to send. |
bool stateline::comms::sendStringPart | ( | zmq::socket_t & | socket, |
const std::string & | string | ||
) |
Send a string over a ZMQ socket as a chunk of a multipart message.
socket | The socket to send the string over. |
string | The string data to send. |
void stateline::comms::setSocketID | ( | const std::string & | id, |
zmq::socket_t & | socket | ||
) |
Sets the ID of a socket. The socket must be a DEALER or A REQ.
id | The socket ID. |
socket | The socket that is being assigned the ID. |
std::string stateline::comms::subjectString | ( | Subject | s | ) |
Convert a subject into a string.
Identifies a particular message code, defined as a Subject enum.
s | The subject to convert. |
s | The subject enum being queried (a uint really). |