Collage  1.6.0
High-performance C++ library for developing object-oriented distributed applications.
co::Node Class Reference

Proxy node representing a remote LocalNode. More...

#include <node.h>

+ Inheritance diagram for co::Node:
+ Collaboration diagram for co::Node:

Public Member Functions

CO_API Node (const uint32_t type=co::NODETYPE_NODE)
 Construct a new node proxy. More...
 
CO_API int64_t getLastReceiveTime () const
 
CO_API std::string serialize () const
 
CO_API bool deserialize (std::string &data)
 
Data Access
CO_API const NodeIDgetNodeID () const
 Get the node's unique identifier. More...
 
CO_API uint32_t getType () const
 
bool operator== (const Node *n) const
 
bool isBigEndian () const
 
CO_API bool isReachable () const
 
CO_API bool isConnected () const
 
CO_API bool isListening () const
 
CO_API bool isClosed () const
 
CO_API bool isClosing () const
 
Connectivity information
bool isLocal () const
 
CO_API void addConnectionDescription (ConnectionDescriptionPtr cd)
 Add a new description how this node can be reached. More...
 
CO_API bool removeConnectionDescription (ConnectionDescriptionPtr cd)
 Removes a connection description. More...
 
CO_API ConnectionDescriptions getConnectionDescriptions () const
 
CO_API ConnectionPtr getConnection (const bool multicast=false)
 Get an active connection to this node. More...
 
Messaging API
CO_API OCommand send (const uint32_t cmd, const bool multicast=false)
 Send a command with optional data to the node. More...
 
CO_API CustomOCommand send (const uint128_t &commandID, const bool multicast=false)
 Send a custom command with optional data to the node. More...
 
Launch parameters
CO_API void setHostname (const std::string &host)
 Set the host name for the launch command. More...
 
CO_API const std::string & getHostname () const
 
virtual CO_API std::string getWorkDir () const
 
virtual CO_API std::string getLaunchQuote () const
 
- Public Member Functions inherited from co::Dispatcher
Dispatcheroperator= (const Dispatcher &)
 
template<typename T >
void registerCommand (const uint32_t command, const CommandFunc< T > &func, CommandQueue *queue)
 Register a command member function for a command. More...
 
virtual CO_API bool dispatchCommand (ICommand &command)
 Dispatch a command from the receiver thread to the registered queue. More...
 

Protected Member Functions

virtual CO_API ~Node ()
 Destruct this node. More...
 
void _addConnectionDescription (ConnectionDescriptionPtr cd)
 
bool _removeConnectionDescription (ConnectionDescriptionPtr cd)
 
ConnectionPtr _getMulticast () const
 
ConnectionPtr getMulticast ()
 Activate and return a multicast connection. More...
 
- Protected Member Functions inherited from co::Dispatcher
CO_API Dispatcher (const Dispatcher &from)
 
CO_API bool _cmdUnknown (ICommand &command)
 The default handler for handling commands. More...
 

Friends

CO_API friend std::ostream & operator<< (std::ostream &, const Node &)
 
class LocalNode
 

Additional Inherited Members

- Public Types inherited from co::Dispatcher
typedef CommandFunc< DispatcherFunc
 The signature of the base Dispatcher callback. More...
 

Detailed Description

Proxy node representing a remote LocalNode.

A node represents a separate entity in a peer-to-peer network, typically a process on another machine. It should have at least one Connection through which is reachable. A Node provides the basic communication facilities through message passing.

Definition at line 42 of file node.h.

Constructor & Destructor Documentation

CO_API co::Node::Node ( const uint32_t  type = co::NODETYPE_NODE)
explicit

Construct a new node proxy.

Parameters
typethe type of the node, used during connect().
Version
1.0
virtual CO_API co::Node::~Node ( )
protectedvirtual

Destruct this node.

Version
1.0

Member Function Documentation

CO_API void co::Node::addConnectionDescription ( ConnectionDescriptionPtr  cd)

Add a new description how this node can be reached.

The node has to be closed.

Parameters
cdthe connection description.
Version
1.0
CO_API ConnectionPtr co::Node::getConnection ( const bool  multicast = false)

Get an active connection to this node.

Parameters
multicastif true, prefer a multicast connection.
Returns
an active connection to this node.
Version
1.0
CO_API ConnectionDescriptions co::Node::getConnectionDescriptions ( ) const
Returns
the connection descriptions.
Version
1.0
CO_API const std::string& co::Node::getHostname ( ) const
Returns
the host name for the launch command.
virtual CO_API std::string co::Node::getLaunchQuote ( ) const
virtual
Returns
the character to quote single arguments.
ConnectionPtr co::Node::getMulticast ( )
protected

Activate and return a multicast connection.

Multicast connections are activated lazily on first use, since they trigger the creation of the remote local node proxies on all members of the multicast group.

Returns
the first usable multicast connection to this node, or 0.
Version
1.0
CO_API const NodeID& co::Node::getNodeID ( ) const

Get the node's unique identifier.

In rare cases (two nodes initiate a two-sided LocalNode::connect()) to each other, two node instances with the same identifier might exist temporarily during the connection handshake.

Returns
the node's unique identifier.
Version
1.0
CO_API uint32_t co::Node::getType ( ) const
Returns
the type of the node.
Version
1.0
virtual CO_API std::string co::Node::getWorkDir ( ) const
virtual
Returns
the working directory for the remote process.
CO_API bool co::Node::isClosed ( ) const
Returns
true if then node is not active.
Version
1.0
CO_API bool co::Node::isClosing ( ) const
Returns
true if the node is about to become inactive.
Version
1.0
CO_API bool co::Node::isConnected ( ) const
Returns
true if the remote node is reachable.
Version
1.0
CO_API bool co::Node::isListening ( ) const
Returns
true if the local node is reachable.
Version
1.0
bool co::Node::isLocal ( ) const
inline
Returns
true if the node is local (listening).
Version
1.0

Definition at line 92 of file node.h.

References co::deserialize(), and co::serialize().

+ Here is the call graph for this function:

CO_API bool co::Node::isReachable ( ) const
Returns
true if the node can send/receive messages.
Version
1.0
CO_API bool co::Node::removeConnectionDescription ( ConnectionDescriptionPtr  cd)

Removes a connection description.

The node has to be closed.

Parameters
cdthe connection description.
Returns
true if the connection description was removed, false otherwise.
Version
1.0
CO_API OCommand co::Node::send ( const uint32_t  cmd,
const bool  multicast = false 
)

Send a command with optional data to the node.

The returned command can be used to pass additional data. The data will be send after the command object is destroyed, aka when it is running out of scope. Thread safe.

Parameters
cmdthe node command to execute.
multicastprefer multicast connection for sending.
Returns
the command object to append additional data.
Version
1.0
CO_API CustomOCommand co::Node::send ( const uint128_t &  commandID,
const bool  multicast = false 
)

Send a custom command with optional data to the node.

The command handler for this command being send is registered with the remote LocalNode::registerCommandHandler().

The returned command can be used to pass additional data. The data will be send after the command object is destroyed, aka when it is running out of scope. Thread safe.

Parameters
commandIDthe ID of the registered custom command.
multicastprefer multicast connection for sending.
Returns
the command object to append additional data.
Version
1.0
CO_API void co::Node::setHostname ( const std::string &  host)

Set the host name for the launch command.


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