1 #ifndef B0__RESOLVER__RESOLVER_H__INCLUDED 2 #define B0__RESOLVER__RESOLVER_H__INCLUDED 5 #include <b0/protobuf/service_server.h> 6 #include <b0/protobuf/publisher.h> 11 #include <boost/thread.hpp> 12 #include <boost/format.hpp> 28 std::string thread_id;
30 boost::posix_time::ptime last_heartbeat;
31 std::vector<ServiceEntry*> services;
43 class ResolverServiceServer :
public b0::protobuf::ServiceServer<b0::resolver_msgs::Request, b0::resolver_msgs::Response>
46 ResolverServiceServer(Resolver *resolver);
51 void setPort(
int port);
62 virtual void announce()
override;
172 void pubProxy(
int xsub_proxy_port,
int xpub_proxy_port);
187 virtual std::string
address(std::string host,
int port);
192 virtual std::string
address(
int port);
197 virtual resolver::NodeEntry *
nodeByName(std::string node_name);
202 virtual resolver::ServiceEntry *
serviceByName(std::string service_name);
207 virtual void heartBeat(resolver::NodeEntry *node_entry);
323 b0::protobuf::Publisher<b0::resolver_msgs::Graph>
graph_pub_;
334 #endif // B0__RESOLVER__RESOLVER_H__INCLUDED This is the response returned by the resolver service.
Definition: resolver.proto:179
std::set< std::pair< std::string, std::string > > node_subscribes_topic_
Graph edges node <– topic.
Definition: resolver.h:314
void shutdown() override
Shutdown this node (set a flag such that Node::shutdownRequested() returns true)
void onNodeServiceUseStop(std::string node_name, std::string service_name)
void handleGetGraph(const b0::resolver_msgs::GetGraphRequest &req, b0::resolver_msgs::GetGraphResponse &resp)
Handle the GetGraph request.
void onNodeTopicSubscribeStart(std::string node_name, std::string topic_name)
virtual void handle(const b0::resolver_msgs::Request &req, b0::resolver_msgs::Response &resp)
Handle a service on the resolv service.
void pubProxy(int xsub_proxy_port, int xpub_proxy_port)
The XSUB/XPUB proxy (will be started in a separate thread)
Response to HeartBeatRequest message.
Definition: resolver.proto:90
virtual void handleAnnounceService(const b0::resolver_msgs::AnnounceServiceRequest &rq, b0::resolver_msgs::AnnounceServiceResponse &rsp)
Handle the AnnounceService request.
void onNodeConnected(std::string name)
bool nodeNameExists(std::string name)
Checks wether a node with this name exists in the connected nodes list.
b0::protobuf::Publisher< b0::resolver_msgs::Graph > graph_pub_
Publisher of the Graph message.
Definition: resolver.h:323
virtual void handleShutdownNode(const b0::resolver_msgs::ShutdownNodeRequest &rq, b0::resolver_msgs::ShutdownNodeResponse &rsp)
Handle the ShutdownNode request.
boost::thread pub_proxy_thread_
The thread running the ZeroMQ XSUB/XPUB proxy.
Definition: resolver.h:296
Response to NodeTopicRequest message.
Definition: resolver.proto:110
Response to ResolveServiceRequest message.
Definition: resolver.proto:73
void setOnlineMonitoring(bool enabled)
Enable or diable online node monitoring.
void onNodeServiceOfferStart(std::string node_name, std::string service_name)
void handleNodeTopic(const b0::resolver_msgs::NodeTopicRequest &req, b0::resolver_msgs::NodeTopicResponse &resp)
Handle the NodeTopic request.
Sent by node to tell a topic it is publishing onto/subscribing to.
Definition: resolver.proto:99
Sent by node to resolver, to announce its presence and try to self-assign a name. ...
Definition: resolver.proto:8
void onNodeServiceOfferStop(std::string node_name, std::string service_name)
The abstraction for a node in the network.
Definition: node.h:40
virtual void handleResolveService(const b0::resolver_msgs::ResolveServiceRequest &rq, b0::resolver_msgs::ResolveServiceResponse &rsp)
Handle the ResolveService request.
Sent by node to resolver when shutting down (it's not really a request buit rather a notification) ...
Definition: resolver.proto:29
Response to AnnounceServiceRequest message.
Definition: resolver.proto:57
virtual std::string address(std::string host, int port)
Format a tcp:// address.
void handleNodeService(const b0::resolver_msgs::NodeServiceRequest &req, b0::resolver_msgs::NodeServiceResponse &resp)
Handle the NodeService request.
Sent by ServiceServer to announce a service by some name The name must be unique. ...
Definition: resolver.proto:47
std::string xpub_proxy_addr_
Public address of the XPUB socket of the ZeroMQ proxy.
Definition: resolver.h:293
std::map< std::string, resolver::ServiceEntry * > services_by_name_
Map of services by name.
Definition: resolver.h:308
This is the message accepted by the resolver service.
Definition: resolver.proto:164
std::string xsub_proxy_addr_
Public address of the XSUB socket of the ZeroMQ proxy.
Definition: resolver.h:290
Response to NodeServiceRequest message.
Definition: resolver.proto:128
virtual resolver::NodeEntry * nodeByName(std::string node_name)
Get the NodeEntry given the node name.
std::set< std::pair< std::string, std::string > > node_offers_service_
Graph edges node –> service.
Definition: resolver.h:317
void getGraph(b0::resolver_msgs::Graph &graph)
virtual void notifyShutdown() override
Hijack notifyShutdown step.
The resolver node.
Definition: resolver.h:76
void onNodeDisconnected(std::string name)
Sent by resolver in reply to AnnounceNodeRequest message, to assign final name and give some connecti...
Definition: resolver.proto:17
void init() override
Perform node initialization.
Sent by node to tell a service it is offering.
Definition: resolver.proto:117
virtual void announceNode() override
Hijack announceNode step.
virtual std::string getXPUBSocketAddress() const override
Retrieve address of the proxy's XPUB socket.
std::set< std::pair< std::string, std::string > > node_uses_service_
Graph edges node <– service.
Definition: resolver.h:320
ResolverServiceServer resolv_server_
The ServiceServer serving the requests for the resolv protocol.
Definition: resolver.h:287
void onNodeTopicSubscribeStop(std::string node_name, std::string topic_name)
std::map< std::string, resolver::NodeEntry * > nodes_by_key_
Map of nodes by key.
Definition: resolver.h:305
Heartbeat sent by node to resolver.
Definition: resolver.proto:82
Sent by node to resolver, for getting the full graph.
Definition: resolver.proto:151
A complete graph of the network.
Definition: resolver.proto:141
std::map< std::string, resolver::NodeEntry * > nodes_by_name_
Map of nodes by name.
Definition: resolver.h:302
void onGraphChanged()
Called when the global graph changes.
virtual void setResolverPort(int port)
Set a specific port number to use (otherwise B0_RESOLVER_PORT will be used).
bool online_monitoring_
If false, silent nodes (i.e.
Definition: resolver.h:327
virtual resolver::ServiceEntry * serviceByName(std::string service_name)
Get the ServiceEntry given the service name.
boost::thread heartbeat_sweeper_thread_
The heartbeat sweeper thread.
Definition: resolver.h:299
virtual std::string getXSUBSocketAddress() const override
Retrieve address of the proxy's XSUB socket.
virtual ~Resolver()
Resolver node destructor.
Response to GetGraphRequest message.
Definition: resolver.proto:158
void heartBeatSweeper()
Code to run in the heartbeat sweeper thread.
Sent by resolver to node in reply to ShutdownNodeRequest (but probably will not be received) ...
Definition: resolver.proto:38
void onNodeTopicPublishStop(std::string node_name, std::string topic_name)
Sent by a ServiceClient to resolve a service name to a ZeroMQ address.
Definition: resolver.proto:65
void onNodeServiceUseStart(std::string node_name, std::string service_name)
virtual void handleHeartBeat(const b0::resolver_msgs::HeartBeatRequest &rq, b0::resolver_msgs::HeartBeatResponse &rsp)
Handle the HeartBeat request.
virtual void handleAnnounceNode(const b0::resolver_msgs::AnnounceNodeRequest &rq, b0::resolver_msgs::AnnounceNodeResponse &rsp)
Handle the AnnounceNode request.
std::string makeUniqueNodeName(std::string nodeName)
Adjust nodeName such that it is unique in the network (amongst the list of connected nodes) ...
Resolver()
Construct a resolver node.
void onNodeTopicPublishStart(std::string node_name, std::string topic_name)
virtual void heartBeat(resolver::NodeEntry *node_entry)
Update the NodeEntry timestamp.
std::set< std::pair< std::string, std::string > > node_publishes_topic_
Graph edges node –> topic.
Definition: resolver.h:311