Manages a node. More...
#include <node.h>


Classes | |
| class | CommandThread |
| The command handler thread. | |
| struct | MCData |
| class | ReceiverThread |
| The receiver thread. | |
Public Types | |
| enum | State { STATE_STOPPED, STATE_LAUNCHED, STATE_CONNECTED, STATE_LISTENING } |
The state of the node. More... | |
Public Member Functions | |
| Node () | |
| Construct a new Node. | |
| 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 |
| std::string | serialize () const |
| Serialize the node's information. | |
| bool | deserialize (std::string &data) |
| Deserialize the node information, consumes given data. | |
Data Access. | |
| bool | operator== (const Node *n) const |
| State | getState () const |
| bool | isConnected () const |
| NodePtr | getNode (const NodeID &id) const |
| Get a node by identifier. | |
| void | setLaunchCommand (const std::string &launchCommand) |
| @ Auto-launch parameters. | |
| const std::string & | getLaunchCommand () const |
| void | setLaunchTimeout (const uint32_t time) |
| Set the launch timeout in milliseconds. | |
| uint32_t | getLaunchTimeout () const |
| void | setLaunchCommandQuote (const char quote) |
| Set the quote charactor for the launch command arguments. | |
| char | getLaunchCommandQuote () const |
| void | setProgramName (const std::string &name) |
| Set the program name to start this node. | |
| const std::string & | getProgramName () const |
| void | setWorkDir (const std::string &name) |
| Set the working directory to start this node. | |
| const std::string & | getWorkDir () const |
| void | setAutoLaunch (const bool autoLaunch) |
| Set if this node should be launched automatically. | |
State Changes | |
| 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 () |
| Open all connections and put this node into the listening state. | |
| virtual bool | close () |
| Close a listening node. | |
| bool | connect (NodePtr node) |
| Connect a proxy node to this listening node. | |
| bool | initConnect (NodePtr node) |
| Start connecting a node using the available connection descriptions. | |
| bool | syncConnect (NodePtr node, const uint32_t timeout) |
| Synchronize the connection initiated by initConnect(). | |
| NodePtr | connect (const NodeID &nodeID) |
| Create and connect a node given by an identifier. | |
| bool | close (NodePtr node) |
| Disconnects a connected 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. | |
| bool | removeConnectionDescription (ConnectionDescriptionPtr cd) |
| Removes a connection description. | |
| const ConnectionDescriptionVector & | getConnectionDescriptions () const |
| Returns the number of stored connection descriptions. | |
| ConnectionPtr | getConnection () const |
| ConnectionPtr | getMulticast () |
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. | |
| bool | multicast (const Packet &packet) |
| Multicasts a packet to the multicast group of this node. | |
| void | flushCommands () |
| Flush all pending commands on this listening node. | |
| void | acquireSendToken (NodePtr toNode) |
| void | releaseSendToken (NodePtr toNode) |
Session management | |
| bool | registerSession (Session *session) |
| Register a new session using this node as the session server. | |
| bool | deregisterSession (Session *session) |
| Deregister a (master) session. | |
| 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) |
| bool | hasSessions () const |
Protected Member Functions | |
| virtual | ~Node () |
| Destructs this node. | |
| bool | _connect (NodePtr node, ConnectionPtr connection) |
| Connect a node proxy to 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. | |
Protected Attributes | |
| base::RequestHandler | _requestHandler |
| Registers request packets waiting for a return value. | |
Manages a node.
A node represents a separate entity in a peer-to-peer network, typically a process on a cluster node or on a shared-memory system. It should have at least one Connection through which is reachable. A Node provides the basic communication facilities through message passing. Nodes manage sessions, that is, one or more Session can be mapped to a Node, in which case the node will dispatch packets to these sessions.
Definition at line 60 of file lib/net/node.h.
| enum eq::net::Node::State |
The state of the node.
| STATE_STOPPED |
initial state |
| STATE_LAUNCHED |
proxy for a remote node, launched |
| STATE_CONNECTED |
proxy for a remote node, connected |
| STATE_LISTENING |
local node, listening |
Definition at line 64 of file lib/net/node.h.
| eq::net::Node::Node | ( | ) |
Construct a new Node.
Definition at line 47 of file lib/net/node.cpp.
References EQINFO, and eq::net::Dispatcher::registerCommand().
Referenced by createNode().


| eq::net::Node::~Node | ( | ) | [protected, virtual] |
Destructs this node.
Definition at line 98 of file lib/net/node.cpp.
References _requestHandler, EQINFO, eq::net::Session::getID(), and eq::base::RequestHandler::isEmpty().

