eq::net::Node Class Reference

Manages a node. More...

#include <node.h>

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

List of all members.

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

The following methods affect the state of the node by changing its 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 ()
 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 ConnectionDescriptionVectorgetConnectionDescriptions () 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.
SessiongetSession (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.

Detailed Description

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.


Member Enumeration Documentation

The state of the node.

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


Constructor & Destructor Documentation

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:


Member Function Documentation

State eq::net::Node::getState (  )  const [inline]
Returns:
the state of this node.

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

Referenced by deserialize(), and eq::server::Server::run().

Here is the caller graph for this function:

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

Get a node by identifier.

The node might not be connected.

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

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
Returns:
the command to spawn the process for this node.

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]
Returns:
the current launch timeout in milliseconds.

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.

Parameters:
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]
Returns:
the program name to start the node.

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.

Parameters:
name the working directory to start this node.

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

Referenced by runClient().

Here is the caller graph for this function:

const std::string& eq::net::Node::getWorkDir (  )  const [inline]
Returns:
the working directory to start the node.

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:

  • --eq-client to launch a client. This is used for remote nodes which have been auto-launched by another node, e.g., remote render clients. This method does not return when this command line option is present.
  • '--eq-listen <connection description>' to add listening connections to this node. This parameter might be used multiple times (cf. ConnectionDescription::fromString).

Please note that further command line parameters are recognized by eq::init().

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

Here is the call graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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.

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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.

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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.

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
node the remote node.
timeout the timeout, in milliseconds, before the launch process is considered to have failed.
Returns:
true if this node is connected, false otherwise.
See also:
initConnect

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

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.

Parameters:
nodeID the identifier of the node to connect.
Returns:
the connected node, or an invalid RefPtr if the node could not be connected.

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.

Here is the call graph for this function:

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

Disconnects a connected node.

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

Here is the call graph for this function:

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 300 of file lib/net/node.h.

References STATE_LISTENING.

Referenced by getCommandThreadQueue(), mapSession(), registerSession(), 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 558 of file lib/net/node.cpp.

Referenced by deserialize(), and initLocal().

Here is the caller graph for this function:

bool eq::net::Node::removeConnectionDescription ( ConnectionDescriptionPtr  cd  ) 

Removes a connection description.

Parameters:
cd the connection description.
Returns:
true if the connection description was removed, false otherwise.

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

const ConnectionDescriptionVector & eq::net::Node::getConnectionDescriptions (  )  const

Returns the number of stored connection descriptions.

Returns:
the number of stored connection descriptions.

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

ConnectionPtr eq::net::Node::getConnection (  )  const [inline]
Returns:
the connection to this node.

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

ConnectionPtr eq::net::Node::getMulticast (  ) 
Returns:
the multicast connection to this node, or 0.

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

References EQINFO, getType(), and eq::base::RefPtr< T >::isValid().

Referenced by multicast().

Here is the call graph for this function:

Here is the caller graph for this function:

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 343 of file lib/net/node.h.

Referenced by eq::Server::chooseConfig(), close(), registerSession(), eq::Server::releaseConfig(), eq::Server::shutdown(), and eq::Server::useConfig().

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 366 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 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.

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

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

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

References getMulticast().

Here is the call graph for this function:

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

Here is the call graph for this function:

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.

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

Here is the call graph for this function:

bool eq::net::Node::deregisterSession ( Session session  )  [inline]

Deregister a (master) session.

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

References unmapSession().

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 node has to be a remote node.

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 633 of file lib/net/node.cpp.

References _requestHandler, eq::net::Session::getID(), 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 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().

Here is the call graph for this function:

Here is the caller graph for this function:

Session * eq::net::Node::getSession ( const uint32_t  id  ) 
Returns:
the mapped session with the given identifier, or 0.

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.

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

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

References clientLoop(), connect(), createNode(), EQERROR, EQVERB, EQWARN, setWorkDir(), and STATE_LISTENING.

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.

Reimplemented in eq::Server.

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

References isLocal().

Here is the call graph for this function:

bool eq::net::Node::inCommandThread (  )  const [inline]
Returns:
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().

Here is the caller graph for this function:

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

Here is the caller graph for this function:

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

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

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

Here is the call graph for this function:

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

Reimplemented in eq::server::Server.

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

References eq::net::Dispatcher::dispatchCommand(), and EQVERB.

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:
Dispatcher::invokeCommand

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.

See also:
runClient()

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

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 566 of file lib/net/node.h.

References eq::net::TYPE_EQNET_NODE.

Referenced by _connect(), and getMulticast().

Here is the caller graph for this function:

NodePtr eq::net::Node::createNode ( const uint32_t  type  )  [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 790 of file lib/net/node.cpp.

References Node(), and eq::net::TYPE_EQNET_NODE.

Referenced by runClient().

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation


The documentation for this class was generated from the following files:
Generated on Sat Feb 6 13:10:06 2010 for Equalizer 0.9.1 by  doxygen 1.6.1