Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members

epi::node::AutoNode Class Reference

#include <EpiAutoNode.hpp>

Inheritance diagram for epi::node::AutoNode:

epi::node::LocalNode epi::node::AbstractNode List of all members.

Public Member Functions

 AutoNode (const std::string aNodeName) throw (EpiBadArgument, EpiConnectionException)
 AutoNode (const std::string aNodeName, const std::string aCookie) throw (EpiBadArgument, EpiConnectionException)
 AutoNode (const std::string aNodeName, const std::string aCookie, ErlangTransport *transport) throw (EpiBadArgument, EpiConnectionException)
MailBoxcreateMailBox ()
void deattachMailBox (MailBox *mailbox)
void registerMailBox (const std::string name, MailBox *mailbox)
void unRegisterMailBox (const std::string name)
void unRegisterMailBox (MailBox *mailbox)
void close ()
void startAcceptor () throw (EpiConnectionException)
void run ()
void deliver (void *origin, EpiMessage *msg)
virtual OutputBuffernewOutputBuffer ()
void sendBuf (epi::type::ErlPid *from, epi::type::ErlPid *to, epi::node::OutputBuffer *buffer) throw (epi::error::EpiConnectionException)
void sendBuf (epi::type::ErlPid *from, const std::string &to, epi::node::OutputBuffer *buffer) throw (epi::error::EpiConnectionException)
void sendBuf (epi::type::ErlPid *from, const std::string &node, const std::string &to, epi::node::OutputBuffer *buffer) throw (epi::error::EpiConnectionException)
void event (EpiObservable *observed, EpiEventTag event)

Protected Member Functions

void addMailBox (MailBox *mailbox)
MailBoxgetMailBox (ErlPid *pid)
MailBoxgetMailBox (std::string name)
void removeMailBox (MailBox *mailbox)
ConnectiongetConnection (std::string name)
void addConnection (Connection *connection)
void removeConnection (Connection *connection)
void flushConnections ()
ConnectionattempConnection (std::string name) throw (EpiConnectionException)

Detailed Description

Represents a local auto managed node. This class is used when you do not wish to manage connections yourself - outgoing connections are established as needed, and incoming connections accepted automatically. The programmer have to use the mailbox API for communication, while management of the underlying communication mechanism is automatic and hidden from the application programmer.

Once an instance of this class has been created, obtain one or more mailboxes in order to send or receive messages. The first message sent to a given node will cause a connection to be set up to that node. Any messages received will be delivered to the appropriate mailboxes.

Mailboxes can be named using registerMailBox(). Messages can be sent to named mailboxes and named Erlang processes without knowing the pid that identifies the mailbox. This is neccessary in order to set up initial communication between parts of an application. A MailBox can have one or more names.

To shut down the node, call close(). This will prevent the node from accepting additional connections and it will cause all existing connections to be closed. Any unread messages in existing mailboxes can still be read, however no new messages will be delivered to the mailboxes.

Note that the use of this class requires that Epmd (Erlang Port Mapper Daemon) is running on each cooperating host. This class does not start Epmd automatically as Erlang does, you must start it manually or through some other means. See the Erlang documentation for more information about this.


Constructor & Destructor Documentation

AutoNode::AutoNode const std::string  aNodeName  )  throw (EpiBadArgument, EpiConnectionException)
 

Create a new node, using default cookie an any port

Parameters:
aNodeName node name
Exceptions:
EpiBadArgument if node name is too long
EpiConnectionException if there is a network problem

AutoNode::AutoNode const std::string  aNodeName,
const std::string  aCookie
throw (EpiBadArgument, EpiConnectionException)
 

Create a new node, using given cookie

Parameters:
aNodeName node name
cookie cookie to use
Exceptions:
EpiBadArgument if node name is too long
EpiConnectionException if there is a network problem

AutoNode::AutoNode const std::string  aNodeName,
const std::string  aCookie,
ErlangTransport transport
throw (EpiBadArgument, EpiConnectionException)
 

Create a new node, using given cookie

Parameters:
aNodeName node name
aCookie cookie to use
transport to use
Exceptions:
EpiBadArgument if node name is too long
EpiConnectionException if there is a network problem