| State eq::net::Node::getState | ( | ) | const [inline] |
Definition at line 80 of file lib/net/node.h.
Referenced by deserialize(), and eq::server::Server::run().

Get a node by identifier.
The node might not be connected.
| id | the node identifier. |
Definition at line 531 of file lib/net/node.cpp.
| void eq::net::Node::setLaunchCommand | ( | const std::string & | launchCommand | ) |
@ Auto-launch parameters.
Set the command to spawn the process for this node.
The default is '"ssh -n %h %c >& %h.%n.log"', with:
h - hostname c - command (work dir + program name) n - unique node identifier
Definition at line 192 of file lib/net/node.cpp.
| const std::string & eq::net::Node::getLaunchCommand | ( | ) | const |
Definition at line 197 of file lib/net/node.cpp.
| void eq::net::Node::setLaunchTimeout | ( | const uint32_t | time | ) | [inline] |
Set the launch timeout in milliseconds.
Definition at line 112 of file lib/net/node.h.
| uint32_t eq::net::Node::getLaunchTimeout | ( | ) | const [inline] |
Definition at line 115 of file lib/net/node.h.
| void eq::net::Node::setProgramName | ( | const std::string & | name | ) |
Set the program name to start this node.
| name | the program name to start this node. |
Definition at line 144 of file lib/net/node.cpp.
| const std::string& eq::net::Node::getProgramName | ( | ) | const [inline] |
Definition at line 132 of file lib/net/node.h.
| void eq::net::Node::setWorkDir | ( | const std::string & | name | ) |
Set the working directory to start this node.
| name | the working directory to start this node. |
Definition at line 149 of file lib/net/node.cpp.
Referenced by runClient().

| const std::string& eq::net::Node::getWorkDir | ( | ) | const [inline] |
Definition at line 142 of file lib/net/node.h.
| void eq::net::Node::setAutoLaunch | ( | const bool | autoLaunch | ) | [inline] |
Set if this node should be launched automatically.
This determines if the launch command is used to start the node when it can not be reached using its connections. The default is false.
Definition at line 150 of file lib/net/node.h.
| bool eq::net::Node::initLocal | ( | const int | argc, | |
| char ** | argv | |||
| ) | [virtual] |
Initialize a local, listening node.
The following command line options are recognized by this method:
Please note that further command line parameters are recognized by eq::init().
| argc | the command line argument count. | |
| argv | the command line argument values. |
true if the client was successfully initialized, false otherwise. Definition at line 202 of file lib/net/node.cpp.
References addConnectionDescription(), clientLoop(), eq::net::CONNECTIONTYPE_TCPIP, deserialize(), eq::base::disableFlush(), eq::base::enableFlush(), EQINFO, EQVERB, EQWARN, eq::net::exit(), exitClient(), eq::net::Global::getDefaultPort(), eq::base::Referenced::getRefCount(), listen(), runClient(), and serialize().

| virtual bool eq::net::Node::exitLocal | ( | ) | [inline, virtual] |
Exit a local, listening node.
Definition at line 185 of file lib/net/node.h.
References close().
Referenced by exitClient().


| virtual bool eq::net::Node::exitClient | ( | ) | [inline, virtual] |
Exit a client node.
Reimplemented in eq::Client.
Definition at line 188 of file lib/net/node.h.
References exitLocal().
Referenced by eq::Client::exitClient(), and initLocal().


| bool eq::net::Node::listen | ( | ) | [virtual] |
Open all connections and put this node into the listening state.
The node will spawn a receiver and command thread, 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 other nodes.
true if the node could be initialized, false if not. Reimplemented in eq::Client.
Definition at line 288 of file lib/net/node.cpp.
References eq::net::Connection::create(), EQINFO, EQVERB, EQWARN, STATE_LISTENING, and STATE_STOPPED.
Referenced by initLocal().


| bool eq::net::Node::close | ( | ) | [virtual] |
Close a listening node.
Disconnects all connected node proxies, closes the listening connections and terminates all threads created in listen().
true if the node was stopped, false if it was not stopped. Reimplemented in eq::Client.
Definition at line 335 of file lib/net/node.cpp.
References _requestHandler, EQINFO, eq::base::RequestHandler::isEmpty(), send(), and STATE_LISTENING.
Referenced by eq::Client::close(), exitLocal(), and eq::Server::shutdown().


