BlueZero (BØ)
Middleware for distributed applications
|
The abstraction for a node in the network. More...
#include <b0/node.h>
Public Member Functions | |
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. | |
virtual void | init () |
Initialize the node (connect to resolve, start heartbeat, announce node name) More... | |
virtual void | shutdown () |
Shutdown the node (stop all running threads, send shutdown notification) More... | |
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 | getXPUBSocketAddress () const |
Retrieve address of the proxy's XPUB socket. | |
virtual std::string | getXSUBSocketAddress () const |
Retrieve address of the proxy's XSUB socket. | |
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 Member Functions | |
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 | announceNode () |
Announce this node to resolver. | |
virtual void | notifyShutdown () |
Notify resolver of this node shutdown. | |
virtual void | heartbeatLoop () |
The heartbeat message loop (run in its own thread) | |
Protected Attributes | |
std::string | resolv_addr_ |
Target address of resolver client. | |
logger::LogInterface * | p_logger_ |
The logger of this node. | |
Friends | |
class | Socket |
Additional Inherited Members | |
Public Types inherited from b0::logger::LogInterface | |
enum | LogLevel { trace = 0, debug = 10, info = 20, warn = 30, error = 40, fatal = 50 } |
The abstraction for a node in the network.
You must create at most one node per thread. You can have many nodes in one process by creating several threads.
b0::Node::Node | ( | std::string | nodeName = "" | ) |
Create a node with a given name.
nodeName | the name of the node |
Create a node with a given name.
A message will be send to resolver to announce this node presence on the network. If a node with the same name already exists in the network, this node will get a different name.
The heartbeat thread will be started to let resolver track the online status of this node.
|
virtual |
Destruct this node.
Any threads, such as the heartbeat thread, will be stopped, and the sockets will be freeed.
|
virtual |
Initialize the node (connect to resolve, start heartbeat, announce node name)
If you need to extend the init phase, when overriding it in your subclass, remember to first call this Node::init() (unless you know what you are doing).
Reimplemented in b0::resolver::Resolver.
|
virtual |
Shutdown the node (stop all running threads, send shutdown notification)
If you need to perform additional cleanup, when overriding this method in your subclass, remember to first call this Node::shutdown() (unless you know what you are doing).
Reimplemented in b0::resolver::Resolver.
|
virtual |
Run the spin loop (continuously call spinOnce(), at the specified rate, and call cleanup() at the end)
spinRate | the approximate frequency (in Hz) at which spinOnce() will be called |
|
virtual |
Read all available messages from the various ZeroMQ sockets, and dispatch them to callbacks.
This method will call b0::Subscriber::spinOnce() and b0::ServiceServer::spinOnce() on the subscribers and service servers that belong to this node.
Warning: every message sent on a topic which has no registered callback will be discarded.
|
protectedvirtual |
Start the heartbeat thread.
The heartbeat thread will periodically send a heartbeat message to inform the resolver node that this node is alive.