BlueZero (BØ)
Middleware for distributed applications
|
The resolver node. More...
#include <b0/resolver/resolver.h>
Public Member Functions | |
Resolver () | |
Construct a resolver node. | |
virtual | ~Resolver () |
Resolver node destructor. | |
void | init () override |
Perform node initialization. | |
void | shutdown () override |
Shutdown this node (set a flag such that Node::shutdownRequested() returns true) | |
virtual std::string | getXPUBSocketAddress () const override |
Retrieve address of the proxy's XPUB socket. | |
virtual std::string | getXSUBSocketAddress () const override |
Retrieve address of the proxy's XSUB socket. | |
virtual void | announceNode () override |
Hijack announceNode step. | |
virtual void | notifyShutdown () override |
Hijack notifyShutdown step. | |
void | onNodeConnected (std::string name) |
void | onNodeDisconnected (std::string name) |
void | onNodeTopicPublishStart (std::string node_name, std::string topic_name) |
void | onNodeTopicPublishStop (std::string node_name, std::string topic_name) |
void | onNodeTopicSubscribeStart (std::string node_name, std::string topic_name) |
void | onNodeTopicSubscribeStop (std::string node_name, std::string topic_name) |
void | onNodeServiceOfferStart (std::string node_name, std::string service_name) |
void | onNodeServiceOfferStop (std::string node_name, std::string service_name) |
void | onNodeServiceUseStart (std::string node_name, std::string service_name) |
void | onNodeServiceUseStop (std::string node_name, std::string service_name) |
void | pubProxy (int xsub_proxy_port, int xpub_proxy_port) |
The XSUB/XPUB proxy (will be started in a separate thread) | |
bool | nodeNameExists (std::string name) |
Checks wether a node with this name exists in the connected nodes list. | |
virtual void | setResolverPort (int port) |
Set a specific port number to use (otherwise B0_RESOLVER_PORT will be used). | |
virtual std::string | address (std::string host, int port) |
Format a tcp:// address. | |
virtual std::string | address (int port) |
Format a tcp:// bind address. | |
virtual resolver::NodeEntry * | nodeByName (std::string node_name) |
Get the NodeEntry given the node name. | |
virtual resolver::ServiceEntry * | serviceByName (std::string service_name) |
Get the ServiceEntry given the service name. | |
virtual void | heartBeat (resolver::NodeEntry *node_entry) |
Update the NodeEntry timestamp. | |
virtual void | handle (const b0::resolver_msgs::Request &req, b0::resolver_msgs::Response &resp) |
Handle a service on the resolv service. | |
std::string | makeUniqueNodeName (std::string nodeName) |
Adjust nodeName such that it is unique in the network (amongst the list of connected nodes) | |
virtual void | handleAnnounceNode (const b0::resolver_msgs::AnnounceNodeRequest &rq, b0::resolver_msgs::AnnounceNodeResponse &rsp) |
Handle the AnnounceNode request. | |
virtual void | handleShutdownNode (const b0::resolver_msgs::ShutdownNodeRequest &rq, b0::resolver_msgs::ShutdownNodeResponse &rsp) |
Handle the ShutdownNode request. | |
virtual void | handleAnnounceService (const b0::resolver_msgs::AnnounceServiceRequest &rq, b0::resolver_msgs::AnnounceServiceResponse &rsp) |
Handle the AnnounceService request. | |
virtual void | handleResolveService (const b0::resolver_msgs::ResolveServiceRequest &rq, b0::resolver_msgs::ResolveServiceResponse &rsp) |
Handle the ResolveService request. | |
virtual void | handleHeartBeat (const b0::resolver_msgs::HeartBeatRequest &rq, b0::resolver_msgs::HeartBeatResponse &rsp) |
Handle the HeartBeat request. | |
void | handleNodeTopic (const b0::resolver_msgs::NodeTopicRequest &req, b0::resolver_msgs::NodeTopicResponse &resp) |
Handle the NodeTopic request. | |
void | handleNodeService (const b0::resolver_msgs::NodeServiceRequest &req, b0::resolver_msgs::NodeServiceResponse &resp) |
Handle the NodeService request. | |
void | handleGetGraph (const b0::resolver_msgs::GetGraphRequest &req, b0::resolver_msgs::GetGraphResponse &resp) |
Handle the GetGraph request. | |
void | getGraph (b0::resolver_msgs::Graph &graph) |
void | onGraphChanged () |
Called when the global graph changes. More... | |
void | heartBeatSweeper () |
Code to run in the heartbeat sweeper thread. | |
void | setOnlineMonitoring (bool enabled) |
Enable or diable online node monitoring. More... | |
Public Member Functions inherited from b0::Node | |
Node (std::string nodeName="") | |
Create a node with a given name. More... | |
virtual | ~Node () |
Destruct this node. More... | |
void | setResolverAddress (const std::string &addr) |
Specify a different value for the resolver address. Otherwise B0_RESOLVER env var is used. | |
bool | shutdownRequested () const |
Return wether shutdown has requested (by Node::shutdown() method or by pressing CTRL-C) | |
virtual void | spinOnce () |
Read all available messages from the various ZeroMQ sockets, and dispatch them to callbacks. More... | |
virtual void | spin (double spinRate=10.0) |
Run the spin loop (continuously call spinOnce(), at the specified rate, and call cleanup() at the end) More... | |
virtual void | cleanup () |
Node cleanup: stop all threads, send a shutdown notification to resolver, and so on... | |
void | log (LogLevel level, std::string message) const override |
Log a message to the default logger of this node. | |
std::string | getName () const |
Get the name assigned by resolver to this node. | |
NodeState | getState () const |
Get the state of this node. | |
void * | getContext () |
Get the ZeroMQ Context. | |
virtual std::string | hostname () |
Return the public address (IP or hostname) to reach this node on the network. | |
virtual int | pid () |
Return the process id of this node. | |
virtual std::string | threadID () |
Return the thread identifier of this node. | |
virtual int | freeTCPPort () |
Find and return an available TCP port. | |
virtual void | notifyTopic (std::string topic_name, bool reverse, bool active) |
Notify topic publishing/subscription start or end. | |
virtual void | notifyService (std::string service_name, bool reverse, bool active) |
Notify service advertising/use start or end. | |
virtual void | announceService (std::string service_name, std::string addr) |
Announce service address. | |
virtual void | resolveService (std::string service_name, std::string &addr) |
Resolve service address by name. | |
virtual void | setAnnounceTimeout (int timeout=-1) |
Set the timeout for the announce phase. See b0::resolver::Client::setAnnounceTimeout() | |
int64_t | hardwareTimeUSec () const |
Return this computer's clock time in microseconds. | |
int64_t | timeUSec () |
Return the adjusted time in microseconds. See Time Synchronization for details. | |
Public Member Functions inherited from b0::logger::LogInterface | |
template<typename... Arguments> | |
void | log (LogLevel level, std::string const &fmt, Arguments &&... args) const |
Log a message using a format string. | |
Protected Attributes | |
ResolverServiceServer | resolv_server_ |
The ServiceServer serving the requests for the resolv protocol. | |
std::string | xsub_proxy_addr_ |
Public address of the XSUB socket of the ZeroMQ proxy. | |
std::string | xpub_proxy_addr_ |
Public address of the XPUB socket of the ZeroMQ proxy. | |
boost::thread | pub_proxy_thread_ |
The thread running the ZeroMQ XSUB/XPUB proxy. | |
boost::thread | heartbeat_sweeper_thread_ |
The heartbeat sweeper thread. | |
std::map< std::string, resolver::NodeEntry * > | nodes_by_name_ |
Map of nodes by name. | |
std::map< std::string, resolver::NodeEntry * > | nodes_by_key_ |
Map of nodes by key. | |
std::map< std::string, resolver::ServiceEntry * > | services_by_name_ |
Map of services by name. | |
std::set< std::pair< std::string, std::string > > | node_publishes_topic_ |
Graph edges node –> topic. | |
std::set< std::pair< std::string, std::string > > | node_subscribes_topic_ |
Graph edges node <– topic. | |
std::set< std::pair< std::string, std::string > > | node_offers_service_ |
Graph edges node –> service. | |
std::set< std::pair< std::string, std::string > > | node_uses_service_ |
Graph edges node <– service. | |
b0::protobuf::Publisher< b0::resolver_msgs::Graph > | graph_pub_ |
Publisher of the Graph message. | |
bool | online_monitoring_ |
If false, silent nodes (i.e. More... | |
Protected Attributes inherited from b0::Node | |
std::string | resolv_addr_ |
Target address of resolver client. | |
logger::LogInterface * | p_logger_ |
The logger of this node. | |
Additional Inherited Members | |
Public Types inherited from b0::logger::LogInterface | |
enum | LogLevel { trace = 0, debug = 10, info = 20, warn = 30, error = 40, fatal = 50 } |
Protected Member Functions inherited from b0::Node | |
virtual void | startHeartbeatThread () |
Start the heartbeat thread. More... | |
virtual std::string | freeTCPAddress () |
Find and return an available tcp address, e.g. tcp://hostname:portnumber. | |
virtual void | heartbeatLoop () |
The heartbeat message loop (run in its own thread) | |
The resolver node.
void b0::resolver::Resolver::getGraph | ( | b0::resolver_msgs::Graph & | graph | ) |
Retrieve the current Graph
void b0::resolver::Resolver::onGraphChanged | ( | ) |
Called when the global graph changes.
Due to a node publishing or subscribing a topic, or offering or using a service.
void b0::resolver::Resolver::onNodeConnected | ( | std::string | name | ) |
Called when a new node has connected
void b0::resolver::Resolver::onNodeDisconnected | ( | std::string | name | ) |
Called when a node disconnects (detected with heartbeat timeout)
void b0::resolver::Resolver::onNodeServiceOfferStart | ( | std::string | node_name, |
std::string | service_name | ||
) |
Called when a node starts offering a service
void b0::resolver::Resolver::onNodeServiceOfferStop | ( | std::string | node_name, |
std::string | service_name | ||
) |
Called when a node stops offering a service
void b0::resolver::Resolver::onNodeServiceUseStart | ( | std::string | node_name, |
std::string | service_name | ||
) |
Called when a node starts using a service
void b0::resolver::Resolver::onNodeServiceUseStop | ( | std::string | node_name, |
std::string | service_name | ||
) |
Called when a node stops using a service
void b0::resolver::Resolver::onNodeTopicPublishStart | ( | std::string | node_name, |
std::string | topic_name | ||
) |
Called when a node starts publishing to a topic
void b0::resolver::Resolver::onNodeTopicPublishStop | ( | std::string | node_name, |
std::string | topic_name | ||
) |
Called when a node stops publishing to a topic
void b0::resolver::Resolver::onNodeTopicSubscribeStart | ( | std::string | node_name, |
std::string | topic_name | ||
) |
Called when a node starts subscribing to a topic
void b0::resolver::Resolver::onNodeTopicSubscribeStop | ( | std::string | node_name, |
std::string | topic_name | ||
) |
Called when a node stops subscribing to a topic
void b0::resolver::Resolver::setOnlineMonitoring | ( | bool | enabled | ) |
Enable or diable online node monitoring.
When disabled, silent nodes (i.e. node not sending a heartbeat withing the required time window) will not be regarded as "dead" and will not be purged.
|
protected |
If false, silent nodes (i.e.
not sending heartbeats) will not be considered as dead and will not be purged.