#include <node.h>
A node represents a separate entity in the peer-to-peer network, typically a process on a cluster node or on a shared-memory system. It has at least one Connection through which is reachable. A Node provides the basic communication facilities through message passing.
Definition at line 43 of file lib/net/node.h.
Session management | |
| base::RequestHandler | _requestHandler |
| Registers request packets waiting for a return value. | |
| bool | mapSession (NodePtr server, Session *session) |
| Maps a local session object to the session of the same name on the server. | |
| bool | mapSession (NodePtr server, Session *session, const uint32_t id) |
| Maps a local session object to the session of the same identifier on the server. | |
| bool | unmapSession (Session *session) |
| Unmaps a mapped session. | |
| Session * | getSession (const uint32_t id) |
| void | addSession (Session *session, NodePtr server, const uint32_t sessionID) |
| Adds an already mapped session to this node. | |
| void | removeSession (Session *session) |
| Removes an unmapped session from this node. | |
| bool | hasSessions () const |
| virtual bool | runClient (const std::string &clientArgs) |
| Runs this node as a client to a server. | |
| CommandQueue * | getCommandThreadQueue () |
| Return the command queue to the command thread. | |
| bool | inCommandThread () const |
| bool | inReceiverThread () const |
| const NodeID & | getNodeID () const |
| virtual | ~Node () |
| Destructs this node. | |
| virtual bool | dispatchCommand (Command &command) |
| Dispatches a packet to the registered command queue. | |
| virtual CommandResult | invokeCommand (Command &command) |
| Invokes the command handler method for the packet. | |
| virtual bool | clientLoop () |
| The main loop for auto-launched clients. | |
| virtual uint32_t | getType () const |
| virtual NodePtr | createNode (const uint32_t type) |
| Factory method to create a new node. | |
| std::string | serialize () const |
| Serialize the node's information. | |
| bool | deserialize (std::string &data) |
| Deserialize the node information, consumes data. | |
Public Types | |
| enum | State { STATE_STOPPED, STATE_LAUNCHED, STATE_CONNECTED, STATE_LISTENING } |
Public Member Functions | |
| Node () | |
| Constructs a new Node. | |
Data Access. | |
| bool | operator== (const Node *n) const |
| State | getState () const |
| Returns the state of this node. | |
| bool | isConnected () const |
| void | setAutoLaunch (const bool autoLaunch) |
| void | setProgramName (const std::string &name) |
| Set the program name to start this node. | |
| void | setWorkDir (const std::string &name) |
| Set the working directory to start this node. | |
State Changes | |
The following methods affect the state of the node by changing it's connectivity to the network. | |
| virtual bool | initLocal (const int argc, char **argv) |
| Initialize a local, listening node. | |
| virtual bool | exitLocal () |
| Exit a local, listening node. | |
| virtual bool | exitClient () |
| Exit a client node. | |
| virtual bool | listen () |
| Initializes this node. | |
| virtual bool | stopListening () |
| Stops this node. | |
| bool | connect (NodePtr node, ConnectionPtr connection) |
| Connects a node to this listening node. | |
| NodePtr | getNode (const NodeID &id) const |
| Get a node by identifier. | |
| bool | connect (NodePtr node) |
| Connect and potentially launch a node to this listening node, using the available connection descriptions. | |
| bool | initConnect (NodePtr node) |
| Start connecting and potentially launching a node using the available connection descriptions. | |
| bool | syncConnect (NodePtr node) |
| Synchronize the connection initiated by initConnect(). | |
| NodePtr | connect (const NodeID &nodeID, NodePtr server) |
| Create and connect a node given by an identifier. | |
| bool | disconnect (NodePtr node) |
| Disconnects a connected node. | |
| ConnectionPtr | checkConnection () |
| Ensures the connectivity of this node. | |
Connectivity information. | |
| bool | isLocal () const |
| Returns if the node is local. | |
| void | addConnectionDescription (ConnectionDescriptionPtr cd) |
| Adds a new description how this node can be reached. | |
| void | removeConnectionDescription (const uint32_t index) |
| Removes a connection description. | |
| const ConnectionDescriptionVector & | getConnectionDescriptions () const |
| Returns the number of stored connection descriptions. | |
| ConnectionPtr | getConnection () const |
| Returns the connection to this node. | |
Messaging API | |
| bool | send (const Packet &packet) |
| Sends a packet to this node. | |
| bool | send (Packet &packet, const std::string &string) |
| Sends a packet with a string to the node. | |
| template<class T> | |
| bool | send (Packet &packet, const std::vector< T > &data) |
| Sends a packet with additional data to the node. | |
| bool | send (Packet &packet, const void *data, const uint64_t size) |
| Sends a packet with additional data to the node. | |
| void | flushCommands () |
| Flush all pending commands on this listening node. | |
Classes | |
| class | CommandThread |
| The command handler thread. | |
| class | ReceiverThread |
| The receiver thread. | |
| eq::net::Node::~Node | ( | ) | [protected, virtual] |
Destructs this node.
Definition at line 82 of file lib/net/node.cpp.
References _requestHandler, eq::base::RequestHandler::empty(), eq::net::CommandCache::empty(), and eq::net::ConnectionSet::empty().
| State eq::net::Node::getState | ( | ) | const [inline] |
Returns the state of this node.
Definition at line 68 of file lib/net/node.h.
Referenced by deserialize().
| void eq::net::Node::setProgramName | ( | const std::string & | name | ) | [inline] |
Set the program name to start this node.
| name | the program name to start this node. |
Definition at line 79 of file lib/net/node.h.
| void eq::net::Node::setWorkDir | ( | const std::string & | name | ) | [inline] |
Set the working directory to start this node.
| name | the working directory to start this node. |
Definition at line 86 of file lib/net/node.h.
| bool eq::net::Node::initLocal | ( | const int | argc, | |
| char ** | argv | |||
| ) | [virtual] |
Initialize a local, listening node.
This function does not return when the command line option '--eq-client' is present. This is used for remote nodes which have been auto-launched by another node, e.g., remote render clients.
| argc | the command line argument count. | |
| argv | the command line argument values. |
true if the client was successfully initialized, false otherwise. Definition at line 118 of file lib/net/node.cpp.
References addConnectionDescription(), clientLoop(), eq::net::CONNECTIONTYPE_TCPIP, deserialize(), eq::base::disableFlush(), eq::base::enableFlush(), eq::net::exit(), exitClient(), eq::net::Global::getDefaultPort(), listen(), runClient(), and serialize().
| virtual bool eq::net::Node::exitLocal | ( | ) | [inline, virtual] |
| virtual bool eq::net::Node::exitClient | ( | ) | [inline, virtual] |
Exit a client node.
Reimplemented in eq::Client.
Definition at line 114 of file lib/net/node.h.
Referenced by eq::Client::exitClient(), and initLocal().
| bool eq::net::Node::listen | ( | ) | [virtual] |
Initializes this node.
The node will spawn a thread locally and listen on all connections described for incoming commands. The node will be in the listening state if the method completed successfully. A listening node can connect to other nodes.
true if the node could be initialized, false if not. Reimplemented in eq::Client.
Definition at line 203 of file lib/net/node.cpp.
References eq::net::ConnectionSet::addConnection(), and eq::net::Connection::create().
Referenced by initLocal(), and eq::Client::listen().
| bool eq::net::Node::stopListening | ( | ) | [virtual] |
Stops this node.
If this node is listening, the node will stop listening and terminate its receiver thread.
true if the node was stopped, false if it was not stopped. Reimplemented in eq::Client.
Definition at line 240 of file lib/net/node.cpp.
References _requestHandler, eq::base::RequestHandler::empty(), eq::net::ConnectionSet::getConnections(), send(), and eq::net::ConnectionSet::size().
Referenced by eq::Client::stopListening().
| bool eq::net::Node::connect | ( | NodePtr | node, | |
| ConnectionPtr | connection | |||
| ) |
Connects a node to this listening node.
| node | the remote node. | |
| connection | the connection to the remote node. |
true if the node was connected correctly, false otherwise. Definition at line 349 of file lib/net/node.cpp.
References _requestHandler, eq::net::ConnectionSet::addConnection(), eq::net::NodeID::convertToNetwork(), eq::base::RefPtr< T >::get(), getType(), eq::base::RefPtr< T >::isValid(), eq::base::RequestHandler::registerRequest(), serialize(), and eq::base::RequestHandler::waitRequest().
Referenced by connect(), eq::Client::connectServer(), initConnect(), and runClient().
Get a node by identifier.
| id | the node identifier. |
Definition at line 384 of file lib/net/node.cpp.
| bool eq::net::Node::connect | ( | NodePtr | node | ) |
Connect and potentially launch a node to this listening node, using the available connection descriptions.
On success, the node is in the connected state, otherwise its state is unchanged.
| node | the remote node. |
true if this node was connected, false otherwise. Definition at line 1297 of file lib/net/node.cpp.
References initConnect(), and syncConnect().
| bool eq::net::Node::initConnect | ( | NodePtr | node | ) |
Start connecting and potentially launching a node using the available connection descriptions.
On success, the node is in the launched or connected state, otherwise its state is unchanged.
| node | the remote node. |
true if this node is connecting, false otherwise. Definition at line 1314 of file lib/net/node.cpp.
References connect(), and eq::net::Connection::create().
Referenced by connect().
| bool eq::net::Node::syncConnect | ( | NodePtr | node | ) |
Synchronize the connection initiated by initConnect().
On success, the node is in the connected state, otherwise its state is unchanged.
| node | the remote node. |
true if this node is connected, false otherwise. Definition at line 1358 of file lib/net/node.cpp.
References _requestHandler, eq::base::RequestHandler::unregisterRequest(), and eq::base::RequestHandler::waitRequest().
Referenced by connect().
Create and connect a node given by an identifier.
| nodeID | the identifier of the node to connect. | |
| server | a node holding connection information to the destination node. |
Definition at line 1380 of file lib/net/node.cpp.
References _requestHandler, connect(), eq::net::NodeID::convertToNetwork(), eq::base::RequestHandler::registerRequest(), eq::base::RefPtr< T >::unref(), and eq::base::RequestHandler::waitRequest().
| bool eq::net::Node::disconnect | ( | NodePtr | node | ) |
Disconnects a connected node.
| node | the remote node. |
true if the node was disconnected correctly, false otherwise. Definition at line 392 of file lib/net/node.cpp.
References _requestHandler, eq::base::RefPtr< T >::get(), inCommandThread(), eq::base::RequestHandler::registerRequest(), send(), and eq::base::RequestHandler::waitRequest().
Referenced by eq::Client::disconnectServer().
| ConnectionPtr eq::net::Node::checkConnection | ( | ) | [inline] |
Ensures the connectivity of this node.
true if this node is connected, false otherwise. Definition at line 227 of file lib/net/node.h.
| bool eq::net::Node::isLocal | ( | ) | const [inline] |
Returns if the node is local.
true if the node is local, false otherwise. Definition at line 247 of file lib/net/node.h.
Referenced by addSession(), mapSession(), and unmapSession().
| void eq::net::Node::addConnectionDescription | ( | ConnectionDescriptionPtr | cd | ) |
Adds a new description how this node can be reached.
| cd | the connection description. |
Definition at line 410 of file lib/net/node.cpp.
Referenced by deserialize(), and initLocal().
| void eq::net::Node::removeConnectionDescription | ( | const uint32_t | index | ) |
Removes a connection description.
| index | the index of the connection description. |
| const ConnectionDescriptionVector& eq::net::Node::getConnectionDescriptions | ( | ) | const [inline] |
Returns the number of stored connection descriptions.
Definition at line 268 of file lib/net/node.h.
| ConnectionPtr eq::net::Node::getConnection | ( | ) | const [inline] |
Returns the connection to this node.
Definition at line 276 of file lib/net/node.h.
| bool eq::net::Node::send | ( | const Packet & | packet | ) | [inline] |
Sends a packet to this node.
| packet | the packet. |
Definition at line 289 of file lib/net/node.h.
Referenced by disconnect(), and stopListening().
| bool eq::net::Node::send | ( | Packet & | packet, | |
| const std::string & | string | |||
| ) | [inline] |
Sends a packet with a string to the node.
The data is send as a new packet containing the original packet and the string, so that it is received as one packet by the node.
It is assumed that the last 8 bytes in the packet are usable for the string. This is used for optimising the send of short strings and on the receiver side to access the string. The node implementation gives examples of this usage.
| packet | the packet. | |
| string | the string. |
Definition at line 312 of file lib/net/node.h.
| bool eq::net::Node::send | ( | Packet & | packet, | |
| const std::vector< T > & | data | |||
| ) | [inline] |
Sends a packet with additional data to the node.
The data is send as a new packet containing the original packet and the string, so that it is received as one packet by the node.
It is assumed that the last item in the packet is of sizeof(T) and usable for the data.
| packet | the packet. | |
| data | the vector containing the data. |
Definition at line 334 of file lib/net/node.h.
| bool eq::net::Node::send | ( | Packet & | packet, | |
| const void * | data, | |||
| const uint64_t | size | |||
| ) | [inline] |
Sends a packet with additional data to the node.
The data is send as a new packet containing the original packet and the data, so that it is received as one packet by the node.
It is assumed that the last 8 bytes in the packet are usable for the data. This is used for optimising the send of short data and on the receiver side to access the data. The node implementation gives examples of this usage.
| packet | the packet. | |
| data | the data. | |
| size | the size of the data in bytes. |
Definition at line 358 of file lib/net/node.h.
| void eq::net::Node::flushCommands | ( | ) | [inline] |
Flush all pending commands on this listening node.
This causes the receiver thread to redispatch all pending commands, which are normally only redispatched when a new command is received.
Definition at line 372 of file lib/net/node.h.
Maps a local session object to the session of the same name on the server.
| server | the node serving the session. | |
| session | the session. |
true if the session was mapped, false if not. Definition at line 446 of file lib/net/node.cpp.
References _requestHandler, eq::net::Session::getName(), inCommandThread(), isLocal(), eq::base::RequestHandler::registerRequest(), and eq::base::RequestHandler::waitRequest().
Maps a local session object to the session of the same identifier on the server.
The session's name is changed to the name of the session on the server.
| server | the node serving the session. | |
| session | the session. | |
| id | the identifier of the session. |
true if the session was mapped, false if not. Definition at line 460 of file lib/net/node.cpp.
References _requestHandler, isLocal(), eq::base::RequestHandler::registerRequest(), and eq::base::RequestHandler::waitRequest().
| bool eq::net::Node::unmapSession | ( | Session * | session | ) |
Unmaps a mapped session.
| session | the session. |
true if the session was unmapped, false if there was an error. Definition at line 475 of file lib/net/node.cpp.
References _requestHandler, eq::net::Session::getID(), eq::net::Session::getServer(), isLocal(), eq::base::RequestHandler::registerRequest(), and eq::base::RequestHandler::waitRequest().
| Session* eq::net::Node::getSession | ( | const uint32_t | id | ) | [inline] |
Definition at line 414 of file lib/net/node.h.
Adds an already mapped session to this node.
| session | the session. | |
| server | the node serving the session. | |
| sessionID | the identifier of the session. |
Definition at line 418 of file lib/net/node.cpp.
References eq::net::Session::_id, eq::net::Session::_isMaster, eq::net::Session::_name, eq::net::Session::_server, eq::base::RefPtr< T >::get(), isLocal(), and eq::net::Session::setLocalNode().
| void eq::net::Node::removeSession | ( | Session * | session | ) |
Removes an unmapped session from this node.
| session | the session. |
Definition at line 435 of file lib/net/node.cpp.
References eq::net::Session::_id, eq::net::Session::_isMaster, eq::net::Session::_server, eq::net::Session::getID(), and eq::net::Session::setLocalNode().
| bool eq::net::Node::runClient | ( | const std::string & | clientArgs | ) | [virtual] |
Runs this node as a client to a server.
| clientArgs | the client arguments as specified by the server. |
Definition at line 1574 of file lib/net/node.cpp.
References clientLoop(), connect(), createNode(), and eq::net::Global::setWorkDir().
Referenced by initLocal().
| CommandQueue* eq::net::Node::getCommandThreadQueue | ( | ) | [inline] |
| bool eq::net::Node::inCommandThread | ( | ) | const [inline] |
true if executed from the command handler thread, false if not. Definition at line 452 of file lib/net/node.h.
Referenced by disconnect(), and mapSession().
| bool eq::net::Node::dispatchCommand | ( | Command & | command | ) | [protected, virtual] |
Dispatches a packet to the registered command queue.
| command | the command. |
Reimplemented from eq::net::Base.
Definition at line 768 of file lib/net/node.cpp.
References eq::net::Session::dispatchCommand(), eq::net::Base::dispatchCommand(), eq::net::Command::getPacket(), and eq::net::Command::isValid().
| CommandResult eq::net::Node::invokeCommand | ( | Command & | command | ) | [protected, virtual] |
Invokes the command handler method for the packet.
| command | the command. |
Reimplemented from eq::net::Base.
Definition at line 862 of file lib/net/node.cpp.
References eq::net::Command::getPacket(), eq::net::Session::invokeCommand(), eq::net::Base::invokeCommand(), and eq::net::Command::isValid().
| virtual bool eq::net::Node::clientLoop | ( | ) | [inline, protected, virtual] |
The main loop for auto-launched clients.
Reimplemented in eq::Client.
Definition at line 484 of file lib/net/node.h.
Referenced by initLocal(), and runClient().
| virtual uint32_t eq::net::Node::getType | ( | ) | const [inline, protected, virtual] |
Definition at line 487 of file lib/net/node.h.
References eq::net::TYPE_EQNET_NODE.
Referenced by connect().
| virtual NodePtr eq::net::Node::createNode | ( | const uint32_t | type | ) | [inline, protected, virtual] |
Factory method to create a new node.
| type | the type the node type |
Definition at line 496 of file lib/net/node.h.
References eq::net::TYPE_EQNET_NODE.
Referenced by runClient().
| std::string eq::net::Node::serialize | ( | ) | const [protected] |
Serialize the node's information.
Definition at line 503 of file lib/net/node.cpp.
Referenced by connect(), and initLocal().
| bool eq::net::Node::deserialize | ( | std::string & | data | ) | [protected] |
Deserialize the node information, consumes data.
Definition at line 519 of file lib/net/node.cpp.
References addConnectionDescription(), and getState().
Referenced by initLocal().
base::RequestHandler eq::net::Node::_requestHandler [protected] |
Registers request packets waiting for a return value.
Definition at line 505 of file <a class="el" href="lib_2net_2node_