Member Function Documentation

void AutoNode::addConnection Connection connection  )  [protected]
 

Add a connection to the map of Connections. This node will be set as receiver for this connection. Connection will be started and must not be running. I also deletes the connections in the flush list (list of connections to be deleted).

void AutoNode::addMailBox MailBox mailbox  )  [protected]
 

Add mailbox to the map of associated mailboxes. This node will be set as sender for mailbox. This node will monitor the mailbox.

Connection * AutoNode::attempConnection std::string  name  )  throw (EpiConnectionException) [protected]
 

Get the connection for given name. If no connection exists, try to setup a connection, adding it to the map

void AutoNode::close  ) 
 

Close this node. All connections will be closed and no more connections will be created or accepted.

MailBox * AutoNode::createMailBox  ) 
 

Create a new MailBox with a new pid associated to this node. The MailBox will use this node as sender and this node will deliver to this mailbox all messages with mailbox pid as destination.

MailBox pointer owership belongs to this node.

void AutoNode::deattachMailBox MailBox mailbox  ) 
 

Deatach a mailbox from this AutoNode. The mailbox will be unregistered from mailboxes lists and will not recive more messages. It will not be deleted and owership by this node is lost, so the user MUST delete the mailbox after call this method.

void AutoNode::deliver void *  origin,
EpiMessage msg
 

Deliver incoming message This method will analize the message content, delivering it to the destination mailbox.

void AutoNode::event EpiObservable *  observed,
EpiEventTag  event
 

Receive an event from an observed object. If the sender is a mailbox and event is EVENT_DESTROY, mailbox will be deleted from mailbox list.

void AutoNode::flushConnections  )  [protected]
 

Delete all connections in the flush list (connections to be deleted). This method is not guarded, and must be called from a guarded method.

Connection * AutoNode::getConnection std::string  name  )  [protected]
 

Get connection by node name from internal map

MailBox * AutoNode::getMailBox std::string  name  )  [protected]
 

Get mailbox by string

MailBox * AutoNode::getMailBox ErlPid pid  )  [protected]
 

Get mailbox by pid

OutputBuffer * AutoNode::newOutputBuffer  )  [virtual]
 

Create a new OutputBuffer to be used with this sender. The output buffer used by AutoNode is a plain buffer that simply stores the term.

void AutoNode::registerMailBox const std::string  name,
MailBox mailbox
 

Register an MailBox with given name. MailBox must be associated to this node.

void AutoNode::removeConnection Connection connection  )  [protected]
 

Remove and delete a connection. It deletes connection only if it exists in connection map. It really adds the connection to a list of connections to be deleted. This allows a connection thread to remove himself.

void AutoNode::removeMailBox MailBox mailbox  )  [protected]
 

Remove a mailbox

void AutoNode::run  ) 
 

Connection acceptor thread code. The node will automacly accept incomming connections.

void AutoNode::sendBuf epi::type::ErlPid from,
const std::string &  node,
const std::string &  to,
epi::node::OutputBuffer buffer
throw (epi::error::EpiConnectionException)
 

Send a buffer to a registered server in the given node

void AutoNode::sendBuf epi::type::ErlPid from,
const std::string &  to,
epi::node::OutputBuffer buffer
throw (epi::error::EpiConnectionException)
 

Send a buffer to a registered server.

void AutoNode::sendBuf epi::type::ErlPid from,
epi::type::ErlPid to,
epi::node::OutputBuffer buffer
throw (epi::error::EpiConnectionException)
 

Send a buffer to a pid.

void AutoNode::startAcceptor  )  throw (EpiConnectionException)
 

Start acceptor thread. Call this method to accept new connections automacly.

Exceptions:
EpiConnectionException if there are problems publishing port

void AutoNode::unRegisterMailBox MailBox mailbox  ) 
 

Unregister all names for this mailbox

void AutoNode::unRegisterMailBox const std::string  name  ) 
 

Unregister a name for a mailbox


The documentation for this class was generated from the following files:
Generated on Wed Mar 30 22:04:44 2005 for EPI by doxygen 1.3.4