| bool eq::net::Node::connect | ( | NodePtr | node | ) |
Connect a proxy node to this listening node.
The connection descriptions of the node are used to connect the node. If this fails, and auto launch is true, the node is started using the launch command.
On success, the node is in the connected state, otherwise its state is unchanged.
This method is one-sided, that is, the node to be connected should not initiate a connection to this node at the same time.
| node | the remote node. |
Definition at line 819 of file lib/net/node.cpp.
References EQERROR, initConnect(), STATE_CONNECTED, STATE_LISTENING, and syncConnect().
Referenced by eq::Client::connectServer(), and runClient().


| bool eq::net::Node::initConnect | ( | NodePtr | node | ) |
Start connecting a node using the available connection descriptions.
The connection descriptions of the node are used to connect the node. If this fails, and auto launch is true, the node is started using the launch command.
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 836 of file lib/net/node.cpp.
References _connect(), eq::net::Connection::create(), EQINFO, STATE_CONNECTED, STATE_LISTENING, and STATE_STOPPED.
Referenced by connect().


| bool eq::net::Node::syncConnect | ( | NodePtr | node, | |
| const uint32_t | timeout | |||
| ) |
Synchronize the connection initiated by initConnect().
On success, the node is in the connected state, otherwise its state is unchanged.
| node | the remote node. | |
| timeout | the timeout, in milliseconds, before the launch process is considered to have failed. |
true if this node is connected, false otherwise. Definition at line 917 of file lib/net/node.cpp.
References _requestHandler, STATE_CONNECTED, STATE_STOPPED, eq::base::RequestHandler::unregisterRequest(), and eq::base::RequestHandler::waitRequest().
Referenced by connect().


Create and connect a node given by an identifier.
This method is two-sided and thread-safe, that is, it can be called by mulltiple threads on the same node with the same nodeID, or concurrently on two nodes with each others' nodeID.
| nodeID | the identifier of the node to connect. |
Definition at line 936 of file lib/net/node.cpp.
References _connect(), EQWARN, eq::base::RefPtr< T >::isValid(), STATE_LISTENING, and eq::base::UUID::ZERO.

| bool eq::net::Node::close | ( | NodePtr | node | ) |
Disconnects a connected node.
| node | the remote node. |
true if the node was disconnected correctly, false otherwise. Definition at line 540 of file lib/net/node.cpp.
References _requestHandler, eq::base::RefPtr< T >::get(), inCommandThread(), eq::base::RequestHandler::registerRequest(), send(), STATE_CONNECTED, STATE_LISTENING, and eq::base::RequestHandler::waitRequest().

| bool eq::net::Node::isLocal | ( | ) | const [inline] |
Returns if the node is local.
true if the node is local, false otherwise. Definition at line 300 of file lib/net/node.h.
References STATE_LISTENING.
Referenced by getCommandThreadQueue(), mapSession(), registerSession(), 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 558 of file lib/net/node.cpp.
Referenced by deserialize(), and initLocal().

| bool eq::net::Node::removeConnectionDescription | ( | ConnectionDescriptionPtr | cd | ) |
Removes a connection description.
| cd | the connection description. |
Definition at line 566 of file lib/net/node.cpp.
| const ConnectionDescriptionVector & eq::net::Node::getConnectionDescriptions | ( | ) | const |
Returns the number of stored connection descriptions.
Definition at line 154 of file lib/net/node.cpp.
| ConnectionPtr eq::net::Node::getConnection | ( | ) | const [inline] |
Definition at line 327 of file lib/net/node.h.
| ConnectionPtr eq::net::Node::getMulticast | ( | ) |
Definition at line 159 of file lib/net/node.cpp.
References EQINFO, getType(), and eq::base::RefPtr< T >::isValid().
Referenced by multicast().


| bool eq::net::Node::send | ( | const Packet & | packet | ) | [inline] |
Sends a packet to this node.
| packet | the packet. |
Definition at line 343 of file lib/net/node.h.
Referenced by eq::Server::chooseConfig(), close(), registerSession(), eq::Server::releaseConfig(), eq::Server::shutdown(), and eq::Server::useConfig().

| 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 366 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 388 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 412 of file lib/net/node.h.
| bool eq::net::Node::multicast | ( | const Packet & | packet | ) | [inline] |
Multicasts a packet to the multicast group of this node.
| packet | the packet. |
Definition at line 426 of file lib/net/node.h.
References getMulticast().

| 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 440 of file lib/net/node.h.
References eq::net::ConnectionSet::interrupt().

| bool eq::net::Node::registerSession | ( | Session * | session | ) |
Register a new session using this node as the session server.
This method assigns the session identifier. The node has to be local.
| session | the session. |
true if the session was mapped, false if not. Definition at line 619 of file lib/net/node.cpp.
References _requestHandler, eq::net::Session::getID(), inCommandThread(), isLocal(), eq::base::RequestHandler::registerRequest(), send(), and eq::base::RequestHandler::waitRequest().

