eq::net::Node Class Reference

#include <node.h>

Inheritance diagram for eq::net::Node:

[legend]
Collaboration diagram for eq::net::Node:

[legend]

List of all members.


Detailed Description

Manages a node.

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.
SessiongetSession (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.
CommandQueuegetCommandThreadQueue ()
 Return the command queue to the command thread.
bool inCommandThread () const
bool inReceiverThread () const
const NodeIDgetNodeID () 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.

Constructor & Destructor Documentation

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().

Here is the call graph for this function:


Member Function Documentation

State eq::net::Node::getState (  )  const [inline]

Returns the state of this node.

Returns:
the state of this node.

Definition at line 68 of file lib/net/node.h.

Referenced by deserialize().

Here is the caller graph for this function:

void eq::net::Node::setProgramName ( const std::string &  name  )  [inline]

Set the program name to start this node.

Parameters:
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.

Parameters:
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.

Parameters:
argc the command line argument count.
argv the command line argument values.
Returns:
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().

Here is the call graph for this function:

virtual bool eq::net::Node::exitLocal (  )  [inline, virtual]

Exit a local, listening node.

Definition at line 111 of file lib/net/node.h.

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().

Here is the caller graph for this function:

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.

Returns:
true if the node could be initialized, false if not.
See also:
connect

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().

Here is the call graph for this function:

Here is the caller graph for this function:

bool eq::net::Node::stopListening (  )  [virtual]

Stops this node.

If this node is listening, the node will stop listening and terminate its receiver thread.

Returns:
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().

Here is the call graph for this function:

Here is the caller graph for this function:

bool eq::net::Node::connect ( NodePtr  node,
ConnectionPtr  connection 
)

Connects a node to this listening node.

Parameters:
node the remote node.
connection the connection to the remote node.
Returns:
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().

Here is the call graph for this function:

Here is the caller graph for this function:

NodePtr eq::net::Node::getNode ( const NodeID id  )  const

Get a node by identifier.

Parameters:
id the node identifier.
Returns:
the node.

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.

Parameters:
node the remote node.
Returns:
true if this node was connected, false otherwise.
See also:
initConnect, syncConnect

Definition at line 1297 of file lib/net/node.cpp.

References initConnect(), and syncConnect().

Here is the call graph for this function:

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.

Parameters:
node the remote node.
Returns:
true if this node is connecting, false otherwise.
See also:
syncConnect

Definition at line 1314 of file lib/net/node.cpp.

References connect(), and eq::net::Connection::create().

Referenced by connect().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
node the remote node.
Returns:
true if this node is connected, false otherwise.
See also:
initConnect

Definition at line 1358 of file lib/net/node.cpp.

References _requestHandler, eq::base::RequestHandler::unregisterRequest(), and eq::base::RequestHandler::waitRequest().

Referenced by connect().

Here is the call graph for this function:

Here is the caller graph for this function:

NodePtr eq::net::Node::connect ( const NodeID nodeID,
NodePtr  server 
)

Create and connect a node given by an identifier.

Parameters:
nodeID the identifier of the node to connect.
server a node holding connection information to the destination node.
Returns:
the connected node, or an invalid RefPtr if the node could not be connected.

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().

Here is the call graph for this function:

bool eq::net::Node::disconnect ( NodePtr  node  ) 

Disconnects a connected node.

Parameters:
node the remote node.
Returns:
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().

Here is the call graph for this function:

Here is the caller graph for this function:

ConnectionPtr eq::net::Node::checkConnection (  )  [inline]

Ensures the connectivity of this node.

Returns:
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.

Returns:
true if the node is local, false otherwise.

Definition at line 247 of file lib/net/node.h.

Referenced by addSession(), mapSession(), and unmapSession().

Here is the caller graph for this function:

void eq::net::Node::addConnectionDescription ( ConnectionDescriptionPtr  cd  ) 

Adds a new description how this node can be reached.

Parameters:
cd the connection description.

Definition at line 410 of file lib/net/node.cpp.

Referenced by deserialize(), and initLocal().

Here is the caller graph for this function:

void eq::net::Node::removeConnectionDescription ( const uint32_t  index  ) 

Removes a connection description.

Parameters:
index the index of the connection description.

const ConnectionDescriptionVector& eq::net::Node::getConnectionDescriptions (  )  const [inline]

Returns the number of stored connection descriptions.

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.

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.

Parameters:
packet the packet.
Returns:
the success status of the transaction.

Definition at line 289 of file lib/net/node.h.

Referenced by disconnect(), and stopListening().

Here is the caller graph for this function:

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.

Parameters:
packet the packet.
string the string.
Returns:
the success status of the transaction.

Definition at line 312 of file lib/net/node.h.

template<class T>
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.

Parameters:
packet the packet.
data the vector containing the data.
Returns:
the success status of the transaction.

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.

Parameters:
packet the packet.
data the data.
size the size of the data in bytes.
Returns:
the success status of the transaction.

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.

bool eq::net::Node::mapSession ( NodePtr  server,
Session session 
)

Maps a local session object to the session of the same name on the server.

Parameters:
server the node serving the session.
session the session.
Returns:
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().

Here is the call graph for this function:

bool eq::net::Node::mapSession ( NodePtr  server,
Session session,
const uint32_t  id 
)

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.

Parameters:
server the node serving the session.
session the session.
id the identifier of the session.
Returns:
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().

Here is the call graph for this function:

bool eq::net::Node::unmapSession ( Session session  ) 

Unmaps a mapped session.

Parameters:
session the session.
Returns:
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().

Here is the call graph for this function:

Session* eq::net::Node::getSession ( const uint32_t  id  )  [inline]

Returns:
the mapped session with the given identifier, or 0.

Definition at line 414 of file lib/net/node.h.

void eq::net::Node::addSession ( Session session,
NodePtr  server,
const uint32_t  sessionID 
)

Adds an already mapped session to this node.

Parameters:
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().

Here is the call graph for this function:

void eq::net::Node::removeSession ( Session session  ) 

Removes an unmapped session from this node.

Parameters:
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().

Here is the call graph for this function:

bool eq::net::Node::runClient ( const std::string &  clientArgs  )  [virtual]

Runs this node as a client to a server.

Parameters:
clientArgs the client arguments as specified by the server.
Returns:
the success value of the run.

Definition at line 1574 of file lib/net/node.cpp.

References clientLoop(), connect(), createNode(), and eq::net::Global::setWorkDir().

Referenced by initLocal().

Here is the call graph for this function:

Here is the caller graph for this function:

CommandQueue* eq::net::Node::getCommandThreadQueue (  )  [inline]

Return the command queue to the command thread.

Definition at line 445 of file lib/net/node.h.

bool eq::net::Node::inCommandThread (  )  const [inline]

Returns:
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().

Here is the caller graph for this function:

bool eq::net::Node::dispatchCommand ( Command command  )  [protected, virtual]

Dispatches a packet to the registered command queue.

Parameters:
command the command.
Returns:
the result of the operation.
See also:
invokeCommand

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().

Here is the call graph for this function:

CommandResult eq::net::Node::invokeCommand ( Command command  )  [protected, virtual]

Invokes the command handler method for the packet.

Parameters:
command the command.
Returns:
the result of the operation.
See also:
Base::invokeCommand

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().

Here is the call graph for this function:

virtual bool eq::net::Node::clientLoop (  )  [inline, protected, virtual]

The main loop for auto-launched clients.

See also:
runClient()

Reimplemented in eq::Client.

Definition at line 484 of file lib/net/node.h.

Referenced by initLocal(), and runClient().

Here is the caller graph for this function:

virtual uint32_t eq::net::Node::getType (  )  const [inline, protected, virtual]

Returns:
the type of the node, used during connect().

Definition at line 487 of file lib/net/node.h.

References eq::net::TYPE_EQNET_NODE.

Referenced by connect().

Here is the caller graph for this function:

virtual NodePtr eq::net::Node::createNode ( const uint32_t  type  )  [inline, protected, virtual]

Factory method to create a new node.

Parameters:
type the type the node type
Returns:
the node.
See also:
getType()

Definition at line 496 of file lib/net/node.h.

References eq::net::TYPE_EQNET_NODE.

Referenced by runClient().

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Registers request packets waiting for a return value.

Definition at line 505 of file <a class="el" href="lib_2net_2node_