| bool eq::net::Node::deregisterSession | ( | Session * | session | ) | [inline] |
Deregister a (master) session.
Definition at line 462 of file lib/net/node.h.
References unmapSession().

Maps a local session object to the session of the same identifier on the server.
The node has to be a remote node.
| 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 633 of file lib/net/node.cpp.
References _requestHandler, eq::net::Session::getID(), 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 649 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().
Referenced by deregisterSession().


| Session * eq::net::Node::getSession | ( | const uint32_t | id | ) |
Definition at line 663 of file lib/net/node.cpp.
| 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 1180 of file lib/net/node.cpp.
References clientLoop(), connect(), createNode(), EQERROR, EQVERB, EQWARN, setWorkDir(), and STATE_LISTENING.
Referenced by initLocal().


| CommandQueue* eq::net::Node::getCommandThreadQueue | ( | ) | [inline] |
Return the command queue to the command thread.
Reimplemented in eq::Server.
Definition at line 504 of file lib/net/node.h.
References isLocal().

| bool eq::net::Node::inCommandThread | ( | ) | const [inline] |
true if executed from the command handler thread, false if not. Definition at line 511 of file lib/net/node.h.
Referenced by close(), and registerSession().

| std::string eq::net::Node::serialize | ( | ) | const |
Serialize the node's information.
Definition at line 688 of file lib/net/node.cpp.
Referenced by _connect(), and initLocal().

| bool eq::net::Node::deserialize | ( | std::string & | data | ) |
Deserialize the node information, consumes given data.
Definition at line 707 of file lib/net/node.cpp.
References addConnectionDescription(), EQERROR, EQVERB, EQWARN, getState(), STATE_LAUNCHED, and STATE_STOPPED.
Referenced by initLocal().


| bool eq::net::Node::_connect | ( | NodePtr | node, | |
| ConnectionPtr | connection | |||
| ) | [protected] |
Connect a node proxy to this node.
This node has to be in the listening state. The node proxy will be put in the connected state upon success. The connection has to be connected.
| node | the remote node. | |
| connection | the connection to the remote node. |
true if the node was connected correctly, false otherwise. For internal use only.
Definition at line 884 of file lib/net/node.cpp.
References _requestHandler, eq::base::UUID::convertToNetwork(), EQINFO, eq::base::RefPtr< T >::get(), getType(), eq::base::RefPtr< T >::isValid(), eq::base::RequestHandler::registerRequest(), serialize(), STATE_LISTENING, STATE_STOPPED, eq::base::RequestHandler::waitRequest(), and eq::base::UUID::ZERO.
Referenced by connect(), eq::Client::connectServer(), and initConnect().


| bool eq::net::Node::dispatchCommand | ( | Command & | command | ) | [protected, virtual] |
Dispatches a packet to the registered command queue.
| command | the command. |
Reimplemented from eq::net::Dispatcher.
Reimplemented in eq::server::Server.
Definition at line 1483 of file lib/net/node.cpp.
References eq::net::Dispatcher::dispatchCommand(), and EQVERB.

| CommandResult eq::net::Node::invokeCommand | ( | Command & | command | ) | [protected, virtual] |
Invokes the command handler method for the packet.
| command | the command. |
Reimplemented from eq::net::Dispatcher.
Reimplemented in eq::server::Server.
Definition at line 1584 of file lib/net/node.cpp.
References eq::net::COMMAND_ERROR, and EQVERB.
| virtual bool eq::net::Node::clientLoop | ( | ) | [inline, protected, virtual] |
The main loop for auto-launched clients.
Reimplemented in eq::Client, eqNbody::Client, eqPly::EqPly, and eVolve::EVolve.
Definition at line 563 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 566 of file lib/net/node.h.
References eq::net::TYPE_EQNET_NODE.
Referenced by _connect(), and getMulticast().

| NodePtr eq::net::Node::createNode | ( | const uint32_t | type | ) | [protected, virtual] |
Factory method to create a new node.
| type | the type the node type |
Definition at line 790 of file lib/net/node.cpp.
References Node(), and eq::net::TYPE_EQNET_NODE.
Referenced by runClient().


base::RequestHandler eq::net::Node::_requestHandler [protected] |
Registers request packets waiting for a return value.
Definition at line 578 of file lib/net/node.h.
Referenced by _connect(), eq::Server::chooseConfig(), close(), mapSession(), registerSession(), eq::Server::releaseConfig(), eq::Server::shutdown(), syncConnect(), unmapSession(), eq::Server::useConfig(), and ~Node().
0.9.1 by
1.6.1